[solved] Confused using PrintWindow lazarus / 39-Graphics ---------------------------------------------------------------------- Cliff48 · 2015-06-27 20:59 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. ---------------------------------------------------------------------- rvk · 2015-06-27 21:21 Quote from: Cliff48 on June 27, 2015, 10:59:24 pmSo 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; Quote from: Cliff48 on June 27, 2015, 10:59:24 pmThis 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 · 2015-06-27 21:28 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!! ---------------------------------------------------------------------- BitBangerUSA · 2015-06-27 21:58 QuoteWhy 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.