Re: [Lazarus] How to hide pop-up menu before taking a screen snapshot?

2021-02-07 Thread Bo Berglund via lazarus
On Sun, 7 Feb 2021 17:16:31 +0300, Andrey Sobol via lazarus
 wrote:

>Try to call
>
>Application.ProcessMessages();
>after disable a popup menu.
>
>Andrey.
>

Did not work. popmenu item still shows on captured image.
The Sleep(300) in the menu handler does work OTOH...


-- 
Bo Berglund
Developer in Sweden

-- 
___
lazarus mailing list
lazarus@lists.lazarus-ide.org
https://lists.lazarus-ide.org/listinfo/lazarus


Re: [Lazarus] How to hide pop-up menu before taking a screen snapshot?

2021-02-07 Thread Andrey Sobol via lazarus

Try to call

Application.ProcessMessages();
after disable a popup menu.

Andrey.

On 07.02.2021 17:09, Bo Berglund via lazarus wrote:

On Sun, 7 Feb 2021 14:01:46 +, Denis Kozlov via lazarus
 wrote:



I had a similar experience with taking a screenshot programmatically.
Simply waiting or processing application messages after hiding the form
often doesn't help, and results in a form being a part of the screenshot
anyway.

I managed to work around it by forcing Windows to repaint everything on
the desktop by broadcasting WM_PAINT message, like so:

SendMessageTimeout(HWND_BROADCAST, WM_PAINT, 0, 0, SMTO_ABORTIFHUNG,
1000, MsgResult);

You might also need to disable transition effects (fade-in and fade-out)
by setting the DWMWA_TRANSITIONS_FORCEDISABLED flag on the form before
hiding it, and then unsetting it when showing the form again.

DwmSetWindowAttribute(AForm.Handle, DWMWA_TRANSITIONS_FORCEDISABLED,
@dwAttribute, SizeOf(dwAttribute));

Good luck,
Denis


Thanks for the suggestion!

It turned out that (from a suggestion on the Lazarus forum) I could use a
sleep(300) right before the call to the CopyScreenRect() instead of the other
failed tests.

Apparently the menu item is subject to Windows "animation" when it is closed...

So this is now the code and it does work:

procedure TfrmMain.miCopyImageClick(Sender : TObject);
begin
   Sleep(300);
   CopyScreenRect;
end;

procedure TfrmMain.CopyScreenRect;
var
   MyCapture : TBgraBitmap;
   Clip: TRect;
begin
   try
 Clip := Bounds(Self.Left, Self.Top, Self.Width, Self.Height);
 Self.Visible := false; //To remove the capture frame from image
 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;

I tried various values for the sleep time and settled for 300, 200 does not
quite fix it - a faded shadow image still remains.





--
Andrey
--
___
lazarus mailing list
lazarus@lists.lazarus-ide.org
https://lists.lazarus-ide.org/listinfo/lazarus


Re: [Lazarus] How to hide pop-up menu before taking a screen snapshot?

2021-02-07 Thread Bo Berglund via lazarus
On Sun, 7 Feb 2021 14:01:46 +, Denis Kozlov via lazarus
 wrote:

>
>I had a similar experience with taking a screenshot programmatically. 
>Simply waiting or processing application messages after hiding the form 
>often doesn't help, and results in a form being a part of the screenshot 
>anyway.
>
>I managed to work around it by forcing Windows to repaint everything on 
>the desktop by broadcasting WM_PAINT message, like so:
>
>SendMessageTimeout(HWND_BROADCAST, WM_PAINT, 0, 0, SMTO_ABORTIFHUNG, 
>1000, MsgResult);
>
>You might also need to disable transition effects (fade-in and fade-out) 
>by setting the DWMWA_TRANSITIONS_FORCEDISABLED flag on the form before 
>hiding it, and then unsetting it when showing the form again.
>
>DwmSetWindowAttribute(AForm.Handle, DWMWA_TRANSITIONS_FORCEDISABLED, 
>@dwAttribute, SizeOf(dwAttribute));
>
>Good luck,
>Denis

Thanks for the suggestion!

It turned out that (from a suggestion on the Lazarus forum) I could use a
sleep(300) right before the call to the CopyScreenRect() instead of the other
failed tests.

Apparently the menu item is subject to Windows "animation" when it is closed...

So this is now the code and it does work:

procedure TfrmMain.miCopyImageClick(Sender : TObject);
begin
  Sleep(300);
  CopyScreenRect;
end;

