本文整理汇总了C++中CString::GetAllocLength方法的典型用法代码示例。如果您正苦于以下问题:C++ CString::GetAllocLength方法的具体用法?C++ CString::GetAllocLength怎么用?C++ CString::GetAllocLength使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CString
的用法示例。
在下文中一共展示了CString::GetAllocLength方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: DDX_FieldCBString
void AFXAPI DDX_FieldCBString(CDataExchange* pDX, int nIDC, CString& value,
CRecordset* pRecordset)
{
ASSERT_VALID(pRecordset);
HWND hWndCtrl = pDX->PrepareCtrl(nIDC);
if (pDX->m_bSaveAndValidate)
{
// just get current edit item text (or drop list static)
int nLen = ::GetWindowTextLength(hWndCtrl);
if (nLen != -1)
{
CString strTemp;
::GetWindowText(hWndCtrl, strTemp.GetBuffer(nLen), nLen+1);
strTemp.ReleaseBuffer();
nLen = strTemp.GetLength();
if (nLen > value.GetAllocLength())
AfxFailMaxChars(pDX, value.GetAllocLength());
// get known length
::GetWindowText(hWndCtrl, value.GetBuffer(0), nLen+1);
}
else
{
// for drop lists GetWindowTextLength does not work - assume
// preallocated length
::GetWindowText(hWndCtrl, value.GetBuffer(0), value.GetAllocLength()+1);
}
value.ReleaseBuffer();
if (value.GetLength() == 0)
{
if (pRecordset->IsFieldNullable(&value))
pRecordset->SetFieldNull(&value, TRUE);
}
else
{
pRecordset->SetFieldNull(&value, FALSE);
}
}
else
{
if (!pRecordset->IsOpen() || pRecordset->IsFieldNull(&value))
{
SendMessage(hWndCtrl, CB_SETCURSEL, (WPARAM)-1, 0L);
}
else
{
// set current selection based on model string
if (::SendMessage(hWndCtrl, CB_SELECTSTRING, (WPARAM)-1,
(LPARAM)(LPCTSTR)value) == CB_ERR)
{
// just set the edit text (will be ignored if DROPDOWNLIST)
AfxSetWindowText(hWndCtrl, value);
}
}
}
}
示例2: DDX_FieldLBString
void AFXAPI DDX_FieldLBString(CDataExchange* pDX, int nIDC, CString& value,
CRecordset* pRecordset)
{
ASSERT_VALID(pRecordset);
HWND hWndCtrl = pDX->PrepareCtrl(nIDC);
if (pDX->m_bSaveAndValidate)
{
int nIndex = (int)::SendMessage(hWndCtrl, LB_GETCURSEL, 0, 0L);
if (nIndex != -1)
{
int nLen = (int)::SendMessage(hWndCtrl, LB_GETTEXTLEN, nIndex, 0L);
if (nLen > value.GetAllocLength())
AfxFailMaxChars(pDX, value.GetAllocLength());
::SendMessage(hWndCtrl, LB_GETTEXT, nIndex,
(LPARAM)(LPSTR)value.GetBuffer(0));
if (nLen == 0)
{
if (pRecordset->IsFieldNullable(&value))
pRecordset->SetFieldNull(&value, TRUE);
}
else
{
pRecordset->SetFieldNull(&value, FALSE);
}
value.ReleaseBuffer();
}
else
{
// no selection
value.GetBufferSetLength(0);
if (pRecordset->IsFieldNullable(&value))
pRecordset->SetFieldNull(&value);
}
}
else
{
if (!pRecordset->IsOpen() || pRecordset->IsFieldNull(&value))
{
SendMessage(hWndCtrl, LB_SETCURSEL, (WPARAM)-1, 0L);
}
else
{
// set current selection based on data string
if (::SendMessage(hWndCtrl, LB_SELECTSTRING, (WPARAM)-1,
(LPARAM)(LPCTSTR)value) == LB_ERR)
{
// no selection match
TRACE0("Warning: no listbox item selected.\n");
}
}
}
}
示例3: OnNewGame
void NetGoAction::OnNewGame()
{
agree = true;
isMe = true;
CString send = _T("-1:-4");
winDig->gogame.Send(send, send.GetAllocLength() * 2);
}
示例4: DebugDboException
CString GravadorControllerDlg::DebugDboException(CDBException *e, CString cOrigin, int nNivel)
{
// procura pelo código do erro. Extrai de "State:%s,Native:%ld,Origin:%s"
int nPos;
nPos = e->m_strStateNativeOrigin.Find(',');
CString cErr;
cErr = e->m_strStateNativeOrigin.Left(nPos); // State:%s
CString cException;
e->GetErrorMessage(cException.GetBuffer(1024), cException.GetAllocLength());
e->Delete(); // lembrar que não precisa apagar fora dessa rotina.
cException.ReleaseBuffer();
// acrescenta a rotina de origem, a descrição e o código do erro.
cException = cOrigin + cException;
cException = cException + cErr;
m_debugLog.Log(LOG_ERROR, cException);
MessageBox(cException, _T("ERRO"), MB_OK | MB_ICONERROR);
// devolve o código do erro
cErr.Delete(0, 6); // aqui só fica o "%s"
return cErr;
}
示例5: OnUndo
void NetGoAction::OnUndo()
{
if (guiGo->count == 1) {
return;
}
agree = true;
CString send = _T("-1:-1");
winDig->gogame.Send(send, send.GetAllocLength() * 2);
}
示例6: DDX_FieldText
void AFXAPI DDX_FieldText(CDataExchange* pDX, int nIDC, CString& value,
CRecordset* pRecordset)
{
ASSERT_VALID(pRecordset);
HWND hWndCtrl = pDX->PrepareEditCtrl(nIDC);
if (pDX->m_bSaveAndValidate)
{
// check if length is too long (this is complicated by Windows NT/J)
int nLen = ::GetWindowTextLength(hWndCtrl);
if (nLen > value.GetAllocLength())
{
if (!_afxDBCS)
AfxFailMaxChars(pDX, value.GetAllocLength());
CString strTemp;
::GetWindowText(hWndCtrl, strTemp.GetBuffer(nLen), nLen+1);
strTemp.ReleaseBuffer();
nLen = strTemp.GetLength();
if (nLen > value.GetAllocLength())
AfxFailMaxChars(pDX, value.GetAllocLength());
}
// get known length
::GetWindowText(hWndCtrl, value.GetBuffer(0), nLen+1);
value.ReleaseBuffer();
if (nLen == 0)
{
if (pRecordset->IsFieldNullable(&value))
pRecordset->SetFieldNull(&value, TRUE);
}
else
{
pRecordset->SetFieldNull(&value, FALSE);
}
}
else if (pRecordset->IsDeleted())
{
CString strDeleted(MAKEINTRESOURCE(AFX_IDS_DELETED));
AfxSetWindowText(hWndCtrl, strDeleted);
}
else
{
AfxSetWindowText(hWndCtrl, value);
}
}
示例7: OnPass
void NetGoAction::OnPass()
{
if (!isMe) {
return;
}
turnBW();
guiGo->passStip(winDig->GetDC());
CString send = _T("-1:-2");
winDig->gogame.Send(send, send.GetAllocLength() * 2);
}
示例8: _GetStringValue
void CDSN::_GetStringValue(CRegKey &key,
const CString &strValueName, CString &strValue) const
{
PTSTR pBuf = strValue.GetBuffer(255);
ULONG ulChars = strValue.GetAllocLength(); // not GetLength
LONG lRes = key.QueryStringValue(strValueName, pBuf, &ulChars);
pBuf = NULL;
strValue.ReleaseBuffer();
if (lRes != ERROR_SUCCESS)
{
throw _T("_GetStringValue failed");
}
}
示例9: GetWindowTextType
int CUtils::GetWindowTextType(const CString& text)
{
int len = text.GetAllocLength();
if (len >= 3 && text[0] == _T('*') && text[len - 1] == _T('*'))
return IDS_WINDOW_TEXT_MATCH;
else if (len >= 2 && text[0] != _T('*') && text[len - 1] == _T('*'))
return IDS_WINDOW_TEXT_MATCH_FORWARD;
else if (len >= 2 && text[0] == _T('*') && text[len - 1] != _T('*'))
return IDS_WINDOW_TEXT_MATCH_BACKWARD;
else if (len > 0 && text[0] != _T('*') && text[len - 1] != _T('*'))
return IDS_WINDOW_TEXT_MATCH_FULL;
return IDS_WINDOW_TEXT_IGNORE;
}
示例10: CStringToA
LPSTR CStringToA(const CString& strData)
{
CString ret;
char *ptr = NULL;
#ifdef _UNICODE
LONG len;
len = WideCharToMultiByte(CP_ACP, 0, strData, -1, NULL, 0, NULL, NULL);
ptr = new char [len+1];
if (ptr)
{
memset(ptr,0,len + 1);
WideCharToMultiByte(CP_ACP, 0, strData, -1, ptr, len + 1, NULL, NULL);
}
#else
ptr = new char [strData.GetAllocLength()+1];
sprintf(ptr,_T("%s"),strData);
#endif
return ptr;
}
示例11: OnPoint
void NetGoAction::OnPoint(CPoint point)
{
if (!isMe) {
return;
}
turnBW();
//下棋
if (guiGo->clickGo(winDig->GetDC(), point)) {
int px = guiGo->px;
int py = guiGo->py;
CString stx, sty;
stx.Format(_T("%d"), px);
sty.Format(_T("%d"), py);
CString send = stx + _T(":") + sty;
winDig->gogame.Send(send, send.GetAllocLength()*2);
}else {
//走棋非法时,保留下棋权利 ps:bug(2016/5/6)
turnBW();
}
}
示例12: WinMain
int WINAPI WinMain(
HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow
)
{
SECURITY_ATTRIBUTES sa;
sa.bInheritHandle = true;
sa.nLength = sizeof(SECURITY_ATTRIBUTES);
sa.lpSecurityDescriptor = NULL;
if (!IsWow64())
return 1;
if (!CString(lpCmdLine).IsEmpty())
pidToAttach = atoi(lpCmdLine);
HMODULE hKernel32 = LoadLibrary("KERNEL32.DLL");
pfnLoadLibrary = (LPTHREAD_START_ROUTINE)GetProcAddress(hKernel32, ("LoadLibraryA"));
char *pDataRemote = 0;
DWORD numBytes = 0;
HANDLE fledgeProcess = NULL;
int numTries = 30;
while (numTries)
{
EnumWindows(FindFledge, pidToAttach);
if (fledgeWindow != NULL)
break;
Sleep(1000);
numTries--;
}
if (fledgeWindow == NULL)
return 1;
GetWindowThreadProcessId(fledgeWindow, &pidToAttach);
fledgeProcess = OpenProcess(PROCESS_ALL_ACCESS, false, pidToAttach);
CStringA curDir;
GetCurrentDirectoryA(MAX_PATH, curDir.GetBuffer(MAX_PATH + 1));
CString param = curDir.GetBuffer();
param.Append("\\");
param.Append(HOOK_DLLNAME);
pDataRemote = (char*) VirtualAllocEx(fledgeProcess, 0, param.GetAllocLength(), MEM_COMMIT, PAGE_READWRITE);
if (pDataRemote == NULL)
return 1;
if (!WriteProcessMemory(fledgeProcess, pDataRemote, param.GetBuffer(), param.GetAllocLength(), &numBytes))
return 1;
DWORD threadID;
HANDLE fledgeThread = CreateRemoteThread(fledgeProcess, NULL, 0, (LPTHREAD_START_ROUTINE) pfnLoadLibrary, pDataRemote, 0, &threadID);
CStringA eventName;
eventName.Format("%s%d", "Global\\FledgeHook", pidToAttach);
HANDLE hEvent = CreateEventA(NULL, false, false, eventName);
WaitForSingleObject(hEvent, INFINITE);
DWORD WM_FLEDGEHOOKDATA = RegisterWindowMessageA("FledgeHookDataEvent");
PostThreadMessageA(threadID, WM_FLEDGEHOOKDATA, 0, (LPARAM)fledgeWindow);
curDir.ReleaseBuffer();
param.ReleaseBuffer();
CloseHandle(fledgeProcess);
return 0;
}