我試圖從記事本窗口輸出文本到控制檯,它總是0. 我在做什麼錯了?輸出LRESULT到控制檯
int main()
{
HWND hwnd = (HWND)0x0031019C; // Window Handler of Notepad
char szBuf[4096];
HWND hwndEdit;
LRESULT result;
hwndEdit = FindWindowEx(hwnd, NULL, L"Edit", NULL); // Class for edit box
result = SendMessage(hwndEdit, WM_GETTEXT, sizeof(szBuf)/sizeof(szBuf[0]), (LPARAM)szBuf);
cout<<"Contents: \n"<<result;
cin.get();
return 0;
}
我試過print_f
,但它輸出亂碼:
printf("Contents: %s\n", result, szBuf);
我檢查了你的代碼,但在我的案例'0x0031019C'。它似乎並不是記事本的句柄。請在'FindWindowEx()'之前嘗試'GetWindowtext(hwnd,szbuf,1024)'。希望它能幫助你 –