The only explanation I can come up with, is your application's MainFormOnTaskbar
is set to false.
If this is the case, when your application is minimized, the main form is not actually minimized but hidden according to VCL's minimization mechanism. When you send a WM_SETREDRAW
message with 'wParam' set to True, you're forcing the hidden (not minimized) main form's window to be shown.
At this stage the application is still minimized according to the VCL since it has never been restored. When you click the minimize button of the main form, VCL calls TApplication.Minimize
and sees that the application window is already minimized and so returns without further action, hence the main form is not minimized.
Here's a simple sample that would duplicate the problem. Set MainFormOnTaskbar
to false in project source. Run the application and then click the button:
procedure TForm1.Button2Click(Sender: TObject);
begin
Application.Minimize;
SendMessage(Handle, WM_SETREDRAW, 1, 0);
// ShowWindow(Handle, SW_SHOWNORMAL); // this will also do the same
end;
You won't be able to minimize the form after that.
To solve, you can check if the main form is visible f.i. before disabling drawing:
if IsWindowVisible(Handle) then begin
Windows.SendMessage(self.Handle, WM_SETREDRAW, 0, 0);
...