Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Print Active window repainted just after SetForegroundWindow

Posted on 2006-11-04
4
381 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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

Suggested Solutions

Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

861 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