?
Solved

MessageDlg default button!!

Posted on 2003-04-01
13
Medium Priority
?
620 Views
Last Modified: 2008-01-09
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
Comment
Question by:morees
[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
  • 4
  • 3
  • 3
  • +2
13 Comments
 
LVL 3

Expert Comment

by:Nosfedra
ID: 8244946
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
 

Expert Comment

by:GBOB
ID: 8250094
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
 

Expert Comment

by:GBOB
ID: 8250114
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
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.

 
LVL 49

Expert Comment

by:DanRollins
ID: 8252030
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
 
LVL 3

Expert Comment

by:Nosfedra
ID: 8252114
@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
 
LVL 49

Accepted Solution

by:
DanRollins earned 400 total points
ID: 8252480
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
 
LVL 3

Expert Comment

by:Nosfedra
ID: 8269282
Thanks.
0
 

Author Comment

by:morees
ID: 8269680
I did not say thanx yet.......
THANX.......
it works excelent
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 8270632
morees,
I think you awarded the points to the wrong person.
What comment helped you to solve the problem?
-- Dan
0
 

Author Comment

by:morees
ID: 8281839
Nosfedra

Sorry, I awarded the points to Dan.
I OW YOU BIG TIME!!!!!!!!!
Sorry about this.
Cheers......
0
 
LVL 1

Expert Comment

by:Computer101
ID: 8287379
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
 
LVL 49

Expert Comment

by:DanRollins
ID: 8289145
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
 

Author Comment

by:morees
ID: 8289578
Thanx Dan
Sorry Nosfedra
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
Suggested Courses

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