Catching event from edit control/window

This is a discussion on Catching event from edit control/window within the Windows Programming forums, part of the Platform Specific Boards category; Hi, I am trying to catch the VK_RETURN message from a edit control in my window app. I have created ...

  1. #1
    Registered User
    Join Date
    Aug 2001
    Posts
    55

    Catching event from edit control/window

    Hi,

    I am trying to catch the VK_RETURN message from a edit control in my window app. I have created a main window which i them add a edit control like this:

    Code:
    sendTextHandle = CreateWindowEx(
                                 WS_EX_WINDOWEDGE, "EDIT", NULL,
                                 WS_VISIBLE|WS_BORDER|ES_AUTOHSCROLL,
                                10, 415, 500, 30,  mainHwnd, (HMENU)150, 
                                hInstance, NULL);
    where mainHwnd is the handle to main window

    THe edit box is created and display in the main window. But i cant figure out to catch events from it. I can catch when something is being typed into it by the VW_COMMAND, but which message do i switch on for the Enter key. VW_KEYDOWN dosnt catch it.

    Also...when i type in the edit control it goes off and displays the letter for a while in the editbox. I can slow it down by looping on a counter when i recieve a VW_COMMAND message from it, but is there any other way...

    G'n'R

  2. #2
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,859
    Messages for the edit will be sent to the callback for

    mainHwnd

    To get them switch the WM_COMMAND and look for the ID of the control

    I use the cracker from windowsx.h

    idControl = GET_WM_COMMAND_ID( wParam, lParam) ;

    150 is your ID

    I would do something like
    #define IDC_MYEDIT 40001
    this number is greater than those used by the MSVC resource editor and so will not cause a conflict

    If however you need the return from an edit then it must have the

    ES_WANTRETURN which requires the style ES_MULTILINE
    Last edited by novacain; 09-23-2003 at 09:27 PM.
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  3. #3
    Registered User
    Join Date
    Aug 2001
    Posts
    55
    Hi,

    Ok, will try that out.... Still wondering how the input to it works. e.g.

    I type a single character in edit contorl e.g d
    In the display it gets repeated for a while. e.g.

    ddddddddddddddddddddddddddddddddddddddddddd

    It seems its got something do do with the keyboard buffer and i need to clear it for each type the user types a character. I have tried to use while(kbhit)) in the windproc(where i catch the event under VM_COMMAND but dosnt work?

    G'n'R

  4. #4
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,859
    The edit should take care of its own text.

    Sounds like you are creating a loop that is adding the text over and over (while the key is down).

    You should not need to use kbhit()

    Look for an EN_CHANGE message under the edits handler

    that is switch the WM_COMMAND as I said previously then

    Code:
    case WM_COMMAND:
         idControl = GET_WM_COMMAND_ID( wParam, lParam) ;
         switch(idControl)
         {
              case IDC_MYEDIT://the int ID you gave the edit
                      if (EN_CHANGE == HIWORD(wParam))
    For more detailed processing you may want to subclass the control. that is give the edit its own wndproc to handle msg's.
    Do a search for 'subclass' or GetWindowLong() or GetWindowLongPtr()
    as I have posted code before.
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  5. #5
    Registered User
    Join Date
    Aug 2001
    Posts
    55
    Hi,

    By subclassing do you mean creating and filling in a new WNDCLASSEX variable and setting a winproc function there. After that registering it for so to create....

    G'n'R

  6. #6
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,859
    No. that is for actual windows (not controls)

    this is more complex than I think you need.

    What is still going wrong?

    Code:
    lpfnOriginalWndProc = (WNDPROC)GetWindowLong(hWndControl , GWL_WNDPROC);
    SetWindowLong(hWndControl , GWL_WNDPROC, (LONG) NewWndProc);
    This will send the control (hWndControl) msg's to the callback (wndproc function) NewWndProc.
    Where they previously would go to its parents callback, pfnOriginalWndProc.
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  7. #7
    Registered User
    Join Date
    Aug 2001
    Posts
    55
    Hi,

    Ok, i can see what you are doing from the above code. You are getting the default callback for the handle and replacing it by you own. Very cool....And with that i "probably" can catch key events for the handle and catching messages i want. Like WM_PAINT etc.....I looked it up on the documentation but they where using PASCAL stuff (but same logic). Just wondering....In the docs at the end of the subclass function they call the mainHandle winProcedure. Is that correct or should i call the DefWindowProc..at the end (for the subclassed function)?

    I am also wondering about one more thing. In my multi line edit function i have managed to append text etc. I have also managed to change the color on text etc. I am using the following call to append text.

    Code:
    ...formatting buffer etc here...
    
    SendMessage(recieveTextHandle, EM_SETSEL, (WPARAM)
                           textLength,(LPARAM)textLength);
    SendMessage(recieveTextHandle, EM_REPLACESEL,0, (LPARAM)
                           ((LPSTR)buffer));
    This works fine, but when i mess around with the color of text the text of the WHOLE edit control changes. e.g not only the new appended text. My suspicion is that in effects the whole control since the whole control is being repainted and it uses the color set in SetTextColor(...), but are there any tricks of trade i can use here or is this simply the way it is (I will stopp trying and move on then )

    Ok, thanks for you help

    G'n'R

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Multiline Edit Box Parser
    By The Brain in forum Windows Programming
    Replies: 6
    Last Post: 11-01-2005, 06:15 PM
  2. Replies: 3
    Last Post: 07-23-2005, 08:00 AM
  3. delegate & event
    By Micko in forum C# Programming
    Replies: 5
    Last Post: 03-08-2004, 03:05 AM
  4. Replies: 2
    Last Post: 09-22-2003, 01:47 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21