Thread: editbox problem

  1. #1
    Registered User
    Join Date
    May 2002
    Posts
    132

    editbox problem

    Hi,

    I have an editbox problem. I create the editbox with the following:

    Code:
    settings.hSEdit = CreateWindow("edit", 
    "", WS_CHILD | WS_VISIBLE | WS_BORDER
    | ES_AUTOHSCROLL | ES_MULTILINE | ES_WANTRETURN, 
    rect.left - 1, rect.bottom - 17, rect.right + 2 - rect.left, 18, 
    hwnd, NULL, g_hInst, NULL);
    The odd thing about this is if I changed hwnd to settings.hStatus (which is an HWND that I use to store the parent window's handle upon creation in another function), in that function call it wont work. I've even tried comparing hwnd to settings.hStatus and using a MessageBox() call to determine the results and it says that they don't match. But thats not even a huge issue cause I can deal with it this way, but it might be a part of my next problem so thats why I included it. The above code is from my windows procedure function for the window in which the editbox is being created for.

    Now what my true problem is, is I never receive the messages in which I should be receiving in that very same windows procedure. I use the following to see if I even receive the messages:

    Code:
    case WM_KEYDOWN:
    			MessageBox(NULL, "a key is pressed right now (StatusWndProc)", "keypress", MB_OK);
                                                    return(DefMDIChildProc(hwnd, Message, wParam, lParam)); // so normal results still occur
    			break;
    But I never see the message box ever popup. I've tried to do this with also the WM_CHAR message and others but it's never received. I've checked the MSDN for all possible windows messages related to an editbox but I can't find any others that would inform me of text being entered into the editbox (I know I could use the EN_CHANGE notification of the WM_COMMAND message to see if changes were made, but I'm looking for a message where I can determine if certain keys were being pressed and not just if changes were made to the editbox's contents).

    I'm using MSVC++ .NET 2003 on WinXP, incase thats needed.

    Any help would be greatly appreciated,
    Tyouk

  2. #2
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    if you use the WS_CHILD style then the HMENU param of the Create() becomes the control/window/dialogs resource ID number. This could be a problem but I don't think so.


    I'm not 100% sure but I think your parent won't get keyboard input while the edit control has the focus. The msg is sent to the edit only as an EN_CHANGE.
    Try setting the focus to the whole dialog and then see if you get the msgs.
    "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
    Sep 2004
    Location
    California
    Posts
    3,268
    You can subclass the edit control to catch the WM_KEYDOWN message. Here is how you do this:

    Code:
    // Place the following in some initialization code somewhere (maybe WM_INITDIALOG).
    //  g_oldProc is of type WNDPROC.  editHwnd is your edit controls
    // HWND.
    g_oldProc = (WNDPROC)SetWindowLong(editHwnd,GWL_WNDPROC,(LONG)WindowProc);
    
    // WindowProc is your edit boxes new window procedure.
    LRESULT CALLBACK WindowProc(HWND hwnd,
        UINT uMsg,
        WPARAM wParam,
        LPARAM lParam
    )
    {
    	if(uMsg == WM_KEYDOWN)
    		MessageBox(NULL,"Got MSG","ADS",MB_OK);
    	return CallWindowProc(g_oldProc,hwnd,uMsg,wParam,lParam);
    }

  4. #4
    Registered User
    Join Date
    May 2002
    Posts
    132
    Okay the code worked great, thanks a lot for that help. Got one more question for you though if your able to help me out any...

    Okay I have similar editboxes to the one I just subclassed. Each is using a different windows procedure because I have a series of registered classes for the different window types that my program creates in it's different uses. Each of these editboxes are used as "command line" type thing where users can type commands into them. Is there a way I can subclass these to all use the new windows procedure I just created when I subclassed the last editbox? Or am I forced to subclass each individually with separate windows procedures even though they will all be doing the same task?

    Well I guess I could infact just have each one under WM_KEYDOWN pass the input off to a common function that deals with the input, but that isn't the most desirable result. Thats why I want them all to use the same proc function if possible.

    Any suggestions?

    Thanks,
    Tyouk
    Last edited by tyouk; 10-05-2004 at 04:45 PM. Reason: Doesn't sound right.

  5. #5
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,268
    you can subclass them all, and have them use the same windows procedure.

  6. #6
    Registered User
    Join Date
    May 2002
    Posts
    132
    how is that possible then? when you call CallWindowProc() you are also passing g_oldProc into that function, or does this really matter what that value is?

  7. #7
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    You can store the old window procedure with each window:
    Code:
    // Place the following in some initialization code somewhere (maybe WM_INITDIALOG).
    // editHwnd is your edit controls HWND.
    WNDPROC oldProc = (WNDPROC) SetWindowLongPtr(editHwnd,GWLP_WNDPROC,(LONG_PTR)  WindowProc);
    
    /* Store old window procedure with window. */
    SetWindowLongPtr(editHwnd, GWLP_USERDATA, (LONG_PTR) oldProc);
    
    
    
    // WindowProc is your edit boxes new window procedure.
    LRESULT CALLBACK WindowProc(HWND hwnd,
        UINT uMsg,
        WPARAM wParam,
        LPARAM lParam
    )
    {
    	if(uMsg == WM_KEYDOWN)
    		MessageBox(NULL,"Got MSG","ADS",MB_OK);
    
    	/* Retrieve and call old window procedure. */
    	WNDPROC oldProc = (WNDPROC) GetWindowLongPtr(hwnd, GWLP_USERDATA);
    	return CallWindowProc(oldProc,hwnd,uMsg,wParam,lParam);  
    }

  8. #8
    Registered User
    Join Date
    May 2002
    Posts
    132
    Ahhh, thank you very much.

    Regards,
    Tyouk

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Memory problem with Borland C 3.1
    By AZ1699 in forum C Programming
    Replies: 16
    Last Post: 11-16-2007, 11:22 AM
  2. Someone having same problem with Code Block?
    By ofayto in forum C++ Programming
    Replies: 1
    Last Post: 07-12-2007, 08:38 AM
  3. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 02:51 PM
  4. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 06:54 PM
  5. Laptop Problem
    By Boomba in forum Tech Board
    Replies: 1
    Last Post: 03-07-2006, 06:24 PM