Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 629
  • Last Modified:

MessageDlg default button!!

Hi there ppl.

I'm using Borland c++ Builder 5.
Is there a way that I can change the default button selected when a message dialog is diplayed.
This is my message dialog:
MessageDlg("blah blah", mtConfirmation, TMsgDlgButtons()  << mbYes << mbNo , 0);

The default button is Yes, I want the default button to be No.
Is this possible and how.

Thanx
0
morees
Asked:
morees
  • 4
  • 3
  • 3
  • +2
1 Solution
 
NosfedraCommented:
I don't know much about the builder, but it does use the win32 API underneath, AFAIK.

The default push buttons have the BS_DEFPUSHBUTTON bitflag set.
You could try the following (taken straight out of the MSDN):

   // Reset the current default push button to a regular button.
   SendDlgItemMessage(hDlg, <ID of current default push button>,
         BM_SETSTYLE, BS_PUSHBUTTON, (LONG)TRUE);

   // Update the default push button's control ID.
   SendMessage(hDlg, DM_SETDEFID, <ID of new default push button>,
         0L);

   // Set the new style.
   SendDlgItemMessage(hDlg, <ID of new default push button>,
         BM_SETSTYLE, BS_DEFPUSHBUTTON, (LONG)TRUE);

Hope this helps.
--Razvan
0
 
GBOBCommented:
The TButton class has a Default property. Set this to true for the button you want to be the default. This can be done at design time or run time.

The system accepts Default being set to true for more than one button. Make sure that Default is set to false for all the other buttons in order to get the results you expect.

Hope this helps.
0
 
GBOBCommented:
That applies if you've designed your own message box. If you use MessageBox instead of MessageDlg then you can use the WinApi flags for the box which allow you to define the default button.
0
Independent Software Vendors: 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!

 
DanRollinsCommented:
I don't use the Borland stuff, but if MessageDlg is the same as the MessageBox Win32 API function, then there is no way to set a different default button.  

Just construct your own dialog box and set the default in the dialog editor.

-- Dan
0
 
NosfedraCommented:
@Dan...
Hey, that was a refresher...
There is a way to specify which button is selected by default in message box:
MB_DEFBUTTONxxx, where xxx goes from 1 to 4, depending on which button you want to set as default button.

So, if you do:
MessageBox(NULL,"A","B",MB_YESNOCANCEL | MB_DEFBUTTON2), you'll have "No" selected.

Cheers,
--Razvan
0
 
DanRollinsCommented:
Nosfedra,
You are absolutely correct.  I used to know that, but then I had to memorize my mom's new phone number, and something had to go... :)
0
 
NosfedraCommented:
Thanks.
0
 
moreesAuthor Commented:
I did not say thanx yet.......
THANX.......
it works excelent
0
 
DanRollinsCommented:
morees,
I think you awarded the points to the wrong person.
What comment helped you to solve the problem?
-- Dan
0
 
moreesAuthor Commented:
Nosfedra

Sorry, I awarded the points to Dan.
I OW YOU BIG TIME!!!!!!!!!
Sorry about this.
Cheers......
0
 
Computer101Commented:
It is not common practice to take points away.  What I have done is make a 100 point question for Nosfedra in this topic area for the correct answer

Computer101
E-E Admin
0
 
DanRollinsCommented:
Nosfedra,
Please click this link, and enter a short comment.  Then you will get the points that you deserve.

    http://www.experts-exchange.com/Programming/Programming_Languages/Cplusplus/Q_20577470.html
0
 
moreesAuthor Commented:
Thanx Dan
Sorry Nosfedra
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 4
  • 3
  • 3
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now