Change bug report form position

delphi package - automated exception handling
Post Reply
moennich
Posts: 4
Joined: Tue Nov 23, 2021 4:48 pm

Change bug report form position

Post by moennich »

I'm using IMEException.Show method do display bug report form. It's working properly.
But I'd like to change the form positon, actually on desktop center, to main form center.
How could I do that?

Thanks in advance.
madshi
Site Admin
Posts: 10753
Joined: Sun Mar 21, 2004 5:25 pm

Re: Change bug report form position

Post by madshi »

You can register these callbacks exported by madExcept.pas:

Code: Select all

// do you want to be notified when a madExcept exception box was created/destroyed?
var
  OnExceptBoxCreate  : procedure (exceptBox: HWND; simpleMsgBox: boolean) = nil;
  OnExceptBoxDestroy : procedure = nil;
Then in your "OnExceptBoxCreate" handler you can use win32 APIs (e.g. SetWindowPos) to change the form position. You can't use VCL because the madExcept exception box doesn't use VCL, because the VCL is not thread safe.
moennich
Posts: 4
Joined: Tue Nov 23, 2021 4:48 pm

Re: Change bug report form position

Post by moennich »

Thank you!!

It's worked:

Code: Select all


implementation

uses
  madExcept;

...

procedure DoShowException(exceptBox: HWND; simpleMsgBox: boolean);
var
  MbRect: TRect;
  x, y, w, h: integer;
begin
    GetWindowRect(exceptBox, MBRect);
    with MbRect do
    begin
      w := Right - Left;
      h := Bottom - Top;
    end;
    // center horzontal
    x := Application.MainForm.Left + ((Application.MainForm.Width - w) div 2);
    // keep on screen
    if x < 0 then
      x := 0
    else if x + w > Screen.Width then x := Screen.Width - w;
    //center vertical
    y := Application.MainForm.Top + ((Application.MainForm.Height - h) div 2);
    // keep on screen
    if y < 0 then y := 0
    else if y + h > Screen.Height then y := Screen.Height - h;
    // set new windows position
    SetWindowPos(exceptBox, 0, x, y, 0, 0, SWP_NOACTIVATE or SWP_NOSIZE or SWP_NOZORDER);
end;

...

initialization
  OnExceptBoxCreate := DoShowException;

Post Reply