procedure TfrmMain.CopyScreenRect;
var
  MyCapture : TBgraBitmap;
  Clip: TRect;
begin
  try
Clip := Bounds(Self.Left, Self.Top, Self.Width, Self.Height);
Self.Visible := false; //To remove the capture frame from image
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;

I tried various values for the sleep time and settled for 300, 200 does not
quite fix it - a faded shadow image still remains.


-- 
Bo Berglund
Developer in Sweden

-- 
___
lazarus mailing list
lazarus@lists.lazarus-ide.org
https://lists.lazarus-ide.org/listinfo/lazarus


Re: [Lazarus] Lazarus configuration - portable between versions?

2021-02-07 Thread Juha Manninen via lazarus
LazarusDirectory tag indeed has version dependent paths.
I don't remember what exactly it is used for.
The Recent file lists are not important. They are updated dynamically and
old entries will go away.

So, you can copy the whole configuration if you do some minor editing.

Juha
-- 
___
lazarus mailing list
lazarus@lists.lazarus-ide.org
https://lists.lazarus-ide.org/listinfo/lazarus


Re: [Lazarus] How to hide pop-up menu before taking a screen snapshot?

2021-02-07 Thread Denis Kozlov via lazarus

Hi,

I had a similar experience with taking a screenshot programmatically. 
Simply waiting or processing application messages after hiding the form 
often doesn't help, and results in a form being a part of the screenshot 
anyway.


I managed to work around it by forcing Windows to repaint everything on 
the desktop by broadcasting WM_PAINT message, like so:


SendMessageTimeout(HWND_BROADCAST, WM_PAINT, 0, 0, SMTO_ABORTIFHUNG, 
1000, MsgResult);


You might also need to disable transition effects (fade-in and fade-out) 
by setting the DWMWA_TRANSITIONS_FORCEDISABLED flag on the form before 
hiding it, and then unsetting it when showing the form again.


DwmSetWindowAttribute(AForm.Handle, DWMWA_TRANSITIONS_FORCEDISABLED, 
@dwAttribute, SizeOf(dwAttribute));


Good luck,
Denis


On 07/02/2021 09:37, Bo Berglund via lazarus wrote:

I have worked on a tool to copy a region of the Windows desktop for use in
illustrations. The tool consists of a transparent form which is supposed to be
located on top of the area to copy.

This form has a pop-up menu where there are 3 items to select from:
- Copy image
- Copy position
- Close

When I use the "Copy image" function the resulting image contains the selected
menu item caption on top of the copied desktop bitmap...

I have tried various ways to get rid of this but everything I tried has failed.
So how can I hide the menu item caption in code before I make the image
extraction?

I even added a timer set to 50 ms interval and put the image copy in its ontimer
event hoping that the menu click should have exited and the text disappeared
before the image copy happened, but no go...

Here is the way the copy is commanded via the popup menu:
http://blog.boberglund.com/files/Lazarus_popmenu_usage.png

And here is a captured image where the popup caption is visible:
http://blog.boberglund.com/files/Lazarus_popmenu.png

As you can see the caption of the clicked menu item is still present in the
screenshot image...

Here is parts of the code:

procedure TfrmMain.miCopyImageClick(Sender : TObject);
begin
   //CopyScreenRect;  //Moved to timer
   //miCopyImage.Visible := false; //Does not work
   //self.Refresh;  //Does not work
   timCopyImg.Enabled := true;  //make copy inside timer event?
end;

procedure TfrmMain.miCopyPosClick(Sender : TObject);
begin
   SaveRectCoords; //Saving rect coordinates to clipboard (OK)
end;

procedure TfrmMain.timCopyImgTimer(Sender : TObject);
begin
   timCopyImg.Enabled := false;
   miCopyImage.Visible := false; //Does not work, caption still present
   self.Refresh;  //Does also not work to remove caption
   CopyScreenRect;
   miCopyImage.Visible := true;  //Put it back to enable next capture
end;

procedure TfrmMain.CopyScreenRect;
var
   MyCapture : TBgraBitmap;
   Clip: TRect;
begin
   try
 Clip := Bounds(Self.Left, Self.Top, Self.Width, Self.Height);
 Self.Visible := false; //Hide selection form before copy
 //Self.Hide;  //Not working for popup menu item...
 MyCapture := TBgraBitmap.Create();
 MyCapture.TakeScreenShot(Clip);
 Self.Visible := true; //Show selection form after copy is done
 //Self.Show;  //Not working for popup menu item...
 Clipboard.Assign(MyCapture.Bitmap);
   except
 on E: exception do
   Clipboard.AsText := E.Message;
   end;
