Go Premium for a chance to win a PS4. Enter to Win

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

Creating ny own message dialog

How do I create a message dialog with my own Icon/bmp without creating a new form?
0
ronit051397
Asked:
ronit051397
  • 9
  • 8
1 Solution
 
JimBob091197Commented:
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
 
ronit051397Author Commented:
I don't see the icon in the message box, do you?
0
 
JimBob091197Commented:
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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
ronit051397Author Commented:
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
 
JimBob091197Commented:
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
 
ronit051397Author Commented:
Thanks, Please Email me the sample project and the resource file to:
cmr@netvision.net.il
0
 
JimBob091197Commented:
I have sent the prog + source to you.  Let me know if you get it...

JB
0
 
ronit051397Author Commented:
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
 
ronit051397Author Commented:
Adjusted points to 100
0
 
JimBob091197Commented:
I'm not sure what "stub" is, but try replacing:
  MBParams.lpszIcon := '#123';
with:
  MBParams.lpszIcon := MakeIntResource(123);

JB
0
 
ronit051397Author Commented:
Cheers.
0
 
JimBob091197Commented:
Does "MakeIntResource(123)" work on your PC?  I've just tested it on an NT machine and it worked...
JB
0
 
ronit051397Author Commented:
Sure, You have got an A.
0
 
JimBob091197Commented:
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
 
ronit051397Author Commented:
If I use   MBParams.dwStyle := MB_USERICON+MB_YESNO
then how do I know which button was pressed, Yes or No?

0
 
JimBob091197Commented:
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
 
ronit051397Author Commented:
Cheers again.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 9
  • 8
Tackle projects and never again get stuck behind a technical roadblock.
Join Now