Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

DialogBox

Posted on 2001-08-03
20
Medium Priority
?
807 Views
Last Modified: 2013-12-03
I Have a DialogBox with a ComboBox in it, I want to call to a function when the user hits <enter> in the ComboBox, I subclassed the window procedure of the ComboBox so I could check the WN_CHAR messages, the problem is, when the user hits <enter> in the ComboBox the DialogBox doesnt send an WM_CHAR message to it's window procedure, it sends WM_COMMAND with IDOK to the Dialog Procedure which ends the dialog...

How do I fix that?

no MFC
VC++
0
Comment
Question by:dafoki
  • 9
  • 8
  • 2
  • +1
20 Comments
 

Expert Comment

by:sdjefferies
ID: 6348890
Have you tried unticking the "default button" property? Thus preventing the IDOK event triggering on return.

Simon
0
 

Author Comment

by:dafoki
ID: 6348961
i tried that, it still triger the IDOK
0
 
LVL 2

Expert Comment

by:Lockias
ID: 6349116
You need to handle the WM_KEYDOWN message and look for the wParam to be VK_RETURN.  You will only find alpha numerics in come through the WM_CHAR message.

~Lockias
0
NEW Veeam Backup for Microsoft Office 365 1.5

With Office 365, it’s your data and your responsibility to protect it. NEW Veeam Backup for Microsoft Office 365 eliminates the risk of losing access to your Office 365 data.

 

Author Comment

by:dafoki
ID: 6349401
This is my ComboBox procedure:
HRESULT CALLBACK myComboProc(HWND hWnd,UINT Msg,WPARAM wParam,LPARAM lParam)
{
     if(Msg == WM_KEYDOWN && wParam == VK_RETURN)
     {
          MessageBox(0,"Enter","",0);
          return 0;
     }
     return CallWindowProc(OldComboProc,hWnd,Msg,wParam,lParam);
}

it's not working......
0
 
LVL 2

Expert Comment

by:Lockias
ID: 6349475
Test to see if your combo is getting keydown messages other than for the return.  I suspect that return (and I think the escape key as well) may be special cases that the main dialog get first crack at and your combo box never sees.  In this case you will need to handle these events in your dialog procedure, or mess around with the message translation stuff.  

I have seen this before.  If what I stated above does not get anywhere, I will look more deeply and thoroughly at this.

~Lockias
0
 
LVL 5

Expert Comment

by:robpitt
ID: 6349495
There is a mechanism by which a control can signal what keypresses it is interested in.

This mechanism is the WM_GETDLGCODE message which is sent by windows to the control.

Add code to your myComboProc() so that the control returns WANTALLKEYS when windows sends the WM_GETDLGCODE message t the control.

Rob
0
 

Author Comment

by:dafoki
ID: 6350035
Rob, I'm not sure I understand how to use the WM_GETDLGCODE,
all I need to do is to return DLGC_WANTALLKEYS when I get the message?

This how my Combo procedure should look like?

switch(Msg)
{
     case WM_GETDLGCODE:
          return DLGC_WANTALLKEYS;
     case WM_KEYDOWN:
          if(wParam == VK_RETURN)
               MessageBox(0,"Enter","",0);
          return 0;
}
0
 
LVL 5

Expert Comment

