Archived

This topic is now archived and is closed to further replies.

Win32 EM_GETLINE

This topic is 5236 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have never had to do much with win32 other than create a window for directX purposes, but i decided it was time to start learning how to do the GUI stuff (Visual C++). I have a edit box (CreateWindow(...)) and i would like to get the text/String data from it. I have been trying to use the SendMessage(hwnd, EM_GETLINE.... but i just don''t seem to understand how to wotk with it, if anyone could help, it would be much appriciated, Thanks.

Share this post


Link to post
Share on other sites
I suppose you are implementing it like this:

char char_array[1000]={0};
int line_number=0;
//...
SendMessage(hEdit,EM_GETLINE,line_number,char_array);

It should work, but if it doesn''t then do this:

SendMessage(hEdit,WM_GETTEXT,num_characters,char_array);

Share this post


Link to post
Share on other sites
Hmmm, sorry about that, I guess you would use a pointer to the buffer.

Ayway, just use this if you want to get the whole contents of the edit control: GetDlgItemText(hwnd,IDC_EDIT,char_array,1000);

Share this post


Link to post
Share on other sites
quote:
Original post by Xiachunyi
char char_array[1000]={0};
int line_number=0;
//...
SendMessage(hEdit,EM_GETLINE,line_number,char_array);



That should be:

SendMessage(hEdit, EM_GETLINE, (WPARAM)line_number, (LPARAM)char_array);



Qui fut tout, et qui ne fut rien
Invader''s Realm

Share this post


Link to post
Share on other sites
Hi,
Thanks Xiachunyi, thanks Invader X.
I must still be doing something wrong.
I create my text box with

hwndtext = CreateWindowEx(NULL,
"edit",
"hello",
WS_BORDER|WS_CHILD|WS_VISIBLE|ES_LEFT,
10,10,
100,100,
hWnd,
(HMENU)(100),
hInstance,
NULL);


and then i 'Attempt' to get the data with


//if pushbutton

if(LOWORD(wParam)==101)
{
char char_array[1000]={0};
int line_number=0;

SendMessage(hwndtext, WM_GETTEXT, (WPARAM)line_number,(LPARAM)char_array);

HDC hdc = GetDC(hwnd);
TextOut(hdc,220,140,char_array,1000);

}


...but i am still not getting the data from the edit box. Any further help would be much appriciated, thanks again.

PS. I have tried WM_GETTEXT, EM_GETLINE and the GetDlgItemText() method.

[edited by - Defcom on August 15, 2003 5:29:14 AM]

Share this post


Link to post
Share on other sites
I''ve fixed it.


HDC hdc = GetDC(hwnd);
char* buf;
int len;
len = SendMessage (hwndtext, WM_GETTEXTLENGTH, 0, 0);
SendMessage(hwndtext, EM_GETLINE, 0, (LPARAM)buf);
TextOut(hdc,220,nextline,buf,len);
nextline+=20;



Thanks again.

Share this post


Link to post
Share on other sites