Solved

Default CButton doens't work when created programmatically

Posted on 2007-04-03
3
675 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
Comment Utility
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
Comment Utility
Be sure that no other buttons in the dialog have the BS_DEFPUSHBUTTON style
0
 

Author Comment

by:kevinbenedict
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

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. …
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
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.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

762 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

12 Experts available now in Live!

Get 1:1 Help Now