Solved

Print Active window repainted just after SetForegroundWindow

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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

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…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Suggested Courses

734 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