Teen Programmers Unite  
 

 

Return to forum top

Text input using edit controls

Posted by nid [send private reply] at June 26, 2001, 09:36:27 PM

Recently I have been trying to make a simple program in which the user will be able to enter text into an edit control in a modal dialog box and the text will be printed out in the main (parent) window. After the user enters the text into the edit control I expect them to click a submit button and have it sent to the window. I have ran into some snags though. I have been trying to use the EM_GETLINE message but I can't seem to get it to work using global variables. Example:

TCHAR szBuffer[128];

DlgProc()
{
switch(LOWORD(wParam))
{
case IDOK:
SendMessage(hEditBox, EM_GETLINE, 0, (LPARAM) szBuffer);
}
}

But this results in nothing being entered into the buffer. I left out some code, of course, but none of it acted on the buffer in any way. I finally got it to work by putting my szBuffer declaration inside of the dialog procedure but now I am having problems sending the buffer from the dialog procedure back to the parent window. I can't figure out how to pass the buffer to the window in a way that makes sense. I can do it in a roundabout way, but it doesn't seem too efficient or logical. I figure there has to be a way to get the global variable to work, I just can't figure it out. I can use TextOut() to paint the text back to the parent window, but then if the dialog box is covering the area the text should be printed to, it doesn't show up. Also, when I resize the window the text dissapears. What should I do?

Any ideas would be greatly appreciated... or anyone that can point me to a tutorial about text input would be terrific :) Thanks a ton!

Posted by taubz [send private reply] at June 28, 2001, 09:27:25 PM

Just some basic questions to cover the bases: are you sure that line of code is executing? Is the value of szBuffer empty right after the API call, or is it just empty when you access it from the other Window?

From the Platform SDK: "Before sending the message, set the first word of this buffer to the size, in TCHARs, of the buffer. For ANSI text, this is the number of bytes; for Unicode text, this is the numer of characters. The size in the first word is overwritten by the copied line."

Did you do that? I'm guessing it would look like *((int *)szBuffer) = BUFFER_SIZE.

Also note that "The copied line does not contain a terminating null character" Maybe that's throwing you off in displaying it.

Since the dialog should be in the same thread as your other window, there shouldn't be a problem (AFAIK) using a global variable to store the text.

Just some ideas. Hope it helps.

- taubz

Posted by nid [send private reply] at June 29, 2001, 06:39:22 PM

Yep, that's what it was. I had forgotten to set the first word equal to the size of the buffer. Thanks a ton for the help :)

You must be logged in to post messages and see which you have already read.

Log on
Username:
Password:
Save for later automatic logon

Register as a new user
 
Copyright TPU 2002. See the Credits and About TPU for more information.