by:robpitt
ID: 6350403
I think that should work, though you might want to do a CallWindowProc first.
E.g.

    case WM_GETDLGCODE:
        CallWindowProc(OldComboProc,...
        return DLGC_WANTALLKEYS;

Let us know how it goes.
0
 

Author Comment

by:dafoki
ID: 6351067
it's not working........

i an expamle for WM_GETDLGCODE, i tried to combine in with my code, and it's still not working...
why?????

HRESULT CALLBACK myComboProc(HWND hWnd,UINT Msg,WPARAM wParam,LPARAM lParam)
{
     LRESULT lRet;
     LPMSG lpmsg;

     switch(Msg)
     {
     case WM_GETDLGCODE:
          lRet = CallWindowProc(OldComboProc,hWnd,Msg,wParam,lParam);
         if (lParam)
          {
               lpmsg= (LPMSG) lParam;
               if (lpmsg->message == WM_KEYDOWN)
               {
                    if (lpmsg->wParam == VK_RETURN)
                              lRet |= DLGC_WANTALLKEYS;
               }
          }
        return (lRet);
     case WM_KEYDOWN:
          if(wParam == VK_RETURN)
               MessageBox(hWnd,"ENTER","",0);
          return 0;
     }
     return CallWindowProc(OldComboProc,hWnd,Msg,wParam,lParam);
}
0
 
LVL 5

Expert Comment

by:robpitt
ID: 6351115
That's odd, I would have expected that to work!

You might want to checkout http://support.microsoft.com/support/kb/articles/Q102/5/89.asp
This artcile talks about the very same issue in the context of EDIT boxes - it should be applicable.

Rob
0
 

Author Comment

by:dafoki
ID: 6351159
I know what's wrong, the dialog procedure never gets the WM_DLGCODE message,

case WM_GETDLGCODE:
     MessageBox(hWnd,"DLG","",0); // it never pops
          return(DLGC_WANTALLKEYS | CallWindowProc(OldComboProc,hWnd,Msg

The MessagewBox doesnt pop, any idea why?
0
 
LVL 5

Expert Comment

by:robpitt
ID: 6351355
Just to clarify, all of the above WM_GETDLGODE stuff should be put in the replacement combo box wndproc.
I imagine you installed this by doing something like:
OldComboProc=SetWindowLong(hCombo,GWL_WNDPROC,NewComboProc);


Another question... is your dialog box modal or modeless (i.e. was it created with DialogBox() or CreateDialog()). If it is modeless do call IsDialogMessage() correctly in your main message loop?
0
 
LVL 5

Expert Comment

by:robpitt
ID: 6351382
Just to clarify, all of the above WM_GETDLGODE stuff should be put in the replacement combo box wndproc.
I imagine you installed this by doing something like:
OldComboProc=SetWindowLong(hCombo,GWL_WNDPROC,NewComboProc);


Another question... is your dialog box modal or modeless (i.e. was it created with DialogBox() or CreateDialog()). If it is modeless do call IsDialogMessage() correctly in your main message loop?
0
 

Author Comment

by:dafoki
ID: 6351421
it's ok i fixed it.......there was somthing wrong with my code, now i get the WM_GETDLGCODE, but i still cant make my dialog proc to send me a WM_CHAR/WM_KEYDOWN when the user hits <enter>....
0
 
LVL 5

Expert Comment

by:robpitt
ID: 6351445
Ahhhh, I bet its because its the EDIT control inside the combobox that actually has the keyboard focus!

ANYWAY, I just found this which should do exactly what you want...

http://msdn.microsoft.com/library/en-us/winui/hh/winui/combobox_2hbm.asp
0
 

Author Comment

by:dafoki
ID: 6351494
is that how they do it?
hwndEdit1 = ChildWindowFromPoint(hwndCombo1, pt);
hwndEdit2 = ChildWindowFromPoint(hwndCombo2, pt);

what does the ChildWindowFromPoint() do? (i didnt understand from the MSDN)
0
 
LVL 5

Expert Comment

by:robpitt
ID: 6351508
If you hadn't gathered, an editable combo box control contains an edit control as a child window.

All the ChildWindowFromPoint thing does is get the child window (the edit control) that is at position (1,1) inside the combo box.

Since there is only likely to be one child window within the combo box, I would have just done
    GetWindow(hCombo,GW_CHILD);
to get the same result.
0
 

Author Comment

by:dafoki
ID: 6351655
i think i got it,
After i get the child edit window,  inside the combo box than i use the WM_GETDLGCODE to monitor which keys was pressed
0
 
LVL 5

Accepted Solution

by:
robpitt earned 1200 total points
ID: 6351687
Almost. I think you'll actually need a mixture of the two samples I've refered you to thus far.

You should subclass the edit control inside the combo box and then in your new edit procedure you can handle WM_GETDLGCODE and WM_KEYDOWN.

0
 

Author Comment

by:dafoki
ID: 6351783
thanks for all the help
0

Featured Post

Fill in the form and get your FREE NFR key NOW!

Veeam is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article shows how to make a Windows 7 gadget that accepts files dropped from the Windows Explorer.  It also illustrates how to give your gadget a non-rectangular shape and how to add some nifty visual effects to text displayed in a your gadget.…
This article describes how to add a user-defined command button to the Windows 7 Explorer toolbar.  In the previous article (http://www.experts-exchange.com/A_2172.html), we saw how to put the Delete button back there where it belongs.  "Delete" is …
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …

916 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question