Correct handling of the Minimize window modal behavior

I have the following problem: we are creating a rather large application (win32, Delphi 6 Enterprise). Several parts of the application use modal windows, usually containing the detail of selecting the main window.

We have included a modification to the processing of WM_SYSCOMMAND messages, so that if the window is modal, then the SW_SHOWMINNOACTIVE message will be sent to the main application window. This leads to minimization of the entire application, and not just to the modal form.

However, in a specific case, a problem arises: if the calling window is set to full screen, then when recovering, a modal window appears under the maximum (disabled) main window (this seems to be happening in Windows 7)

My problem is double:

Firstly, I don’t get the syscommand message when the application is being restored, so I can’t enter the Z-Order recovery code because I don’t know where to put it. Secondly, it seems to me that if the entire application is minimized, clicking on the application button on the taskbar should restore it to the same state, and not under the modal window. Is there any way to fix this?

Edit: we did some additional testing, and it looks like we can actually detect the problem in the WM_ACTIVATE handler for the main form. We can also define a modal window at this stage. However, I cannot find a way to restore it at the top of the Z-Order.

Edit2: here is the code that minimizes the application when the modal form is minimized:

procedure TfmGITForm.WMSysCommand(var Message: TWMSysCommand); begin if (fsModal in FormState) or not Application.MainForm.Visible then begin case Message.CmdType of SC_MINIMIZE: begin ShowWindow(Application.Handle, SW_SHOWMINNOACTIVE); end; SC_RESTORE: begin ShowWindow(Application.Handle, SW_SHOWNORMAL); inherited; end; else inherited; end; // case end else inherited; end; 

All our forms come off this.

+6
source share
2 answers

Override the Params.WndParent dialog CreateParams and set Params.WndParent to a full-screen window (or Owner.Handle if you own it correctly). By default, Application.Handle used, which will cause such problems. PopupParent properties introduced in later versions of Delphi do the same.

+3
source

This is due to the windows ghosting window, which was introduced in (I think) XP. I have the same problems in the D5 application for these operating systems. At that time, Peter Below offered the following work, and it still helps me a lot:

 procedure DisableProcessWindowsGhosting; type TDisableProcessWindowsGhostingProc = procedure; stdcall; const sUser32 = 'User32.dll'; var ModH: HMODULE; _DisableProcessWindowsGhosting: TDisableProcessWindowsGhostingProc; begin ModH := GetModuleHandle(sUser32); if ModH <> 0 then begin @_DisableProcessWindowsGhosting := nil; @_DisableProcessWindowsGhosting := GetProcAddress(ModH, 'DisableProcessWindowsGhosting'); if Assigned(_DisableProcessWindowsGhosting) then begin _DisableProcessWindowsGhosting; end; end; end; 

I call it at the beginning of the main OnCreate handler of the main application form.

+1
source

Source: https://habr.com/ru/post/890211/


All Articles