- changing DEFID to child dialog
- Posted by Martijn on July 30th, 2003
Hi,
My application uses tabsheets which are shown and hidden according to the
tabs being selected. The sheets themselves are defined through dialog
templates. One of them contains comboboxes. I want these - and some other
controls - to respond to the ENTER key. From what I reckon I have three
options:
1) Remove the IsDialogMessage from my message loop, or make a special case
depending on the message,
2) Subclass the control to handle WM_GETDLGCODE messages,
3) To make a special handler in my DEFPUSHBUTTON handler.
Modularity (on a sheet basis) is important, ergo #1 is not appropriate.
Subclassing is my last resort, so I tried to use DM_SETDEFID to change the
DEFPUSHBUTTON when the page is shown. After sending this message to the
child dialog, visually the changes are made, but when I press enter, a
WM_COMMAND message is sent to the parent dialog! This kills the whole
concept of modularity.
So my question is this: Is there a way to have this message sent to the
child _or_ is there a way to capture the ENTER key which has not been
mentioned here.
Thanks a lot for the help,
--
Martijn Haak
http://www.sereneconcepts.nl
- Posted by Jugoslav Dujic on July 30th, 2003
Martijn wrote:
| Hi,
|
| My application uses tabsheets which are shown and hidden according to the
| tabs being selected. The sheets themselves are defined through dialog
| templates. One of them contains comboboxes. I want these - and some other
| controls - to respond to the ENTER key. From what I reckon I have three
| options:
|
| 1) Remove the IsDialogMessage from my message loop, or make a special case
| depending on the message,
|
| 2) Subclass the control to handle WM_GETDLGCODE messages,
|
| 3) To make a special handler in my DEFPUSHBUTTON handler.
|
| Modularity (on a sheet basis) is important, ergo #1 is not appropriate.
|
| Subclassing is my last resort, so I tried to use DM_SETDEFID to change the
| DEFPUSHBUTTON when the page is shown. After sending this message to the
| child dialog, visually the changes are made, but when I press enter, a
| WM_COMMAND message is sent to the parent dialog! This kills the whole
| concept of modularity.
|
| So my question is this: Is there a way to have this message sent to the
| child _or_ is there a way to capture the ENTER key which has not been
| mentioned here.
Well, what's so hard with subcllassing?
As a variation on the theme, I'd suggest using SUPERclassing instead.
That is, on startup you register your own window class (e.g. "MyComboBox"),
whose window procedure handles
WM_GETDLGCODE
(MSG)lParam->message==WM_KEYDOWN
(MSG)lParam->wParam==VK_ENTER
returning DLGC_WANTMESSAGE, (see example in Q92905)
and WM_KEYDOWN/VK_ENTER, doing what you need.
In all other cases, call normal combo box procedure (you can obtain
it using GetClassInfo).
With superclassing, you can enter "MyComboBox"-es in design time.
The only inconvenience is that resource editor will not know that
it is kinda combo box, so you'll have to enter styles & size
manually in hex form.
Of course, subclassing in above manner will work as well, but
you will have to subclass every control you want explicitly from
the code.
--
Jugoslav
___________
www.geocities.com/jdujic
- Posted by Martijn on July 30th, 2003
Jugoslav Dujic wrote:
It's not hard, I just don't want to get the extra overhead when it is
unneccesary. I did come up with a scheme that has the parent sends a
message to the child window, which works fine. But now the question is,
which window has (or had, at the time of the message) the focus - I can use
GetFocus, but the focus may have gone to another control.
Another thing I noticed is that a Tree View does capture the ENTER key -
does it handle WM_GETDLGCODE messages? (it has some other non-standard
behaviour such as not sending WM_LBUTTONUP messages when a user clicks an
items label)
Thanks for the help!
--
Martijn Haak
http://www.sereneconcepts.nl
- Posted by Jugoslav Dujic on July 30th, 2003
Martijn wrote:
| Jugoslav Dujic wrote:
|| Martijn wrote:
||| Hi,
|||
||| My application uses tabsheets which are shown and hidden according
||| to the tabs being selected. The sheets themselves are defined
||| through dialog templates. One of them contains comboboxes. I want
||| these - and some other controls - to respond to the ENTER key. From
||| what I reckon I have three options:
|||
||| 1) Remove the IsDialogMessage from my message loop, or make a
||| special case depending on the message,
|||
||| 2) Subclass the control to handle WM_GETDLGCODE messages,
|||
||| 3) To make a special handler in my DEFPUSHBUTTON handler.
|||
||| Modularity (on a sheet basis) is important, ergo #1 is not
||| appropriate.
|||
||| Subclassing is my last resort, so I tried to use DM_SETDEFID to
||| change the DEFPUSHBUTTON when the page is shown. After sending this
||| message to the child dialog, visually the changes are made, but when
||| I press enter, a WM_COMMAND message is sent to the parent dialog!
||| This kills the whole concept of modularity.
|||
||| So my question is this: Is there a way to have this message sent to
||| the child _or_ is there a way to capture the ENTER key which has not
||| been mentioned here.
||
|| Well, what's so hard with subcllassing?
|
| It's not hard, I just don't want to get the extra overhead when it is
| unneccesary. I did come up with a scheme that has the parent sends a
| message to the child window, which works fine. But now the question is,
| which window has (or had, at the time of the message) the focus - I can use
| GetFocus, but the focus may have gone to another control.
I'm not sure -- try it yourself. For what it's worth, WM_NEXTDLGCTL
works as expected (on IDOK, it sets focus to the control next to the
one that had focus, not to the control next to IDOK), so I'd expect that
SetFocus will return the "right" one as well.
| Another thing I noticed is that a Tree View does capture the ENTER key -
| does it handle WM_GETDLGCODE messages? (it has some other non-standard
| behaviour such as not sending WM_LBUTTONUP messages when a user clicks an
| items label)
Erm, it does not by default -- only if subclassed :-)). Use Spy++ and
point to Explorer's TreeView -- see "WindowProc: ...(Unicode)(Subclassed)?"
See also here (the comment below is straighter to the point -- but it uses
DEFPUSHBUTTON trick):
http://codeguru.earthweb.com/treeview/esc_edit.shtml
http://codeguru.earthweb.com/mfc/comments/14012.shtml
--
Jugoslav
___________
www.geocities.com/jdujic
- Posted by Martijn on July 30th, 2003
Jugoslav Dujic wrote:
I mean that the user may have done something that causes a switch in focus
_before_ the message is processed (<rant>altough the dialog messages go
through the same loop, so it would have to be by mouse or other input
device...</rant>)
I've superclassed it, but it calls the old window procedure for must
message, such as WM_GETDLGCODE. Maybe it knows... 
This comes with VC, right? I can't seem to find it as a separate download.
Thanks for the links, I'll go and read them once they're up again 
Thanks again for the help!
--
Martijn Haak
http://www.sereneconcepts.nl