开发者

EM_GETLINE error C++ Get last Line from Textbox

I'm having a minor problem with EM_GETLINE. I have a textbox I want to extract the text from. The box keeps updating开发者_如何转开发 all the time (it's a log file thet keeps updating, last message at the bottom). All I want is that very last line.

My code:

        HWND hwnd = (HWND)0x00020A72;
 TCHAR param[1000];
 char display[1000];
 LONG lResult;
 lResult = SendMessage( hwnd, WM_GETTEXT, 500, (LPARAM)param);
 //lResult = SendMessage( hwnd, EM_STREAMOUT, SF_RTF, (LPARAM)param);
 //lResult = SendMessage( hwnd, EM_GETLINE, 1, (LPARAM)param); 
 wcstombs(display, param, 1000);

 printf( " %s\n", display );

As you can see I've tried WM_GETTEXT (that works). When using GETLINE it compiles nice (VS2010express) but returns rubbish.

Would be really gratful for help. Thanks for listening.


This window belongs to another process, right? I can see you hard-coded the window handle. Not so sure that message is automatically marshaled across process boundaries, only the system message are (WM_Xxx < 0x400).

Marshaling it yourself requires OpenProcess, VirtualAllocEx to allocate the buffer, WriteProcessMemory to intialize it, SendMessage, ReadProcessMemory to read the buffer. Plus cleanup.


You should ask for the last not the first line and add the NULL for the termination, try the following:

int last_line = SendMessage(hwnd, EM_GETLINECOUNT,0 ,0) - 1;
int size = SendMessage(hwnd, EM_GETLINE, (WPARAM)last_line, (LPARAM)param);
param[size] = 0;//EM_GETLINE does not add the NULL


"Long pointer to the buffer that receives a copy of the line. The first word of the buffer specifies the maximum number of characters that can be copied to the buffer" http://msdn.microsoft.com/en-us/library/aa921607.aspx

*(WORD*) param = 1000
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