Recent

Author Topic: Placing selection box on windows desktop?  (Read 6260 times)

BosseB

  • Sr. Member
  • ****
  • Posts: 468
Re: Placing selection box on windows desktop?
« Reply #15 on: November 30, 2020, 10:53:03 am »
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...
--
Bo Berglund
Sweden

BosseB

  • Sr. Member
  • ****
  • Posts: 468
Re: Placing selection box on windows desktop?
« Reply #16 on: February 03, 2021, 10:41:06 pm »
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][+][-]
  1. procedure TfrmMain.FormCreate(Sender : TObject);
  2. begin
  3.   PrevWndProc := Windows.WNDPROC(SetWindowLongPtr(Self.Handle, GWL_WNDPROC, PtrInt(@WndCallback)));
  4.   Self.Color := clFuchsia; // clAqua;
  5.   //Defaults:
  6.   InitialWidth := 860;
  7.   InitialHeight := 480;
  8.   InitialPosx := (Screen.Width - InitialWidth) div 2;
  9.   InitialPosy := (Screen.Height - InitialHeight) div 2;
  10.  
  11.   {$IFNDEF MAINAPP}
  12.     InitialWidth := ReadIniInt('configure', 'InitialWidth', InitialWidth);
  13.     InitialHeight := ReadIniInt('configure', 'InitialHeight', InitialHeight);
  14.     InitialPosx := ReadIniInt('configure', 'InitialPosx', InitialPosx);
  15.     InitialPosy := ReadIniInt('configure', 'InitialPosy', InitialPosy);
  16.   {$ENDIF}
  17.  
  18.   Self.Width := InitialWidth;
  19.   Self.Height := InitialHeight;
  20. end;
  21.  
  22. procedure TfrmMain.CreateTransparentForm;
  23. var
  24.   HoleRegion, FormRegion: HRGN;
  25.   Polygon: array of TPoint;
  26. begin
  27.   if FIsBusy then
  28.     Exit;
  29.   FIsBusy := True;
  30.   FormRegion := CreateRectRgn(0, 0, Self.Width, Self.Height);
  31.   try
  32.     SetLength(Polygon, 6);
  33.     Polygon[0].X := 2; Polygon[0].Y := 2;
  34.     Polygon[1].X := Self.Width - 2;  Polygon[1].Y := 2;
  35.     Polygon[2].X := Self.Width - 2;  Polygon[2].Y := Self.Height - stxSize.Height;
  36.     Polygon[3].X := Self.Width - stxSize.Width - stxClose.Width - 25; Polygon[3].Y := Self.Height - stxSize.Height;
  37.     Polygon[4].X := Self.Width - stxSize.Width - stxClose.Width - 25; Polygon[4].Y := Self.Height - 2;
  38.     Polygon[5].X := 2;               Polygon[5].Y := Self.Height - 2;
  39.     Polygon[6].X := 2;               Polygon[6].Y := 2;
  40.     HoleRegion := CreatePolygonRgn(@Polygon[0], Length(Polygon), WINDING);
  41.     try
  42.       CombineRgn(FormRegion, FormRegion, HoleRegion, RGN_DIFF);
  43.     finally
  44.       DeleteObject(HoleRegion);
  45.     end;
  46.     SetWindowRgn(Self.Handle, FormRegion, True);
  47.   finally
  48.     DeleteObject(FormRegion);
  49.     FIsBusy := False;
  50.   end;
  51. end;
  52.  
  53. procedure TfrmMain.FormResize(Sender : TObject);
  54. begin
  55.   frmMain.CreateTransparentForm;
  56.   stxSize.Caption := IntToStr(Self.Width) + 'x' + IntToStr(Self.Height);
  57. end;
  58.  
  59.  
--
Bo Berglund
Sweden

BosseB

  • Sr. Member
  • ****
  • Posts: 468
Re: Placing selection box on windows desktop?
« Reply #17 on: February 04, 2021, 04:10:02 pm »
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.

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?
--
Bo Berglund
Sweden

BosseB

  • Sr. Member
  • ****
  • Posts: 468
Re: Placing selection box on windows desktop?
« Reply #18 on: February 04, 2021, 06:05:05 pm »
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?

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?
--
Bo Berglund
Sweden

BosseB

  • Sr. Member
  • ****
  • Posts: 468
Re: Placing selection box on windows desktop?
« Reply #19 on: February 04, 2021, 06:08:54 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%...
--
Bo Berglund
Sweden

dseligo

  • Hero Member
  • *****
  • Posts: 1196
Re: Placing selection box on windows desktop?
« Reply #20 on: February 04, 2021, 08:43:07 pm »
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!
In Project Options check "Use LCL scaling (Hi-DPI)" and change "DPI awareness" to "on (True)", and then try it.

Jurassic Pork

  • Hero Member
  • *****
  • Posts: 1228
Re: Placing selection box on windows desktop?
« Reply #21 on: February 05, 2021, 12:29:45 am »
hello,
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?
have you put the anchors property of your statictext controls to [akRight,akBottom] ?

Friendly, J.P
Jurassic computer : Sinclair ZX81 - Zilog Z80A à 3,25 MHz - RAM 1 Ko - ROM 8 Ko

BosseB

  • Sr. Member
  • ****
  • Posts: 468
Re: Placing selection box on windows desktop?
« Reply #22 on: February 05, 2021, 11:06:21 am »
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!
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:
--
Bo Berglund
Sweden

BosseB

  • Sr. Member
  • ****
  • Posts: 468
Re: Placing selection box on windows desktop?
« Reply #23 on: February 05, 2021, 11:09:34 am »
hello,
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?
have you put the anchors property of your statictext controls to [akRight,akBottom] ?

Friendly, J.P
Yes, it is set like this:
--
Bo Berglund
Sweden

dseligo

  • Hero Member
  • *****
  • Posts: 1196
Re: Placing selection box on windows desktop?
« Reply #24 on: February 05, 2021, 01:23:42 pm »
Yes, it is set like this:
But you didn't select sibling.

And choose right side/bottom side anchor (click on icon).
« Last Edit: February 05, 2021, 01:25:27 pm by dseligo »

BosseB

  • Sr. Member
  • ****
  • Posts: 468
Re: Placing selection box on windows desktop?
« Reply #25 on: February 05, 2021, 06:20:58 pm »
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.
--
Bo Berglund
Sweden

dseligo

  • Hero Member
  • *****
  • Posts: 1196
Re: Placing selection box on windows desktop?
« Reply #26 on: February 05, 2021, 07:25:48 pm »
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

  • Sr. Member
  • ****
  • Posts: 468
Re: Placing selection box on windows desktop?
« Reply #27 on: February 07, 2021, 08:52:47 am »
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?

--
Bo Berglund
Sweden

BosseB

  • Sr. Member
  • ****
  • Posts: 468
Re: Placing selection box on windows desktop?
« Reply #28 on: February 07, 2021, 09:04:49 am »
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....
--
Bo Berglund
Sweden

dseligo

  • Hero Member
  • *****
  • Posts: 1196
Re: Placing selection box on windows desktop?
« Reply #29 on: February 07, 2021, 02:15:36 pm »
Try it like this:

Code: Pascal  [Select][+][-]
  1. procedure TfrmMain.miCopyImageClick(Sender : TObject);
  2. begin
  3.   Sleep(300);
  4.   CopyScreenRect;
  5. 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.

 

TinyPortal © 2005-2018