Handling Text

Oct 26, 2010 at 5:33am
Hello, I know I can just use WM_KEYDOWN in my message loop or window procedure to check what key I am pressing. I wanted a way to check if I pressed enter and then add a '\n' to my text, not a new line, but the actual text \n. Didn't work out too well. I checked if I pressed VK_RETURNwith:

1
2
if (VK_RETURN == msg.wParam)
     // Add stuff here 


In my message loop and then I tried to make the window title a string variable that I would update depending on if I pressed enter or not in the message loop.

Is there a better way to check if I pressed a button and then update the text that I could use? Any tips or information on text handling of any kind? Thanks to anyone who can answer my question(s)
Last edited on Oct 26, 2010 at 5:34am
Oct 26, 2010 at 7:31am
You'll have to subclass the edit control, see http://msdn.microsoft.com/en-us/library/bb762102(v=VS.85).aspx

The subclass callback procedure:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
LRESULT CALLBACK SubProc(HWND hWnd, UINT uMsg, WPARAM wParam,
                               LPARAM lParam, UINT_PTR uIdSubclass, DWORD_PTR dwRefData)
{
    switch (uMsg)
    {
    case WM_CHAR:
         if(wParam=='\r') // check for return key
           {
               DefSubclassProc(hWnd, WM_CHAR, '\\', lParam);
               DefSubclassProc(hWnd, WM_CHAR, 'n', lParam);
           }


        break;
    }
    return DefSubclassProc(hWnd, uMsg, wParam, lParam);
}

Your edit control must have ES_MULTILINE style.
Topic archived. No new replies allowed.