How to capture inactive window
Hi all
I'm trying to write some simple code that makes window capture of all my current windows. I have all windows in list - with theirs HWND, but I can't get their screen - when i call GetWindowDC - and make a bitmap from that DC - the result is part of my top window (active) with positioning and size of window I want to capture. Is there some way to get DC of inactive or hidden window ?
Thnx for any help.
As far as I know there is no way to capture the window contents if is not the foreground window. Many proffessional programs that make capture minimize themselves and then (usually) using a hot hey make the capture.
But a simple idea is:
But a simple idea is:
// hwndIWANTTOCAPTURETHIS -> window you want to capture// hwd -> help variable....// Get active window hwd = GetActiveWindow(); // bring window to front the capture you want to capture BringWindowToTop(hwndIWANTTOCAPTURETHIS); // <<PLACE YOU CAPTURE CODE HERE>>// Restore the original top window BringWindowToTop(hwd);
Huh.. thnx for quick reply.
I see BringWindowToTop function for the first time - I never heard about that.
Thank you very much !
I see BringWindowToTop function for the first time - I never heard about that.
Thank you very much !
BringWindowToTop:
return zero if fails, nonzero value if succesful
NOTICE: BringWindowToTop works only within current application.
-------------------
To activate another's application window try instead:
SetForegroundWindow:
return zero if fails, nonzero value if succesful
BOOL BringWindowToTop( HWND hWnd // handle to window );
return zero if fails, nonzero value if succesful
NOTICE: BringWindowToTop works only within current application.
-------------------
To activate another's application window try instead:
SetForegroundWindow:
BOOL SetForegroundWindow( HWND hWnd // handle of window to bring to foreground );
return zero if fails, nonzero value if succesful
under certain versions of Windows, SetForegroundWindow will not bring the window to the foreground if that window is not owned by the current thread. the following code solves that problem:
void SetForegroundWnd( HWND hWnd )
{
if( IsWindowVisible(hWnd) )
{
if( hWnd != GetForegroundWindow() )
{
if( IsIconic(hWnd) )
ShowWindow(hWnd, SW_RESTORE);
AttachThreadInput(
GetWindowThreadProcessId(GetForegroundWindow(), NULL),
GetWindowThreadProcessId(hWnd, NULL),
TRUE);
SetForegroundWindow(hWnd);
SetFocus(hWnd);
AttachThreadInput(
GetWindowThreadProcessId(GetForegroundWindow(), NULL),
GetWindowThreadProcessId(hWnd, NULL),
TRUE);
}
}
}
void SetForegroundWnd( HWND hWnd )
{
if( IsWindowVisible(hWnd) )
{
if( hWnd != GetForegroundWindow() )
{
if( IsIconic(hWnd) )
ShowWindow(hWnd, SW_RESTORE);
AttachThreadInput(
GetWindowThreadProcessId(GetForegroundWindow(), NULL),
GetWindowThreadProcessId(hWnd, NULL),
TRUE);
SetForegroundWindow(hWnd);
SetFocus(hWnd);
AttachThreadInput(
GetWindowThreadProcessId(GetForegroundWindow(), NULL),
GetWindowThreadProcessId(hWnd, NULL),
TRUE);
}
}
}
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement