[Lazarus] TLabel and TImage not drawn on ShowWindow(SW_RESTORE) if Form was hidden with Form.Hide

Michael Van Ham michael.vanham at gmail.com
Mon Jul 13 03:36:06 CEST 2015


Hello Lazarus mailing list members,

I am using Lazarus 49537, FPC 2.6.4, and Windows 8.1 64-bit.

If a Form is hidden via the .Hide function, and later another application
uses the ShowWindow function to show the hidden form, TLabel and TImage
components are not drawn, the taskbar icon is not restored,
Form.WindowState is still wsMinimized, and Form1.Visible is still False.

Please consider the attached demo program and possible patch.


To implement "minimize to system tray" functionality in a program in the
Application.Minimize event one can call Form1.Hide.

One can later restore the application by calling Form1.ShowOnTop. This sets
the WindowState and Visible properties, and calls BringToFront. The form
and all components are restored properly.

If the user minimizes the application, and then later tries to start a
second copy of the application, the first copy should be shown instead. To
implement this:

var
  h: THandle;
begin
  h := FindWindow(nil, 'Form1');
  SetForegroundWindow(h);
  ShowWindow(h, SW_RESTORE);
end;

However, at this point Form1.WindowState is still set to wsMinimized and
Form1.Visible is still set to False. The taskbar icon is not drawn. TLabel
and TImage components are not drawn.

A small change in '\lcl\interfaces\win32\win32callback.inc' fixes the
drawing of the taskbar icon and the TLabel and TImage components. I don't
know if this is a good place to make this change though, or what other
effects this might have.

I appreciate any comments or suggestions. Thank you for considering this
issue.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20150712/82827322/attachment-0002.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: repaint-on-restore-test.zip
Type: application/zip
Size: 150762 bytes
Desc: not available
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20150712/82827322/attachment-0002.zip>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: win32callback.inc.patch
Type: application/octet-stream
Size: 890 bytes
Desc: not available
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20150712/82827322/attachment-0002.obj>


More information about the Lazarus mailing list