我一直试图让这个工作适合年龄段,但没有用(悲伤的脸)。从编辑控件(纯Win32 API)中获取文本
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
工作例如:
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;
}
即使您对指针进行反思,内存仍会被删除,因此结果仍然会指向已删除的内存。此外,根据您正在运行的平台,指针的大小将为32/64位。函数GetDlgItemText的Fouth参数必须是iChars。 – beren
是啊,那不是什么导致功能不能正常工作。 – Christian
“不工作”对我们来说不够好。它是如何失败的。准确。我们无法看到您的屏幕。 –