• Welcome to Valhalla Legends Archive.
 

Sending return command in 'Edit' class

Started by Spilled, June 20, 2005, 11:53 AM

Previous topic - Next topic

Spilled

I am currently having trouble with sending the return key in the 'edit' class. I've made a subclass to detect return and key downs but I don't know how to send a new line to another textbox. For example, take a string, add a newline, and then add another string on the next line. I try putting the '/n' into a const char array but it won't work. Help??

MyndFyre

QuoteEvery generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?

After 3 years, it's on the horizon.  The new JinxBot, and BN#, the managed Battle.net Client library.

Quote from: chyea on January 16, 2009, 05:05 PM
You've just located global warming.

Spilled

\n** i meant, typo sorry. Heres my code:

LRESULT CALLBACK MyTextProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
        switch (message)
        {
               case WM_KEYDOWN:
                   if ((int) wParam == 13)
                   {
                   int SendTextLength = GetWindowTextLength(SendBar) + 1;
                   char MyText[SendTextLength + 1];
                   GetWindowText(SendBar, MyText, SendTextLength);
                   MyText[SendTextLength + 1] = '\n';
                   std::string TextString = MyText;
                   SetWindowText(TextBox, TextString.c_str());
                   SetWindowText(SendBar, NULL);   


Ideas?

OnlyMeat

#3
Quote from: Spilled[DW] on June 20, 2005, 02:46 PM
\n** i meant, typo sorry. Heres my code:

LRESULT CALLBACK MyTextProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
        switch (message)
        {
               case WM_KEYDOWN:
                   if ((int) wParam == 13)
                   {
                   int SendTextLength = GetWindowTextLength(SendBar) + 1;
                   char MyText[SendTextLength + 1];
                   GetWindowText(SendBar, MyText, SendTextLength);
                   MyText[SendTextLength + 1] = '\n';
                   std::string TextString = MyText;
                   SetWindowText(TextBox, TextString.c_str());
                   SetWindowText(SendBar, NULL);   


Ideas?

Two things.
(1) MyText[SendTextLength + 1], The last character should be the null terminator if im not mistaken. Replacing it with \n might be causing you problems.

(2) If i remember correctly normally the line delimiters for text streams are carriage return + line feed, which would be \r\n. Could be wrong on that though, if it's not just stick with \n.

Try this:


std::string TextString = MyText;
TextString += "\r\n";


Also a small note, you can actually use a std::string as the buffer, it's not necessary to use a char tempory.

UserLoser.

Eww, use constant.


if((int)wParam == VK_RETURN) { ...

Spilled

Now that i have got this working, thanks to the fast help, i have ran into another problem. Now when i type it goes to the text box but it doesn't auto scroll down. Now in the createwindow api i have include AUTOVSCROLL. Any ideas? Thanks again!

OnlyMeat

#6
Quote from: Spilled[DW] on June 21, 2005, 12:38 PM
Now that i have got this working, thanks to the fast help, i have ran into another problem. Now when i type it goes to the text box but it doesn't auto scroll down. Now in the createwindow api i have include AUTOVSCROLL. Any ideas? Thanks again!

From what i remember the ES_AUTOVSCROLL style enables automatic scrolling when the user hits the return key. Setting the text programmatically will not have the same effect. You have to scroll to the line you want in code.

You can use the EM_LINESCROLL message to force the multiline edit control to scroll to a number of lines. Use that in conjunction with EM_GETLINECOUNT to determine how many lines to scroll to the end of the control, if thats what you want to do that is.

EM_LINEINDEX and EM_LINEFROMCHAR, can be used to determine the current line.

Another quick way of scrolling to the end of the control is using the EM_SETSEL message, and specifying the last character index.

Spilled

Appreciate your help OnlyMeat, thanks.