Chr*_*ian 3 c++ winapi controls edit gettext
我一直试图让这个工作年龄相似,但没有用(悲伤的脸).
int iChars = GetWindowTextLength (GetDlgItem(handle,ID))+1; // Room for '\0'
char* pstrText;
pstrText = (char*) malloc (sizeof(char)*iChars);
if (pstrText != NULL) {
//GetWindowText (GetDlgItem(handle,ID), pstrText, iChars);
GetDlgItemText(handle,ID,pstrText,iChars);
}
return pstrText; // Memory gets freed after it returns
Run Code Online (Sandbox Code Playgroud)
工作范例:
char* MWC::System::TextBox::GetText(){
int len = SendMessage(handle, WM_GETTEXTLENGTH, 0, 0);
char* buffer = new char[len];
SendMessage(handle, WM_GETTEXT, (WPARAM)len+1, (LPARAM)buffer);
return buffer;
}
Run Code Online (Sandbox Code Playgroud)
这里的wParam参数错误:
SendMessage(handle, WM_GETTEXT, (WPARAM)len, (LPARAM)buffer);
Run Code Online (Sandbox Code Playgroud)
你应该通过len+1零终止符来传递.