vs.net and dialog applications

Started by
8 comments, last by emptyhead 21 years, 7 months ago
hi! When i want to quickly make a small utility, i usually just create a dialog application (mfc style), remove all the default buttons (ok, cancel) and start adding what i want. This worked like a charm in visual studio 6, but since i upgraded to vs 7.0 i''ve had some irritating problems with it. Everythings seems to be working as it should, except that if i press ESC or return the application quits! this is the expected behaviour when the ok and cancel buttons are left in the dialog, but it surely cant be when they are gone? And the weirdest thing is that i cant seem to overload any of the key input messages to prevent it from happening, almost as if this behaviour is hardcoded... Do anyone have a clue whats going on? or am i f***ed /emptyhead
:wq!
Advertisement
Actually it is the normal behaviour for Dialogs and Property Sheets even for VS6. All you have to do is override
OnOK()
and
OnCancel()
to not do anything. Even though you deleted the buttons, the methods are still there in the dialog itself (from the class). Once you press ESC, OnCancel() is usually called. The buttons just uses the message ID_CANCEL (I think) to call OnCancel().

Once you override OnCancel() and OnOK() to not do anything, ESC wont work anymore. I hope this helps.
Thanks for the reply!
I''ve tried overloading the functions you mentioned, and it works, almost. The application doesnt quit when i press esc or return anymore (yiehaa!), but now it won''t close at all, not when i click the "close" button and not when i press ALT+F4

But atleast now i know where to look... thanks again!

/emptyhead
:wq!
Now i can close the application again, just captured WM_CLOSE. But i still don''t know how to get WM_KEYDOWN for VK_RETURN, VK_ESC... anoying to say the least.

anyone?

/emptyhead
:wq!
in the event handler for the button you want to close the Dialog try putting

	CDialog::OnOK();or	CDialog::OnCancel(); 


and that should allow your dialog to close

quote:Original post by _the_phantom_
in the event handler for the button you want to close the Dialog try putting

	CDialog::OnOK();or	CDialog::OnCancel();  


and that should allow your dialog to close



Unfortunately, that wont work because he has overridden OnOK() and OnCancel() to not do anything so calling them still wont close the dialog.

.Net must do strange things now, to not close the window. Must be even more oob than I thought. Does the message map for ON_WM_KEYDOWN actually call the OnKeyDown( ... ) method? or is totally ignoring it? Try looking at ON_NOTIFY.
Yes, the onKeyDown function is called, but not for the return, escape or cursor keys. I''ve solved the problem by overloading the PreTranslateMessage funtion and calling the OnKeyDown myself. Not a very nice solution, but atleast everything is working the way it should now.

thanks for helping me out everyone!

/emptyhead
:wq!
quote:Original post by AndyTang
Unfortunately, that wont work because he has overridden OnOK() and OnCancel() to not do anything so calling them still wont close the dialog.

.Net must do strange things now, to not close the window. Must be even more oob than I thought. Does the message map for ON_WM_KEYDOWN actually call the OnKeyDown( ... ) method? or is totally ignoring it? Try looking at ON_NOTIFY.


If you look at the example I gave you are in fact calling the base classe''s OnOK() function and NOT teh one in the dialog class he will be using, which will allow ''im to close the dialog correctly.

and yes, it works, because I''ve got a project where i override the OnOK() and OnCancel() functions of my dialog class and in them call my shutdown code and then either the baseclass'' OnOK() or OnCancel() depending on which event handler i''m in.
quote:Original post by _the_phantom_
If you look at the example I gave you are in fact calling the base classe''s OnOK() function and NOT teh one in the dialog class he will be using, which will allow ''im to close the dialog correctly.

and yes, it works, because I''ve got a project where i override the OnOK() and OnCancel() functions of my dialog class and in them call my shutdown code and then either the baseclass'' OnOK() or OnCancel() depending on which event handler i''m in.


Sorry, your right. Must have misread or something, dunno what I was thinking. but calling the base class method will work. Sorry
quite all right, i figured you hadnt read it properly

This topic is closed to new replies.

Advertisement