Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Message Box with custom icon 1

Status
Not open for further replies.

JohnCMolyneux

Programmer
Jun 22, 2004
24
GB
Hi.

I've got the following code from the internet (seen it in lots of different places - always the same code with same variable names and code formatting etc..)

function MyMessageBox(lpCaption, lpText: PChar): Integer;
var
MBParams : TMsgBoxParams;
begin
with MBParams do begin
cbSize:=SizeOf(MBParams);
hwndOwner:=Application.Handle;
hInstance:=SysInit.HInstance;
lpszText:=lpText;
lpszCaption:=lpCaption;
lpszIcon:=PChar('MAINICON');
dwStyle:=MB_OK or MB_USERICON;
dwContextHelpId:=0;
lpfnMsgBoxCallback:=nil;
dwLanguageId:=LANG_NEUTRAL;
end;
Result:=Integer(MessageBoxIndirect(MBParams));
end;


Basically, if I run MyMessageDlg('Caption','Message dialog text'); I should get a message box with an ok button and the application's icon shown on it. I don't there's no icon.

Can anyone advise me as to where I've gone wrong?

Thanks,

John.



mf_of_john.gif
 
Oh yeah....PChar('MAINICON') can be changed to a simple 'MAINICON'. Sorry - just ensuring that that wasn't the problem (even though I know string constants are fine as pchar's.)

John.

mf_of_john.gif
 
In QDialogs there is a MessageDlg in which you can specify a picture by assigning a bitmap to it. The code would look something like this:

Code:
uses
QDialogs

... bla ...

QDialogs.MessageDlg('My Caption','My Message',QDialogs.mtInformation,[QDialogs.mbOk],0,[QDialogs.mbOk],MyBitMap);

I hope this helps,

[bobafett] BobbaFet [bobafett]

Everyone has a right to my opinion.
E-mail me at caswegkamp@hotmail.com
 
You can also just use the MessageBox method on TApplication. Delphi defines a global variable called "Application".

function MessageBox(const Text, Caption: PChar; Flags: Longint = MB_OK): Integer;

In any form you can just do:

Code:
Application.MessageBox(Message, Caption, Flags)

Look at the Help file. It tells you how to combine flags to have different buttons/icons on the dialog.
 
Hi,

also remember that, if you want to use the qdialogs unit, you must include the file 'qintf.dll' with your application for deployment.

--------------------------------------
What You See Is What You Get
 
brzdude - erm, did you read the question? And thanks for the insight on the Application object. I've never come across that before. (heh)

mf_of_john.gif
 
For your information, QDialogs is part of the Component Library for Cross-platform (CLX) and is the Kylix development side of Delphi, the 'Q' prefix on the unit name indicates this. Kylix is for the development of Linux applications.

Clive [infinity]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"To err is human, but to really foul things up you need a computer."
Paul Ehrlich
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
To get the best answers from this forum see: faq102-5096
 
John

I'm not sure that you have gone wrong.

Which OS are you using?

I found the icon appears when the application runs on Windows 98 but not on Windows XP Pro or on Windows XP Home.



Andrew
Hampshire, UK
 
Hi Andrew,

I'm using XP Pro. I'm assuming, from your comment, that any non-NT version will be okay, but NT versions will not.

I actually ended up making a form to use as a dialog within my application. Let's face it - it's probably the only way to be 100% sure that it'll be stable on all versions etc..

Thanks,

John.

mf_of_john.gif
 
The (Delphi 7) Windows SDK Help for MessageBoxIndirect says this:
[Now Supported on Windows NT]
So I was (only a little) surprised when it didn't work on XP but did on '98. I understood XP was based on NT technology and hence I assumed that it would be okay.

I don't know about other non-NT versions as I only have computers running 98 and XP.

A home grown form seems to be the most pragmatic option.

Andrew
Hampshire, UK
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top