Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Print Active window repainted just after SetForegroundWindow

Posted on 2006-11-04
4
Medium Priority
?
392 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 1200 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 800 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
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…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

916 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