Solved

Creating ny own message dialog

Posted on 1998-01-29
17
167 Views
Last Modified: 2010-04-04
How do I create a message dialog with my own Icon/bmp without creating a new form?
0
Comment
Question by:ronit051397
  • 9
  • 8
17 Comments
 
LVL 5

Accepted Solution

by:
JimBob091197 earned 100 total points
ID: 1357817
Hi

You use the MessageBoxIndirect api call.

Steps:

1.  Create a .res file (with Image Editor).
2.  Add a new 32*32 icon.  Give it an Integer name (in my e.g. below I called it 123).
3.  In your form add {$R MyRes.res}

4.  The following code uses the icon in MyRes.res:

procedure TForm1.Button1Click(Sender: TObject);
var
  MBParams: TMsgBoxParams;
begin
  FillChar(MBParams, SizeOf(TMsgBoxParams), 0);
  MBParams.cbSize := SizeOf(TMsgBoxParams);
  MBParams.hwndOwner := Self.Handle;
  MBParams.hInstance := hInstance;
  MBParams.lpszCaption := 'My Caption';
  MBParams.lpszText := 'This is my message.';
  MBParams.dwStyle := MB_USERICON;
  MBParams.lpszIcon := '#123';    // Icon resource number.
  MessageBoxIndirect(MBParams);
end;


Regards,
JB
0
 
LVL 5

Author Comment

by:ronit051397
ID: 1357818
I don't see the icon in the message box, do you?
0
 
LVL 5

Expert Comment

by:JimBob091197
ID: 1357819
I sure do.

What ver of Delphi are you using?
Did you use Image Editor?
Is your icon called (e.g.) "123" and you load it with #, i.e. '#123'?

0
 
LVL 5

Author Comment

by:ronit051397
ID: 1357820
I work with Delphi 3.0.
Yes, I did everything you said.
Can you copy your source from here to your program and see if this is working? I have had a case where copy and paste didn't get the code to work just rewriting it.
0
 
LVL 5

Expert Comment

by:JimBob091197
ID: 1357821
Mmm...  I also use Delphi 3.

Steps 1, 2 & 3 are not code-based.  With Step 4 I did copy & paste.  I can e-mail you the sample if you want me to.

JB
0
 
LVL 5

Author Comment

by:ronit051397
ID: 1357822
Thanks, Please Email me the sample project and the resource file to:
cmr@netvision.net.il
0
 
LVL 5

Expert Comment

by:JimBob091197
ID: 1357823
I have sent the prog + source to you.  Let me know if you get it...

JB
0
 
LVL 5

Author Comment

by:ronit051397
ID: 1357824
Ok, I have checked it and..
It works great in 95, but not in NT, and I work only with NT. If you see the API help, then in the QuickInfo popup message you'll see that they say
Windows NT    stub
Win95         Yes
I don't know what it means, Do you?
Do you know of another API call to a custom message dialog?
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 5

Author Comment

by:ronit051397
ID: 1357825
Adjusted points to 100
0
 
LVL 5

Expert Comment

by:JimBob091197
ID: 1357826
I'm not sure what "stub" is, but try replacing:
  MBParams.lpszIcon := '#123';
with:
  MBParams.lpszIcon := MakeIntResource(123);

JB
0
 
LVL 5

Author Comment

by:ronit051397
ID: 1357827
Cheers.
0
 
LVL 5

Expert Comment

by:JimBob091197
ID: 1357828
Does "MakeIntResource(123)" work on your PC?  I've just tested it on an NT machine and it worked...
JB
0
 
LVL 5

Author Comment

by:ronit051397
ID: 1357829
Sure, You have got an A.
0
 
LVL 5

Expert Comment

by:JimBob091197
ID: 1357830
Yeah, I commented before I saw the answer...  Glad it works.  We learn something new everyday.  I've just changed my CustomMsgBox routine to use MakeIntResource.  I never knew it didn't work on any NT 4 machines until now!

0
 
LVL 5

Author Comment

by:ronit051397
ID: 1357831
If I use   MBParams.dwStyle := MB_USERICON+MB_YESNO
then how do I know which button was pressed, Yes or No?

0
 
LVL 5

Expert Comment

by:JimBob091197
ID: 1357832
Good question.  It took me a while to work this one out!  MessageBoxIndirect returns a boolean value, but it's actually an integer value.  You need to type-cast the bool to an integer.

E.g.  AInt := Integer(MessageBoxIndirect(MBParams));

AInt will then contain IDYES, IDNO, etc...

JB
0
 
LVL 5

Author Comment

by:ronit051397
ID: 1357833
Cheers again.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
A company’s greatest vulnerability is their email. CEO fraud, ransomware and spear phishing attacks are the no1 threat to a company’s security. Cybercrime is responsible for the largest loss of money to companies today with losses projected to r…
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 …

943 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now