gpt4 book ai didi

c++ - 从编辑控件中获取文本(纯 Win32 API)

转载 作者:太空狗 更新时间:2023-10-29 19:46:47 37 4
gpt4 key购买 nike

多年来,我一直在努力让它发挥作用,但无济于事(悲伤的表情)。

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;
}

最佳答案

此处wParam参数错误:

SendMessage(handle, WM_GETTEXT, (WPARAM)len, (LPARAM)buffer);

由于零终止符,您应该传递 len+1

关于c++ - 从编辑控件中获取文本(纯 Win32 API),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7389757/

37 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com