-
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
-
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.
-
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);
}
-
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
-
you can subclass them all, and have them use the same windows procedure.
-
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?
-
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);
}
-
Ahhh, thank you very much.
Regards,
Tyouk