Thread: getting hidden windows content

  1. #1
    Registered User
    Join Date
    Sep 2006
    Posts
    13

    getting hidden windows content

    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:

    Code:
    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

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

    Code:
     	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
    Last edited by Ken Fitlike; 09-20-2006 at 12:39 PM. Reason: added code tags

  2. #2
    Its hard... But im here swgh's Avatar
    Join Date
    Apr 2005
    Location
    England
    Posts
    1,688
    Perhaps a MOD can move this to windows programming board, it is not standartd C++

  3. #3
    Reverse Engineer maxorator's Avatar
    Join Date
    Aug 2005
    Location
    Estonia
    Posts
    2,318
    USE CODE TAGS

    I don't really understand, what you are trying to do. Are you trying to activate a window?

  4. #4

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. how to make a windows application
    By crvenkapa in forum C++ Programming
    Replies: 3
    Last Post: 03-26-2007, 09:59 AM
  2. dual boot Win XP, win 2000
    By Micko in forum Tech Board
    Replies: 6
    Last Post: 05-30-2005, 02:55 PM
  3. Question..
    By pode in forum Windows Programming
    Replies: 12
    Last Post: 12-19-2004, 07:05 PM
  4. SDL and Windows
    By nickname_changed in forum Windows Programming
    Replies: 14
    Last Post: 10-24-2003, 12:19 AM
  5. IE 6 status bar
    By DavidP in forum Tech Board
    Replies: 15
    Last Post: 10-23-2002, 05:31 PM