end;

Even Self.Visible or Self.Hide do not remove the menuitem caption

What can I do?

Lazarus 2.0.10 / fpc 3.2.0 on Windows 10




--
___
lazarus mailing list
lazarus@lists.lazarus-ide.org
https://lists.lazarus-ide.org/listinfo/lazarus


Re: [Lazarus] Some IDE/LHelp issues

2021-02-07 Thread Andrey Sobol via lazarus

On 04.02.2021 16:39, Rolf Wetjen via lazarus wrote:

Hi Andy

I've patched LHelp.exe with lhelp_index_combine_04.patch.

The "unknown" tab issue is partly solved. Now all tabs have a caption. 
There's one strange behaviour:
[FPDoc Documentation], [Programmer' Guide], [Reference Guide] and 
[User's Guide] doesn't show the default page if LHelp is called from the 
IDE via Help/CHM help or via context F1. They show an empty page. But it 
shows the default page if I open prog.chm for example in LHelp via 
File/Open.


An other difference: Calling LHelp via context F1 doesn't show the toc. 
Tested with F1 on "TForm".


Rolf


Hi Rolf,
I have placed the next version of patch and created a branch on a forum 
for discussion 
https://forum.lazarus.freepascal.org/index.php/topic,53218.0.html


--
Andrey
--
___
lazarus mailing list
lazarus@lists.lazarus-ide.org
https://lists.lazarus-ide.org/listinfo/lazarus


[Lazarus] How to hide pop-up menu before taking a screen snapshot?

2021-02-07 Thread Bo Berglund via lazarus
I have worked on a tool to copy a region of the Windows desktop for use in
illustrations. The tool consists of a transparent form which is supposed to be
located on top of the area to copy.

This form has a pop-up menu where there are 3 items to select from:
- Copy image
- Copy position
- Close

When I use the "Copy image" function the resulting image contains the selected
menu item caption on top of the copied desktop bitmap...

I have tried various ways to get rid of this but everything I tried has failed.
So how can I hide the menu item caption in code before I make the image
extraction?

I even added a timer set to 50 ms interval and put the image copy in its ontimer
event hoping that the menu click should have exited and the text disappeared
before the image copy happened, but no go...

Here is the way the copy is commanded via the popup menu:
http://blog.boberglund.com/files/Lazarus_popmenu_usage.png

And here is a captured image where the popup caption is visible:
http://blog.boberglund.com/files/Lazarus_popmenu.png

As you can see the caption of the clicked menu item is still present in the
screenshot image...

Here is parts of the code:

procedure TfrmMain.miCopyImageClick(Sender : TObject);
begin
  //CopyScreenRect;  //Moved to timer
  //miCopyImage.Visible := false; //Does not work
  //self.Refresh;  //Does not work
  timCopyImg.Enabled := true;  //make copy inside timer event?
end;

procedure TfrmMain.miCopyPosClick(Sender : TObject);
begin
  SaveRectCoords; //Saving rect coordinates to clipboard (OK)
end;

procedure TfrmMain.timCopyImgTimer(Sender : TObject);
begin
  timCopyImg.Enabled := false;
  miCopyImage.Visible := false; //Does not work, caption still present
  self.Refresh;  //Does also not work to remove caption
  CopyScreenRect;
  miCopyImage.Visible := true;  //Put it back to enable next capture
end;

procedure TfrmMain.CopyScreenRect;
var
  MyCapture : TBgraBitmap;
  Clip: TRect;
begin
  try
Clip := Bounds(Self.Left, Self.Top, Self.Width, Self.Height);
Self.Visible := false; //Hide selection form before copy
//Self.Hide;  //Not working for popup menu item...
MyCapture := TBgraBitmap.Create();
MyCapture.TakeScreenShot(Clip);
Self.Visible := true; //Show selection form after copy is done
//Self.Show;  //Not working for popup menu item...
Clipboard.Assign(MyCapture.Bitmap);
  except
on E: exception do
  Clipboard.AsText := E.Message;
  end;
end;

Even Self.Visible or Self.Hide do not remove the menuitem caption

What can I do?

Lazarus 2.0.10 / fpc 3.2.0 on Windows 10


-- 
Bo Berglund
Developer in Sweden

-- 
___
lazarus mailing list
lazarus@lists.lazarus-ide.org
https://lists.lazarus-ide.org/listinfo/lazarus