Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Verg

Find the Default Button in a Dialog Box

This topic is 5155 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I''m subclassing the MS Edit control to change the default behavior of hitting "Enter" on a single-line edit. When the user hits Enter on the control, thw WM_KEYDOWN message is intercepted... if the key code is VK_RETURN, there''s a PostMessage() to the default button of the Dialog (BM_CLICK) that should close the Dialog box. This Dialog box is created in the VC6++ IDE... with the "Default Button" style checked. The HWND of the button is found using ::GetWindow() with the Dialog''s HWND as the parent. Tracing the loop, I know the button is being found... because I can retrieve its string ("OK"). But the following doesn''t do as its supposed to.
_buttonStyle = ::GetWindowLong(_hbutton,GWL_STYLE);
if(_buttonStyle & BS_DEFPUSHBUTTON)
     break;
 
The style always comes back as 0x50010000.... and BS_DEFPUSHBUTTON is defined as 0x0001 (which doesn''t match) So, the default button can''t be found. Is there any other way to find the default push button in the dialog, using APIs, without hardcoding anything? Thanks. Chad

Share this post


Link to post
Share on other sites
Advertisement
Ok, I found the solution fairly quickly:


_dlgDefault = ::SendMessage(_hdlg,DM_GETDEFID,0,0);

if(HIWORD(_dlgDefault) == DC_HASDEFID)
_hbutton = ::GetDlgItem(_hdlg,LOWORD(_dlgDefault));

else _hbutton = 0;


But is there an explanation as to why the earlier piece of code wouldn''t work?

Thank ya

Chad

Share this post


Link to post
Share on other sites
The only explanation i can think of is that the button didn''t have the BS_DEFPUSHBUTTON style set in the ressource.

I checked with a test project, and it returned 0x50010001 for the OK-Button. I recon if there''s no default button windows will go and look for a best match (as in IDOK or IDCANCEL?).

Share this post


Link to post
Share on other sites
Your test sounds pretty reasonable... that''s what you should expect.

... maybe it needed a clean rebuild or something? Or maybe it''s an issue with VC++6?

Thanks Endurion.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!