Placing selection box on windows desktop? lazarus / 31-LCL ---------------------------------------------------------------------- BosseB · 2020-11-16 09:39 I want to create a Windows only application which will operate on data at a specific region on the desktop. I have seen similar programs where one gets to place a rectangle on the desktop to define the region to work with. How is that done? I don't think by writing to the desktop because then there will be a permanent change to it... What I want is to have a way to fairly accurately place a rectangle on the screen, which can be adjusted by the user (by mouse dragging) to accurately fit a specific region of the desktop inside it. Then my new application will operate on that region while keeping its boundaries visible to the user. I have seen a proposal to create an application with a form that is transparent and then draw to that using a different color. But then the operations will be to that application form while I want to use the desktop (or rather another application window on the desktop). EDIT: Forgot to say also that with the suggested code from the link above the created form is transparent also to the mouse so when clicking on some background item position one actually clicks on that and not on the now transparent form... Any suggestions? ---------------------------------------------------------------------- winni · 2020-11-16 10:28 Hi! Put a panel on the first form. Take a second Form. If you drag the second form to the first form you can do Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i Form2.Parent := Form1.Panel1; Winni ---------------------------------------------------------------------- BosseB · 2020-11-16 11:18 Quote from: winni on November 16, 2020, 11:28:07 amHi! Put a panel on the first form. Take a second Form. If you drag the second form to the first form you can do Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i Form2.Parent := Form1.Panel1; Winni I don't quite follow... Do you mean to make a separate form to handle the transparency and use the main form to control the operations? And the main form would be a normal application form and the second form the transparent one? I have now tested the proposed transparent form code and it does make the form internals transparent. Then I placed a panel at the bottom of that form and set it NOT to inherit the colors. Here I placed a "Close" button too. But now the mouse clicks get eaten up somewhere else so buttons on that panel do not receive mouse clicks at all. Breakpoints inside the OnClick of the button do not trigger... There is actually no way to close the application except by the X button in upper right corner of the main form.... ---------------------------------------------------------------------- balazsszekely · 2020-11-16 12:03 @BosseB Please test attached project. ---------------------------------------------------------------------- balazsszekely · 2020-11-16 17:47 @BosseB As an alternative solution you can also test the following project. ---------------------------------------------------------------------- BosseB · 2020-11-16 20:20 I cannot open any of these projects, or should I say when I open the projects there is no code editor shown and if I activate the code editor it is empty. If I try to compile it states that there is no main project file. Seems like these zip files are not complete or else that they reference files outside of the zip... I am using Lazarus 2.0.10 and FPC 3.2.0 Is that what these are made for? ---------------------------------------------------------------------- balazsszekely · 2020-11-16 20:27 QuoteI cannot open any of these projects, or should I say when I open the projects there is no code editor shown and if I activate the code editor it is empty. If I try to compile it states that there is no main project file. Seems like these zip files are not complete or else that they reference files outside of the zip... I am using Lazarus 2.0.10 and FPC 3.2.0 Is that what these are made for?It was made with Lazarus trunk. I will convert them to Lazarus 2.0.10 soon. ---------------------------------------------------------------------- balazsszekely · 2020-11-16 20:45 The following attachment contains the converted version for Lazarus 2.0.10. ---------------------------------------------------------------------- BosseB · 2020-11-16 21:28 Meanwhile I created a new project in Lazarus and manually copied the code in from your zip project (the last one) and made it compile. So this is a rectangle I can place over some area on the desktop. Resize and move by using the red square at the lower right and close via the pop menu at the square. Fine. Thanks for the code, I will start looking at how it works now and try to adapt to my use case. But first some evening tea.... ---------------------------------------------------------------------- balazsszekely · 2020-11-17 03:28 @BosseB You're welcome! In the converted version, I forgot to set FormStyle to fsSystemStayOnTop. This is needed for obvious reasons. ---------------------------------------------------------------------- BosseB · 2020-11-28 08:51 Quote from: GetMem on November 17, 2020, 04:28:33 am@BosseB You're welcome! In the converted version, I forgot to set FormStyle to fsSystemStayOnTop. This is needed for obvious reasons. Back again after some ffmpeg investigations. I have checked that I can use ffmpeg to capture the video in a defined rect area of the desktop. It seems to work fine for the image part of the video, not yet solved: how to get the corresponding audio. But that is for another thread.. Now I need the rectangle to create a selection function so the user (me) can place a video grabbing region on screen and get the coordinates for ffmpeg to use. So I want to have a "select window" function in my app which should create the rectangle form and let the user place it and then when it is closed grab the rect coordinates for use with ffmpeg. Concerning your comment above: How exactly am I supposed to set this FormStyle property? In code or using the Object Inspector on the form? Any preference on which to use? And can the entire thing be created in code without having a form unit included in the project? It would be nice to have a function "SelectCaptureRegion" which when called creates the rectangular frame form all in code so only the pas file is needed... Or is that overkill? ---------------------------------------------------------------------- lucamar · 2020-11-28 09:27 Quote from: BosseB on November 28, 2020, 09:51:38 amAnd can the entire thing be created in code without having a form unit included in the project? It would be nice to have a function "SelectCaptureRegion" which when called creates the rectangular frame form all in code so only the pas file is needed... Or is that overkill? Yes, it can be, and any property that can be set in the object inspector can also be set in code. That's how most non-standard dialogs work. As for it being overkill ... well, it depends but for a simple "selection rectangle" kind of form it migth even be the preferred way to do it. The advantage of designing a form in the IDE, setting properties in the OI, etc. is that the LCL can then load/create the form from a resource in the executable which is quite nice for "normal" forms with lots of controls of some set size, set in some defined position, with properties set to some non-default values; but for a bare form set at some size and in such position in the screen? You might as well do it in code. Do note that for a well behaved form you might want to override/overload its Create() method and set the needed properties in it. That way you can be sure that however you create it, it'll always have those propeties set as you want (in this case BorderStyle, FormStyle, etc.). That is, you would make kind of a custom "dialog" from which you could set/read the values you need for your app without worrying about how it will work internally. Basically, how one works with, say, a TOpenDialog, etc. ---------------------------------------------------------------------- BosseB · 2020-11-28 13:48 Quote from: lucamar on November 28, 2020, 10:27:31 amQuote from: BosseB on November 28, 2020, 09:51:38 amAnd can the entire thing be created in code without having a form unit included in the project? It would be nice to have a function "SelectCaptureRegion" which when called creates the rectangular frame form all in code so only the pas file is needed... Or is that overkill? Do note that for a well behaved form you might want to override/overload its Create() method and set the needed properties in it. That way you can be sure that however you create it, it'll always have those properties set as you want (in this case BorderStyle, FormStyle, etc.). That is, you would make kind of a custom "dialog" from which you could set/read the values you need for your app without worrying about how it will work internally. Basically, how one works with, say, a TOpenDialog, etc. OK thanks! I started doing a unit that I could then use in other programs and when I let Lazarus autocreate the methods I defined in my class (same as in your program) I did not get what I expected for the Create method... Here is what I entered and the framework created by Lazarus: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i type { TfrmSelectScreenRect } TfrmSelectScreenRect = class(TForm)  miClose : TMenuItem;  pm : TPopupMenu;  procedure FormCreate(Sender : TObject); override; // <== override to add stuff  procedure FormResize(Sender : TObject);  procedure miCloseClick(Sender : TObject);protected  procedure CreateParams(var Params: TCreateParams); override;private  FIsBusy: Boolean;  procedure CreateTransparentForm;public end; function SelectCaptureRegion(var PosX, PosY, Width, Height: integer): boolean; implementation function SelectCaptureRegion(var PosX, PosY, Width, Height : integer) : boolean;begin end;  { TfrmSelectScreenRect } procedure TfrmSelectScreenRect.FormCreate(Sender : TObject);begin// <== No inherited here! Why?end; procedure TfrmSelectScreenRect.FormResize(Sender : TObject);begin end; procedure TfrmSelectScreenRect.miCloseClick(Sender : TObject);begin end; procedure TfrmSelectScreenRect.CreateParams(var Params : TCreateParams);begin  inherited CreateParams(Params);end; procedure TfrmSelectScreenRect.CreateTransparentForm;begin end; Can I just add inherited there or is that not even needed? Maybe I can assume it has been done when this event triggers so I can access the form and adjust its properties? ---------------------------------------------------------------------- lucamar · 2020-11-28 15:15 What I meant was that yo would you something like, for example: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i type  TfrmSelectScreenRect = class(TForm)    {... other things here ...}  public    constructor Create(TheOwner: TComponent): overrride;  end; function SelectCaptureRegion(var PosX, PosY, Width, Height: integer): boolean; implementation { TfrmSelectScreenRect } constructor TForm1.Create(TheOwner: TComponent);begin  inherited Create(TheOwner);  {Now set properties of the form,   connect event handlers,   setup and add controls,   etc ...}end; {... more code here ...} end; That allows you to setup a whole form entirely in code but if you have many controls with several properties changed from default it can result in a really huge constructor, which is (among other things) why Delphi introduced the mechanism for loading and setting up forms from a form resource. In your case, if your form really must contain main and popup menus with several menu items (each of which, remember, is a component by itself) I would forget about doing all that in code and would use a "normal" form: it will look more "clean" and will be easier to maintain. And, if for nothing else, pure laziness ---------------------------------------------------------------------- BosseB · 2020-11-28 16:51 But this form really contains the popup menu item just as a way to exit the form, since buttons and such are not clickable on the transparent form. I noted that the little red square at the bottom right is where the popmenu activates and that it results in exiting the form altogether. In the example the popup menu exits the application altogether using Application.Terminate... I guess I might as well create my rectselect form as a complete form and skip this "create in code" idea... After all the example application using only this form works. I just have to replace Application.Terminate with a Form.Close. EDIT I ended up modifying the polygon statements so I increased the size of the bottom right little square to include an exit button (actually a TStaticText item with its OnClick hooked to the popup menu event). This way it is obvious how to close the selector. I also added another TStaticText container there into which I write the current size of the selection box in pixels as feedback. And I set the initial size of the box to the most commonly used video I make (860x480). Finally I added a clipboard output on exit where I put the correct ffmpeg arguments for selecting the area to record from: -offset_x 995 -offset_y 355 -video_size 860x480 so it is ready to be pasted into the ffmpeg command. ---------------------------------------------------------------------- BosseB · 2020-11-30 09:53 Follow-up question I now have a useful screen region selector for use when preparing the ffmpeg commands related to the desktop. It is based on the Frames proposal by @GetMem But it is a Windows only solution AFAICT... Is there some way to accomplish the same on say Ubuntu Mate Linux? I need to use my Linux machine for the video capture since otherwise I cannot use my main Windows10 notebook during captures. It is the machine I use "always" whereas the Linux box just sits there doing nothing for the most part. I have previously installed Lazarus 2.0.8/Fpc 3.0.4 on the Linux machine so I need to upgrade it to 2.0.10/3.2.0 now since that is what I am using on Windows nowadays... ---------------------------------------------------------------------- BosseB · 2021-02-03 21:41 Coming back to this thread because I have found a very strange issue with the code... I build the code on my year-old HP Zbook G5 workstation with Windows 10 and it works well here. But when I copy the program to my wife's HP laptop (same age but a simpler model), then the display is not the same! I have placed two TStaticText controls on the lower left corner, one holds the current xy size of the form in pixels and the other holds the letter X. This latter TStaticText simulates a close button. The lower right corner of the form has a bit more space to allow for grabbing the form to drag it into position. The attached image shows the way the form is displayed on the two laptops, on my wife's there is no sign of the two TStaticText containers, which are clearly visible when the exact same program is run on my own laptop. What in the world can cause this to happen? Below is my code for creating the hole in the form as suggested earlier in this thread. I have tried to figure out the reason for the different behaviour but failed. Changing the color of the form does not help. It seems like the TStaticText controls are hidden on the other laptop.... Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TfrmMain.FormCreate(Sender : TObject);begin  PrevWndProc := Windows.WNDPROC(SetWindowLongPtr(Self.Handle, GWL_WNDPROC, PtrInt(@WndCallback)));  Self.Color := clFuchsia; // clAqua;  //Defaults:  InitialWidth := 860;  InitialHeight := 480;  InitialPosx := (Screen.Width - InitialWidth) div 2;  InitialPosy := (Screen.Height - InitialHeight) div 2;   {$IFNDEF MAINAPP}    InitialWidth := ReadIniInt('configure', 'InitialWidth', InitialWidth);    InitialHeight := ReadIniInt('configure', 'InitialHeight', InitialHeight);    InitialPosx := ReadIniInt('configure', 'InitialPosx', InitialPosx);    InitialPosy := ReadIniInt('configure', 'InitialPosy', InitialPosy);  {$ENDIF}   Self.Width := InitialWidth;  Self.Height := InitialHeight;end; procedure TfrmMain.CreateTransparentForm;var  HoleRegion, FormRegion: HRGN;  Polygon: array of TPoint;begin  if FIsBusy then    Exit;  FIsBusy := True;  FormRegion := CreateRectRgn(0, 0, Self.Width, Self.Height);  try    SetLength(Polygon, 6);    Polygon[0].X := 2; Polygon[0].Y := 2;    Polygon[1].X := Self.Width - 2;  Polygon[1].Y := 2;    Polygon[2].X := Self.Width - 2;  Polygon[2].Y := Self.Height - stxSize.Height;    Polygon[3].X := Self.Width - stxSize.Width - stxClose.Width - 25; Polygon[3].Y := Self.Height - stxSize.Height;    Polygon[4].X := Self.Width - stxSize.Width - stxClose.Width - 25; Polygon[4].Y := Self.Height - 2;    Polygon[5].X := 2;               Polygon[5].Y := Self.Height - 2;    Polygon[6].X := 2;               Polygon[6].Y := 2;    HoleRegion := CreatePolygonRgn(@Polygon[0], Length(Polygon), WINDING);    try      CombineRgn(FormRegion, FormRegion, HoleRegion, RGN_DIFF);    finally      DeleteObject(HoleRegion);    end;    SetWindowRgn(Self.Handle, FormRegion, True);  finally    DeleteObject(FormRegion);    FIsBusy := False;  end;end; procedure TfrmMain.FormResize(Sender : TObject);begin  frmMain.CreateTransparentForm;  stxSize.Caption := IntToStr(Self.Width) + 'x' + IntToStr(Self.Height);end; ---------------------------------------------------------------------- BosseB · 2021-02-04 15:10 Quote from: BosseB on November 28, 2020, 05:51:44 pmBut this form really contains the popup menu item just as a way to exit the form, since buttons and such are not clickable on the transparent form. I noted that the little red square at the bottom right is where the popmenu activates and that it results in exiting the form altogether. In the example the popup menu exits the application altogether using Application.Terminate... I guess I might as well create my rectselect form as a complete form and skip this "create in code" idea... After all the example application using only this form works. I just have to replace Application.Terminate with a Form.Close. EDIT I ended up modifying the polygon statements so I increased the size of the bottom right little square to include an exit button (actually a TStaticText item with its OnClick hooked to the popup menu event). This way it is obvious how to close the selector. I also added another TStaticText container there into which I write the current size of the selection box in pixels as feedback. And I set the initial size of the box to the most commonly used video I make (860x480). Finally I added a clipboard output on exit where I put the correct ffmpeg arguments for selecting the area to record from: -offset_x 995 -offset_y 355 -video_size 860x480 so it is ready to be pasted into the ffmpeg command. The problem I am having right now is that what worked on my development PC does not in my wife's PC... Specifically, whatever I place in the little red box at lower right and is visible on my screen is erased on her screen. I am using this technique with the transparent form to give her a tool to select areas on the desktop to copy into a document she is writing. The exit control (a small TStaticText box with an X inside placed in the enlarged red box in bottom right is not available on her laptop but is shown on mine... I have now tried my best to find something that can be put there and be visible but failed miserably, the only object apart from TStaticText that stays visible also on my laptop is a TToggleBox, so I tried using that, but it too disappears when the program is run on her laptop... I really do not understand how this can be so, what is the difference between mine and her laptop that can cause this behavior??? And how can I put something visible on this form that stays visible independently of the Windows PC it runs on? ---------------------------------------------------------------------- BosseB · 2021-02-04 17:05 Quote from: BosseB on February 04, 2021, 04:10:02 pmThe problem I am having right now is that what worked on my development PC does not in my wife's PC... Specifically, whatever I place in the little red box at lower right and is visible on my screen is erased on her screen. I am using this technique with the transparent form to give her a tool to select areas on the desktop to copy into a document she is writing. The exit control (a small TStaticText box with an X inside placed in the enlarged red box in bottom right) is not available on her laptop but is shown on mine... I have now tried my best to find something that can be put there and be visible but failed miserably, the only object apart from TStaticText that stays visible also on my laptop is a TToggleBox, so I tried using that, but it too disappears when the program is run on her laptop... I really do not understand how this can be so, what is the difference between mine and her laptop that can cause this behavior??? And how can I put something visible on this form that stays visible independently of the Windows PC it runs on? FOUND CAUSE OF PROBLEM! It turns out that my wife's laptop is set in display settings to 125% rather than 100%. If I set hers back to 100% the missing controls do actually appear! So now the question is: Why does visibility of standard Lazarus controls depend on the Windows display scaling setting? ---------------------------------------------------------------------- BosseB · 2021-02-04 17:08 Quote from: GetMem on February 04, 2021, 04:18:10 pm@BosseB You owe me a beer for this one. Requirements:       - Lazarus 2.0.10/Trunk    - FPC 3.2.0    - package BGRABitmap Supported platforms:    - Windows(tested on Win7, Win10)    - Linux(tested on linux Mint, you never know how other distros will behave) Todo:   - the pngs are loaded from from files, namely from the "Images" directory. You should load it from resource or some other method. PS: There are room for improvement, unfortunately I cannot allocate more time for desktop drawing. If you improve the code, please post it back. I will for sure have a look at this! Especially since my wife is not happy with running at 100% scaling (gets too small she says) and the exit control [X] disappears in 125%... ---------------------------------------------------------------------- dseligo · 2021-02-04 19:43 Quote from: BosseB on February 04, 2021, 06:05:05 pmIt turns out that my wife's laptop is set in display settings to 125% rather than 100%. If I set hers back to 100% the missing controls do actually appear! In Project Options check "Use LCL scaling (Hi-DPI)" and change "DPI awareness" to "on (True)", and then try it. ---------------------------------------------------------------------- Jurassic Pork · 2021-02-04 23:29 hello, Quote from: BosseB on February 04, 2021, 06:05:05 pmIt turns out that my wife's laptop is set in display settings to 125% rather than 100%. If I set hers back to 100% the missing controls do actually appear! So now the question is: Why does visibility of standard Lazarus controls depend on the Windows display scaling setting? have you put the anchors property of your statictext controls to [akRight,akBottom] ? Friendly, J.P ---------------------------------------------------------------------- BosseB · 2021-02-05 10:06 Quote from: dseligo on February 04, 2021, 08:43:07 pmQuote from: BosseB on February 04, 2021, 06:05:05 pmIt turns out that my wife's laptop is set in display settings to 125% rather than 100%. If I set hers back to 100% the missing controls do actually appear! In Project Options check "Use LCL scaling (Hi-DPI)" and change "DPI awareness" to "on (True)", and then try it. Already set like that... Screenshot taken using the program: ---------------------------------------------------------------------- BosseB · 2021-02-05 10:09 Quote from: Jurassic Pork on February 05, 2021, 12:29:45 amhello, Quote from: BosseB on February 04, 2021, 06:05:05 pmIt turns out that my wife's laptop is set in display settings to 125% rather than 100%. If I set hers back to 100% the missing controls do actually appear! So now the question is: Why does visibility of standard Lazarus controls depend on the Windows display scaling setting? have you put the anchors property of your statictext controls to [akRight,akBottom] ? Friendly, J.P Yes, it is set like this: ---------------------------------------------------------------------- dseligo · 2021-02-05 12:23 Quote from: BosseB on February 05, 2021, 11:09:34 amYes, it is set like this: But you didn't select sibling. And choose right side/bottom side anchor (click on icon). ---------------------------------------------------------------------- BosseB · 2021-02-05 17:20 Now you lost me. What does a sibling do in this context? I showed the GUI dialog here, just as an example of capturing the image. It is used to set the component "Anchors" property, which is [akTop,akLeft] right now. Sibling is not mentioned in the component properties in Object Inspector AFAICT. ---------------------------------------------------------------------- dseligo · 2021-02-05 18:25 By selecting sibling I meant that you try to select sibling like in attachment here. Also, can you check Left, Top, Width and Height properties of TStaticText control against width and height of the form, just to be sure that they are "inside" form. ---------------------------------------------------------------------- BosseB · 2021-02-07 07:52 After setting the laptop screen to 100% scaling the application seems to work fine. So now I tried to improve its user interface like so: I expanded the pop-up menu, which contained only a "Close" item to also contain a "Copy Image" item so that the copy can be done by using a right click on the form and select copy. But now I got another problem, the pop-up menu itself becomes visible inside the copied image... So I have tried to move the actual copy into a timer event such that the popup menu click enables the timer and in its ontimer event I do the actual copy. But the menu image still is on top if the image I want to capture... The timer is set to 25 ms and I have tried to refresh in the timer event to hopefully remove the menu shadow from the image but to no avail. See screenshot where also the code is shown. How can I remove the menu from screen before the actual image copy is done? ---------------------------------------------------------------------- BosseB · 2021-02-07 08:04 This is how the thing looks like when I have right-clicked to get the popup menu on screen. So what lingers on when I click the "Copy image" item is the highlighted caption text.... ---------------------------------------------------------------------- dseligo · 2021-02-07 13:15 Try it like this: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TfrmMain.miCopyImageClick(Sender : TObject);begin  Sleep(300);  CopyScreenRect;end; Pop up menu takes some time to close (because of an animation), that's why delay is needed. Next time paste some code so I don't have to write it again. ---------------------------------------------------------------------- BosseB · 2021-02-07 13:54 Thanks, I had no idea that this would be the problem.... Now I have removed the non-working timer (it probably would have worked if I had set it to a longer delay) and instead put the Sleep() as you suggested in front of CopyScreenRect. Then I tested with varying sleep times and found that 100 and 200 does not cut it but 300 does. I wonder if there is a Windows system setting that affects the "animation" fade-out time? Interestingly I have this inside the called procedure: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TfrmMain.CopyScreenRect;var  MyCapture : TBgraBitmap;  Clip: TRect;begin  try    Clip := Bounds(Self.Left, Self.Top, Self.Width, Self.Height);    Self.Visible := false;    MyCapture := TBgraBitmap.Create();    try      MyCapture.TakeScreenShot(Clip);    Self.Visible := true;      Clipboard.Assign(MyCapture.Bitmap);    finally      MyCapture.Free;    end;  except    on E: exception do    Clipboard.AsText := E.Message;  end;end;  So here I hide the form used to locate the copy rect (to not be part of the copied image) and then immediately copy the desktop onto the bitmap and then return the form to visibility. Since this works there must be a difference in animation behavior between forms and pop-up menus... Or maybe animation is only applied when visible objects are destroyed or such? Anyway, thanks again - now my code is working! ---------------------------------------------------------------------- dseligo · 2021-02-07 15:42 Quote from: BosseB on February 07, 2021, 02:54:28 pmI wonder if there is a Windows system setting that affects the "animation" fade-out time? There is: go to Advanced System Settings from Control Panel or search for it as "View advanced system settings". Then go to "Advanced" tab, click Properties under Performance, and then uncheck "Fade out menu items after clicking". ---------------------------------------------------------------------- BosseB · 2021-02-12 22:53 Update to the solution For future reference if someone stumbles on this thread... I have been advised on the Lazarus mail list to use the Application.QueueAsyncCall() method to handle these things. It will place the call into the message queue ensuring that the menu has finished its "thing" before the call is executed. The method itself requires the called method to use an int64 argument, which is not really needed here, but required for the call to work. Here is how I fixed it: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TfrmMain.miCopyImageClick(Sender : TObject);begin  Application.QueueAsyncCall(@CopyScreenRect, 0);end; procedure TfrmMain.CopyScreenRect(arg: int64);  //Dummy argument, not usedvar  MyCapture : TBgraBitmap;  Clip: TRect;begin  try    Clip := Bounds(Self.Left, Self.Top, Self.Width, Self.Height);    Self.Visible := false;    MyCapture := TBgraBitmap.Create();    try      MyCapture.TakeScreenShot(Clip);      Self.Visible := true;      Clipboard.Assign(MyCapture.Bitmap);    finally      MyCapture.Free;  end;  except    on E: exception do      Clipboard.AsText := E.Message;  end;end; With this in place the menu "shadow" is no longer visible on the copied image! ---------------------------------------------------------------------- BosseB · 2021-02-13 18:26 BACK TO THE 125% RESOLUTION PROBLEM The problem persists where my statictext controls disappear from sight when the program is running on a Windows 10 computer set to 125% display scaling like my wife's PC.... Now I have investigated the suggestion to set the sibling in the anchoring dialog but it does not change anything. But what I have noted is that on the border of the transparent form to the left of where the controls should be I see indications of the two statictext controls and in fact if I succeed to target the rightmost of these shadow controls then the application closes. This control is the replacement for the form's close button, which is not visible either. So now it seems like the problem is that TStaticText controls that are anchored on the right hand side of the form are actually placed a fair bit to the left when the form is shown on a PC with 125% scaling compared to on one with 100% scaling. How can I fix this? See attached image, top shows the correct display (on 100%) and bottom the erroneous display (on 125%). Edit: I managed to not understand how the forum handling of images work so now there are two images ... ---------------------------------------------------------------------- BosseB · 2021-02-13 19:55 I ended up "fixing" the problem by adding this in the function where the form is made transparent to set the position in code: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i     stxClose.Left := Self.Width - stxClose.Width; //Close "button"    stxSize.Left := stxClose.Left - stxSize.Width; //Size display  And while I was testing that I discovered that the use of Sleep() to get rid of the shadow of the menu command did not actually work on my wife's laptop. So I had to return to use sleep: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TfrmMain.miCopyImageClick(Sender : TObject);begin  Sleep(300);  CopyScreenRect(0);  //Application.QueueAsyncCall(@CopyScreenRect, 0);end;