Solved

DialogBox

Posted on 2001-08-03
20
796 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

 

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 300 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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

Suggested Solutions

As more and more people are shifting to the latest .Net frameworks, the windows presentation framework is gaining importance by the day. Many people are now turning to WPF controls to provide a rich user experience. I have been using WPF controls fo…
What my article will show is if you ever had to do processing to a listbox without being able to just select all the items in it. My software Visual Studio 2008 crystal report v11 My issue was I wanted to add crystal report to a form and show…
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…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

735 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