Advertisement
RandomClear

How to replace dialog icon

Nov 25th, 2013
290
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 2.02 KB | None | 0 0
  1. // EurekaLog offers you feature to use generic error icon or icon of your application for error dialogs.
  2. // However, you may want to use some other icon for that.
  3. // There is no such feature in EurekaLog, but you can easily fix that with such code - see below.
  4. // Obviously, this code replaces icon for one particular dialog type (MS Classic style).
  5. // If you want to alter icon for several classes (such as EurekaLog-style dialog),
  6. // then you have to write more your own child classes.
  7.  
  8. unit Unit1;
  9.  
  10. interface
  11.  
  12. // ...
  13.  
  14. implementation
  15.  
  16. uses
  17.   EBase, ECore, EModules, EListView, EDialog, EDialogWinAPIMSClassic;
  18.  
  19. {$R *.dfm}
  20.  
  21. // To test our customization code
  22. procedure TForm1.Button1Click(Sender: TObject);
  23. begin
  24.   raise Exception.Create('Error Message');
  25. end;
  26.  
  27. type
  28.   // Our child class - inheriting from standard TMSClassicDialog
  29.   TMSClassicDialogCustom = class(TMSClassicDialog)
  30.   private
  31.     FCustomIcon: HBITMAP; // our new icon
  32.   protected
  33.     // Init/done:
  34.     procedure WindowInit; override;
  35.     procedure WindowDone; override;
  36.     // Replacing icon drawing:
  37.     function Paint(const ADC: HDC; const ARect: TRect): Integer; override;
  38.   end;
  39.  
  40. { TMSClassicDialogCustom }
  41.  
  42. procedure TMSClassicDialogCustom.WindowInit;
  43. var
  44.   Ico: HIcon;
  45. begin
  46.   inherited;
  47.  
  48.   Ico := LoadIcon(HInstance, 'CUSTOMICON');
  49.   FCustomIcon := IcoToBmp(Ico, GetStockObject(WHITE_BRUSH), 32, 32);
  50. end;
  51.  
  52. function TMSClassicDialogCustom.Paint(const ADC: HDC; const ARect: TRect): Integer;
  53. begin
  54.   Result := inherited;
  55.   DrawBmp(ADC, FCustomIcon, MonitorLeft, MonitorTop, 32, 32);
  56. end;
  57.  
  58. procedure TMSClassicDialogCustom.WindowDone;
  59. begin
  60.   DeleteObject(FCustomIcon);
  61.   inherited;
  62. end;
  63.  
  64. initialization
  65.  
  66.   if IsEurekaLogInstalled then
  67.   begin
  68.     // You have to register dialog before using it:
  69.     RegisterDialogClass(TMSClassicDialogCustom);
  70.     // Once registered - now you can use it in options:
  71.     CurrentEurekaLogOptions.ExceptionDialogType := TMSClassicDialogCustom.ClassName;
  72.   end;
  73.  
  74. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement