Author: Jonas Bilinkevicius
I have created a form which is snapped to the top of the screen. When I change the
size of the Windows Desktop, the visible form isn't resized accordingly.
Answer:
I use the following code and it works quite good, even if the desktop size is
changed:
1 type2 TForm1 = class(TForm)
3 private4 procedure WMWindowPosChanging(varmessage: TWMWindowPosMsg);
5 message WM_WINDOWPOSCHANGING;
6 7 { ... }8 9 implementation10 11 { ... }12 13 var14 WorkAreaRect: TRect;
15 NewWorkAreaFlag: Boolean;
16 17 { ... }18 19 procedure TForm1.WMWindowPosChanging(varmessage: TWMWindowPosMsg);
20 begin21 if (WindowState <> wsMaximized) then22 begin23 if (message.WindowPos.Flags and SWP_NOMOVE) = 0 then24 begin{form is moved}25 if NewWorkAreaFlag then26 begin{workarea might have changed since last call}27 SystemParametersInfo(SPI_GETWORKAREA, 0, @WorkAreaRect, 0);
28 end;
29 {snap form to border here, something 30 like Message.WindowPos.X := WorkAreaRect.Left if near to left border}31 { ... }32 end;
33 NewWorkAreaFlag := ((message.WindowPos.Flags and (SWP_NOMOVE or SWP_NOSIZE)) <>
34 0);
35 {True if form was (probably) dropped => get workarea again}36 end;
37 end;
38 39 { ... }40 41 initialization42 NewWorkAreaFlag := True;