Recent

Author Topic: [solved] Confused using PrintWindow  (Read 2407 times)

Cliff48

  • Jr. Member
  • **
  • Posts: 51
[solved] Confused using PrintWindow
« on: June 27, 2015, 10:59:24 pm »
Ok tearing the last of my hair out as I keep trying many things to make something work.  I have a popup menu that:
Code: [Select]
procedure TForm1.MenuItem2Click(Sender: TObject);   
begin
  bmp := Tbitmap.Create;
.
.  A bunch of code to manipulate image in a TBitmap
. (content changes each time here). It gets content
. from a DC that was filled via PrintWindow
.
  bmp.Canvas.Changed;
  Image1.Picture.Assign(bmp);
  bmp.Free;
end;


This works perfectly and I can click the menuItem  many times in quick succession and its fine 9 out of 10 times, or 10 out of ten if not clicking too quickly.

So I added another menu item:

Code: [Select]
procedure TForm1.MenuItem3Click(Sender: TObject);
begin
        // simulating 5 clicks of popup Item2
  for i := 1 to 5 do begin
    Delay(2000);
    MenuItem2Click(self);
  end;
end;

It doesn't matter what I set the delay to, I basically only get the titlebar from the window I tried to access.  Even the first itteration (i=1) does this, which leads me to believe its not directly a PrintWindow issue.

I have also tested by running the program directly (not in IDE) and get the same results.  Any suggestions greatly appreciated.
 
« Last Edit: June 27, 2015, 11:28:36 pm by Cliff48 »
Laz Ver 1.4.0  FPC 2.6.4 SVN 48774
Win 7 Ultimate SP1
Intel I7-2600 CPU @  3.40GHZ 8GB Ram 64bit OS

rvk

  • Hero Member
  • *****
  • Posts: 4281
Re: Confused using PrintWindow
« Reply #1 on: June 27, 2015, 11:21:47 pm »
So I added another menu item:

Code: [Select]
procedure TForm1.MenuItem3Click(Sender: TObject);
begin
        // simulating 5 clicks of popup Item2
  for i := 1 to 5 do begin
    Delay(2000);
    MenuItem2Click(self);
  end;
end;

It doesn't matter what I set the delay to, I basically only get the titlebar from the window I tried to access.  Even the first itteration (i=1) does this, which leads me to believe its not directly a PrintWindow issue.
If you're using this in a loop, like your test menu-item, you'll need to add a ProcessMessages in there or the application has no way to update your screen.

So:
Code: [Select]
procedure TForm1.MenuItem3Click(Sender: TObject);
begin
        // simulating 5 clicks of popup Item2
  for i := 1 to 5 do begin
    Delay(2000);
    MenuItem2Click(self);
    Application.ProcessMessages;
  end;
end;

This works perfectly and I can click the menuItem  many times in quick succession and its fine 9 out of 10 times, or 10 out of ten if not clicking too quickly.
What is actually the problem? What happens 1 time out of those 10??

If it's not updating the image you could add the ProcessMessages in the MenuItem2Click.

Cliff48

  • Jr. Member
  • **
  • Posts: 51
Re: Confused using PrintWindow
« Reply #2 on: June 27, 2015, 11:28:12 pm »
Thank you rvk, that fixed it.  Now I am really kicking myself... I knew that!!!! Why does the brain go looking for ridiculous solutions instead of ones already in the armoury?

Thanks so much!!
Laz Ver 1.4.0  FPC 2.6.4 SVN 48774
Win 7 Ultimate SP1
Intel I7-2600 CPU @  3.40GHZ 8GB Ram 64bit OS

BitBangerUSA

  • Full Member
  • ***
  • Posts: 183
Re: [solved] Confused using PrintWindow
« Reply #3 on: June 27, 2015, 11:58:37 pm »
Quote
Why does the brain go looking for ridiculous solutions

because, IMO, one of the hardest things to learn in trouble-shooting is how to recognize when you're going down the wrong path.
i've no doubt you 'knew that' - and that everyone has done the same at least once.
techies need persistence - as long as it doesn't result in the classic 'doing the same thing over and over and expecting different results' scenario.
Lazarus Ver 1.4.0 FPC Ver 2.6.4 SVN 48774 32-bit
Windows 7 U 64-bit

 

TinyPortal © 2005-2018