Title: Create a Custom Message Dialog with Standard Windows Icons using Delphi
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.