Root > How to... > ...change exception dialog?

...change exception dialog?

Previous pageReturn to chapter overviewNext page   

Sometimes EurekaLog does not have an option to implement a behavior or visual appearance that you want. If this is the case - you can alter behavior and/or visual appearance of build-in dialog.

 

If you are looking for switching dialogs in run-time - see How to change EurekaLog's settings at run-time. You are interested in ExceptionDialogType property.
If build-in dialogs does not satisfy your needs in any way, and you want to implement your own dialog class - see this article instead.

 

All EurekaLog dialogs are implemented in WinAPI, wrapped inside classes with lots of virtual and helper functions. Base dialog class is TBaseDialogClass from EDialog unit. All dialogs are child classes from this class. For example, MS Classic dialog is implemented as TMSClassicDialog class from EDialogWinAPIMSClassic unit. If you want to alter any aspect of default dialog - you need to sub-class it and override desired virtual methods. You can also call inherited helper methods to simplify developing.

 

Important Note: dialog class is responsible for almost whole exception processing. That's because "dialog" don't have to be visual. Think about Win32 service, system log, WER (Windows Error Reporting), etc. So, this is not always possible to distinguish between "error dialog" and "exception processing". That's why these concepts are both controlled by single "dialog" class. A primary method for visual dialog is ShowModalInternal method. But real entry point for dialog is Execute method, which performs all tasks: saving bug report, showing dialog, sending, etc.

 

First, you need to subclass the desired dialog class:

 

uses
  EDialogWinAPIMSClassic; // for TMSClassicDialog 
 
type
  TMSClassicDialog = class(EDialogWinAPIMSClassic.TMSClassicDialog)
  // ...

 

The example above uses MS Classic dialog as example. If you want to customize a different dialog - you will need to replace unit name and class name. If you want to customize more than one dialog - you will need to create multiple child classes.

 

You must use the same class name as original class. You'll have to append unit name to class ident to avoid compiler confusion. That way your class will look as original class, so it will use the same options.

 

Second, you need to register your class:

 

uses
  EDialog; // for RegisterDialogFirst
 
initialization

  // Register dialog class to be the first in the list.
  RegisterDialogFirst(TMSClassicDialog);
end.

 

The TMSClassicDialog class in the example above is your class, which you have derived from default EurekaLog class.

 

The important piece here is to register your class as first, which is archived by using registering function with "First" suffix. Default class (from EurekaLog) will be listed after your class in registered dialogs. Any search for class by name will find your class, because it's listed first.

 


 

Now that preparations are completed - you can customize your class in any way you want, by overriding virtual methods. For example, if you want to replace dialog icons:

 

uses
  ELowLevel, // for PrimaryInstance, GetModuleFileNameSafe
  ESysInfo;  // for GetFileIcon, GetSystemIcon
 
// ...
 
  protected
    procedure LoadIcon; override;
    procedure SetWndIcons; override;
  end;
 
procedure TMSClassicDialog.LoadIcon;
var
  Sz: TSize;
  Ico: HIcon;
begin

  // If you want an icon with specified name - use:
  // Ico := GetFileIcon(DPI, GetModuleFileNameSafe(HInstance), True, @Sz, 'YOUR_ICON_NAME', True);
  if Options.edoUseRealIcon then
    Ico := GetFileIcon(DPI, GetModuleFileNameSafe(PrimaryInstance), True, @Sz)
  else
    Ico := GetSystemIcon(DPI, MakeIntResourceW(IDI_ERROR), True, @Sz);
  try
    SetLogoIcon(Ico, Sz);
  finally
    DestroyIcon(Ico);
  end;
end;
 
procedure TMSClassicDialog.SetWndIcons;
const
  ICON_BIG   = 1;
  ICON_SMALL = 0;
var
  Ico: HICON;
  Sz: TSize;
begin
  if Options.edoUseRealIcon then
    Ico := GetFileIcon(DPI, GetModuleFileNameSafe(PrimaryInstance), False, @Sz)
  else
    Ico := GetSystemIcon(DPI, MakeIntResourceW(IDI_ERROR), False, @Sz);
  try
    Ico := SendMessage(Dialog, WM_SETICON, ICON_SMALL, LParam(Ico));
  finally
    DestroyIcon(Ico);
  end;

 
  if Options.edoUseRealIcon then
    Ico := GetFileIcon(DPI, GetModuleFileNameSafe(PrimaryInstance), True, @Sz)
  else
    Ico := GetSystemIcon(DPI, MakeIntResourceW(IDI_ERROR), True, @Sz);
  try
    Ico := SendMessage(Dialog, WM_SETICON, ICON_BIG, LParam(Ico));
  finally
    DestroyIcon(Ico);
  end;
end;

 

If you want to modify WinAPI-based dialogs (such as MS Classic, EurekaLog, EurekaLog Detailed, etc.) by adding your own additional controls - see this article.

If you want to completely replace exception dialog - see this article.

 

 

See also:




Send feedback... Build date: 2021-02-14
Last edited: 2020-05-20
PRIVACY STATEMENT
The documentation team uses the feedback submitted to improve the EurekaLog documentation. We do not use your e-mail address for any other purpose. We will remove your e-mail address from our system after the issue you are reporting has been resolved. While we are working to resolve this issue, we may send you an e-mail message to request more information about your feedback. After the issues have been addressed, we may send you an email message to let you know that your feedback has been addressed.


Permanent link to this article: https://www.eurekalog.com/help/eurekalog/how_to_change_exception_dialog.php