Solved

Print Active window repainted just after SetForegroundWindow

Posted on 2006-11-04
4
384 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
[X]
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
  • 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Suggested Courses

628 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