Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

getting hidden windows content

Status
Not open for further replies.

xximranxx

Programmer
Sep 20, 2006
3
DE
hi.

i am trying to get the contents of a visible (in the sense of WM_VISIBLE) but hidden (meaning blocked by other windows) window.

i have tried the following code, but it only produces a completely black image:

void PrintWindow(CWnd* window) //handle to window in question
{
//memory DC
CDC memDC;

//DC of window in question
CDC *pDC = (*window).GetDC();

//make the memory DC compatible to window DC
memDC.CreateCompatibleDC(pDC);


//create a bitmap compatible to window DC, here just using 100x100
CBitmap bitmap;
bitmap.CreateCompatibleBitmap(pDC, 100, 100);


//select the bitmap into memory DC
CBitmap *pOldBitmap = (CBitmap *)memDC.SelectObject(&bitmap);


//sendmessage to window to print itself into memory DC
(*window).SendMessage(WM_PRINT, (WPARAM)memDC.GetSafeHdc(), PRF_CLIENT | PRF_ERASEBKGND | PRF_NONCLIENT );


//create the desktop DC to display the result
CDC desktop;
desktop.CreateDC("DISPLAY",NULL,NULL,NULL);


//bit to bit transfer of memory DC onto the desktop
desktop.BitBlt(0,0,100,100,&memDC,0,0,SRCCOPY);

//this now shows a black rectangle on the top left corner of my desktop

//then comes some cleanup (release all the DC's etc...

}

if instead of

(*window).SendMessage(WM_PRINT, (WPARAM)memDC.GetSafeHdc(), PRF_CLIENT | PRF_ERASEBKGND | PRF_NONCLIENT );

i use

memDC.BitBlt(0,0,100,100,pDC,0,0,SRCCOPY);

and then display memDC (again by bitblt) to desktop, then the correct image is shown (top left box of window), but
only if the window is visible.

which is why i used sendmessage with WM_PRINT.

please help if you can, as this is coming a major obstacle in my application.
i am using windows xp with service pack 2.

thanks to everyone reading this.

imran
 
When you define the contents of your windows, create a window sized bitmap and draw the contents on to there. In the WM_PAINT, do a BitBlt to get it on the screen.

Now when you want to print it, just BitBlt the bitmap to the print device context.
 
hi miros.

well, the problem is that the window that i want the content from is not my own window. its some other app...

any ideas?

thanks
 
Oh, that's another kettle of fish!

Maybe you could send it to the front, wait a second for it to redraw, then grab the contents?
 
yeah..i know, and thats a problem too...the second i need to wait for redrawing..that gap should be minimized for my app (the less the better). but time gap depends on the machine, cpu power etc. so its not forseeable.

theres no way to find out whether a window has already redrawn itself or not, is there?
 
Hm, I think there's a message you can send to find out if a window is not hidden, but don't remember what it is. Will look it up and get back to you.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top