Solved

Default CButton doens't work when created programmatically

Posted on 2007-04-03
3
681 Views
Last Modified: 2013-11-20
When I create a CButton using Create, and I set the style to BS_DEFPUSHBUTTON, the button doesn't receive the button click message when the user hits the enter key.  It generates the OnOK message.  When the button is created using the resource editor and the style is set to default button, everything works correctly.  How do I make a button the default button when creating it programmatically?  Do I have to determine the default myself by handling the DM_GETDEFID message?  Is there a better way?
0
Comment
Question by:kevinbenedict
3 Comments
 
LVL 9

Accepted Solution

by:
Priyesh earned 500 total points
ID: 18848108
Normally you make a button default by setting the BS_DEFPUSHBUTTON style. If the visual cues doesnt stick, you can try sending a BM_SETSTYLE message to the button.
m_btn.SendMessage(BM_SETSTYLE, BS_DEFPUSHBUTTON, TRUE) ;

This is from MSDN documentation of DM_GETDEFID
An application sends a DM_GETDEFID message to retrieve the identifier of the default push button control for a dialog box.
I think you will have to handle DM_GETDEFID.

For this,
ON_MESSAGE(DM_GETDEFID, OnGetDefID)

LRESULT CMyView::OnGetDefID(WPARAM wPar, LPARAM lPar)
{
   return MAKEWPARAM(1200, DC_HASDEFID) ;//1200 is the button id which you want to make default.
}

Somebody else might know a better way here.
0
 
LVL 19

Expert Comment

by:alb66
ID: 18848770
Be sure that no other buttons in the dialog have the BS_DEFPUSHBUTTON style
0
 

Author Comment

by:kevinbenedict
ID: 18851861
This works great in Windows but not on a PocketPC for some reason.  I am using eVC++ and am targeting mobile devices.
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Strange date stored 22 118
set up trigger (or something) to rename files (starting with ATL) in a linux directory 6 53
sumDigits challenge 9 146
string initialization in java 11 113
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

813 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now