How to make modal form un-minimize after a Show Desktop (or windows + D)

283 Views Asked by At

When I start my application, the first and only form that shows is a login form in modal:

frmLogin = new TfrmLogin(Application);
frmLogin->Init();
if(frmLogin->ShowModal() == mrCancel)
{
  //this will exit the application because user cancel the login
  return -1;
}

There is code happening after the ShowModal which open the main form (not in modal) of the application.

When I press Show Desktop or do windows + D and I'm still on the modal form for the login, I can't get the login back when clicking on the taskbar.

1. Is there a way to un-minimize the modal login after a 'Show Desktop'?

2. Also, if I open my application and the login appears, I can't seem to be able to close it when right-clicking on it in the taskbar > 'Close windows'. Is there a way to close it by the taskbar? (It close perfectly when using the red 'x' in the corner of the login form though)

I'm using c++ Builder 10.1 Berlin

1

There are 1 best solutions below

0
On BEST ANSWER

As @Remy Lebeau suggested, I came to the solution by overriding the CreateParams() function.

In my Login.h

protected:
    virtual void __fastcall CreateParams(TCreateParams &Params);

In my Login.cpp

void __fastcall TfrmLogin::CreateParams(TCreateParams &Params)
{
    TForm::CreateParams(Params);
    Params.ExStyle = WS_EX_APPWINDOW;
    Params.WndParent = GetDesktopWindow();
}

My code is based on the Delphi example found here: https://forums.embarcadero.com/thread.jspa?threadID=244599

Now, my Login form is able to be un-minimized after a ctrl + D! Hopes this helps other c++ builder programmers out there.