Click here to Skip to main content
15,891,905 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello !

I'm having a 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)0x00050440;
		char display[256];
	    LONG lResult;
		TCHAR  tszString[256];
	    
		/*
		TCHAR param[256];
		lResult = SendMessage( hwnd, WM_GETTEXT, 500, (LPARAM)param);
		*/
		
		//Find out the number of lines in the textbox
		int nLines = SendMessageW(hwnd, EM_GETLINECOUNT, 0, 0)-1;
		
		lResult = SendMessageW( hwnd, EM_GETLINE, nLines, (LPARAM)tszString); 
	    
		//Find out how many characters are collected ERROR: Returns 0 ??
		int nLength = SendMessageW(hwnd, EM_GETLINE, (WPARAM)nLines, (LPARAM)tszString);
		
		//Adding the string terminating NULL
		tszString[nLength] = '\0';  
		
		wcstombs(display, tszString, 256);
	    //wcstombs(display, param, 256);
	    printf( " %s\n", display );



I keep getting 0 for nLength. MSDN say thats because I adress a linenumber larger than lines found in the textbox. Thats not the case.
The handle is correct, when using GETTEXT I get all the text from the box. ( Testing it on notepad...)
I'm not sure if I have initialized the buffer correct.
MSDN: "Before sending the message, set the first word of this buffer to the size, in TCHARs, of the buffer." :confused:
Right now the result is a empty console. No text... :((

I have Unicode set as characterset in my project, could that be a problem?

Regards
SH
Posted
Updated 3-Sep-10 7:33am
v2

1 solution

You have the solution in your hands: before sending the message, set the first word of this buffer to the size, in TCHARs, of the buffer.

Then, try this:

C++
*reinterpret_cast<WORD *>(tszString) = _countof(tszString);
int nLength = SendMessage(hWnd, EM_GETLINE, nLines, (LPARAM)tszString);
 
Share this answer
 
Comments
Sandeep Mewara 3-Sep-10 14:21pm    
Comment from OP:
THANK YOU VERY MUCH !!

This was driving me nuts half of my day....

But I simply did not understand what msdn ment by that sentence.
Thanks again!

Regards
SH

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900