1. Home
  2. Computing & Technology
  3. Delphi Programming

A Custom Message Dialog with Standard Windows Icons

By Zarko Gajic, About.com

Tip submitted by Peter Bernard

I needed to create my own customized "MessageDlg" message box with custom buttons, but I still wanted to have access to those spiffy icons that appear when you specify "mtInformation, mtConfirmation..." as the MessageDlg message type. After searching all over for icons on the web (and not finding anything suitable), I dug around in the Windows SDK help and cam across the LoadIcon API function.

LoadIcon - Get Standard Window Message Dialog Icons

LoadIcon loads the icon resource only if it has not been loaded; otherwise, it retrieves a handle to the existing resource. The function searches the icon resource for the icon most appropriate for the current display.
uses ShellAPI;

//drop a timage (image1) on the form
var
  icon : TIcon;
begin
  Icon := TIcon.Create;
  try
   icon.Handle := LoadIcon(icon.Handle, PChar(IDI_QUESTION)) ;
   Image1.Picture.Icon := Icon;
  finally
    icon.Free;
  end;
end;
Note that you might see variations of the type of icon used for the various purposes, depending on the version of Windows and skin you might be running, BUT they will be in keeping with Windows standard for those dialog types.

Note: to use one of the predefined icons, set the lpIconName parameter to one of the following values:

  • IDI_APPLICATION - default application icon
  • IDI_ASTERISK - asterisk (used in informative messages).
  • IDI_EXCLAMATION - exclamation point (used in warning messages).
  • IDI_HAND - hand-shaped icon (used in serious warning messages).
  • IDI_QUESTION - question mark (used in prompting messages).
  • IDI_WINLOGO - Windows logo.

Delphi tips navigator:
» Overloading Delphi's ShowMessage to accept Integer, Boolean, Float, Currency ...
« Formatting a File Size in Bytes for Display - Convert Bytes to String using Delphi

More Delphi Programming Quick Tips
Zarko Gajic
Guide since 1998

Zarko Gajic
Delphi Programming Guide

Explore Delphi Programming
About.com Special Features

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

Easy ways to connect two computers for networking purposes. More >

  1. Home
  2. Computing & Technology
  3. Delphi Programming
  4. Coding Delphi Applications
  5. Delphi Tips and Tricks
  6. Delphi 2008 Tips
  7. Create a Custom Message Dialog with Standard Windows Icons using Delphi

©2009 About.com, a part of The New York Times Company.

All rights reserved.