?
Solved

Default CButton doens't work when created programmatically

Posted on 2007-04-03
3
Medium Priority
?
694 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
[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
3 Comments
 
LVL 9

Accepted Solution

by:
Priyesh earned 2000 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
Ready to get certified? Check out some courses that help you prepare for third-party exams.
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.
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses
Course of the Month8 days, 10 hours left to enroll

764 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