Link to home
Start Free TrialLog in
Avatar of tanm
tanm

asked on

coloring the message dialog..

Is there a way to display a message dialog with customised colours.?
I am using the "messagedlg()" command.
Avatar of rene100
rene100

Hi

I think this isn't possible, because MessageDlg() uses a windows-api-function to display the messagebox....
The colors of the msgbox are determined by the system settings, so you could change these settings..


regards
rene
ASKER CERTIFIED SOLUTION
Avatar of d32coder
d32coder

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi,

It is not possible without creating your own form ! Because windows is calling an API .
Not necessarily ... I think you can override the CreateMessageDialog() for that ...

Let me check.
Ok ... my answer is "Yes", according to the question.  The question simply says "Is there a way...?" and yes, there is.  Not with MessageDlg(), but there sure is.  And except for the color, the dialog looks exactly like the one with MessageDlg().

If you are willing to change all the MessageDlg() commands in your app to, say, MyMessageDlg(), you can change the background of your boxes to a different color.  

Of course, you have to write your own MyMessageDlg like this:

function MyMessageDlg(const Msg: string; DlgType: TMsgDlgType; Buttons: TMsgDlgButtons; HelpCtx: Longint): Integer;
begin
  with CreateMessageDialog(Msg, DlgType, Buttons) do
  begin
    try // ..finally
      HelpContext := HelpCtx;
      // Let's try red
      Color := $000000FF;
      Result := ShowModal;
    finally
      free;
    end; // try
  end;
end;

If you try, you can see that only the background is red; the buttons are still grey.  

Now that I think of it, what I did is exactly what d32coder said... I have created a new Form that emulates the messagebox, with a coloring twist.  I just created the form using code supplied by Delphi.

I personally will consider this good enough code.  ^_^

By the way, if you want to change the button colors as well, do post a comment here.  
Avatar of tanm

ASKER

Brilliant! That's is precisely what i need..
Thanks very much..