Solved

Default CButton doens't work when created programmatically

Posted on 2007-04-03
3
689 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 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
building a service to accessed via telnet client, want colors ? 4 98
Path of Workbook 3 87
Not needed 13 129
Problem to App 4 120
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
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…
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.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

726 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