Solved

Print Active window repainted just after SetForegroundWindow

Posted on 2006-11-04
4
368 Views
Last Modified: 2010-04-16
Hi Experts,

I know how to print the active application using SetForegroundWindow.

The problem is when I use :
SetForegroundWindow(hwnd);    // focus the window I  want
PrintActiveApp();                        // print this window  (no problem)

The problem is when the window is hidden behind another one, there is kind of delay before the window is repainted (so a part of the top window is drawn on the picture).

I only want to be sure the focused window is the one I want and this window is drawn properly to print it.

Thanks in advance for your help.
0
Comment
Question by:noulouk
  • 2
4 Comments
 
LVL 7

Accepted Solution

by:
prosh0t earned 300 total points
ID: 17873611

other than throwing in a sleep which could be unreliable, have you tried this?

SetForegroundWindow(hwnd);    // focus the window I  want

while(GetForegroundWindow() != hwnd)
{
    Application.DoEvents();
}

PrintActiveApp();                        // print this window  (no problem)

This would only work if a window considered foreground AFTER it is actually fully drawn..  I'm not sure how getforegroundindow works but it's worth a shot


0
 
LVL 29

Expert Comment

by:Gautham Janardhan
ID: 17873792
call the Invalidate method
0
 
LVL 29

Assisted Solution

by:Gautham Janardhan
Gautham Janardhan earned 200 total points
ID: 17873796
also check this site

http://msdn.microsoft.com/msdnmag/issues/06/03/WindowsFormsPerformance/default.aspx#S6

look for painting Painting Performance
0
 
LVL 9

Author Comment

by:noulouk
ID: 17873962
while(GetForegroundWindow() != hwnd)
{
    Application.DoEvents();
}

It doesn't work : I don't know when the active window is repainted because this loop doesn't wait for the paint, but get the foregroundwindow state I think.

gauthampj, I  need to use that with the active window of another app, your solution works only with my own.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Bit flags and bit flag manipulation is perhaps one of the most underrated strategies in programming, likely because most programmers developing in high-level languages rely too much on the high-level features, and forget about the low-level ones. Th…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now