• Visitors can check out the Forum FAQ by clicking this link. You have to register before you can post: click the REGISTER link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. View our Forum Privacy Policy.
  • Want to receive the latest contracting news and advice straight to your inbox? Sign up to the ContractorUK newsletter here. Every sign up will also be entered into a draw to WIN £100 Amazon vouchers!

CreateCompatibleBitmap

Collapse
X
  •  
  • Filter
  • Time
  • Show
Clear All
new posts

    CreateCompatibleBitmap

    I have used one of these to do a screen grab. I have a device context to my GTK image widget, and want to load my bitmap into the image

    code is below.

    So I think I have done the screen grab ok, I just cannot see the end result. I would like to load it into the Image box I have, but dumping to file is just as good. Been googling this for a while now, and everything I try does not work.

    What is the shortest way to get this working? Any suggestions? This is only for POC so no need to go to town on it.

    Code:
    int doScreenGrab(HANDLE clientDC)
    {
    	HANDLE hScreenDC;
    	HANDLE hMemDC;
    	HANDLE hWnd;
    	HGDIOBJ     hOldBitmap , hBitmap;
    	
    	long xWidth = GetSystemMetrics(SM_CXSCREEN);
    	long yHeight = GetSystemMetrics(SM_CYSCREEN);
    	
    	g_print("Desktop metrics xWidth : %d yHeight : %d \n",xWidth,yHeight);
    	
    	hScreenDC = GetDC(0);
    	hMemDC = CreateCompatibleDC(hScreenDC);
    	
    	g_print ("Desktop Device Context %d \n", hScreenDC);
    	g_print ("Memory Device Context %d \n", hMemDC);
    	hWnd = WindowFromDC(hScreenDC);
    	g_print ("Desktop hWnd %d \n", hWnd);
    	
    	hBitmap = CreateCompatibleBitmap(hScreenDC, xWidth, yHeight);   
    	hOldBitmap =   SelectObject (hMemDC, hBitmap);
    	BitBlt(hMemDC, 0, 0, 100, 100, hScreenDC, xWidth, yHeight, SRCCOPY);
    
    	hBitmap = SelectObject(hMemDC, hOldBitmap);   
    	BitBlt(clientDC, 0, 0, 100, 100, hMemDC, xWidth, yHeight, SRCCOPY);
    	
    	DeleteDC(hScreenDC);     
    	DeleteDC(hMemDC);     
    }
    Knock first as I might be balancing my chakras.

    #2
    You've got the 7th & 8th parameters of both BitBlts wrong. It's xsrc, ysrc, not width and height, so should be 0,0.

    BitBlt won't stretch. If you're expecting to get a small thumbnail of the whole screen, you want StretchBlt.

    Code:
    // copy whole screen to Memory bitmap
    BitBlt(hMemDC, 0, 0, xWidth, yHeight, hScreenDC, 0, 0, SRCCOPY);
    
    hBitmap = SelectObject(hMemDC, hOldBitmap);
    
    // stretch to 100,100
    StretchBlt(clientDC, 0, 0, 100, 100, hMemDC, 0, 0, xWidth, yHeight, SRCCOPY);
    Will work inside IR35. Or for food.

    Comment


      #3
      Originally posted by VectraMan View Post
      You've got the 7th & 8th parameters of both BitBlts wrong. It's xsrc, ysrc, not width and height, so should be 0,0.

      BitBlt won't stretch. If you're expecting to get a small thumbnail of the whole screen, you want StretchBlt.

      Code:
      // copy whole screen to Memory bitmap
      BitBlt(hMemDC, 0, 0, xWidth, yHeight, hScreenDC, 0, 0, SRCCOPY);
      
      hBitmap = SelectObject(hMemDC, hOldBitmap);
      
      // stretch to 100,100
      StretchBlt(clientDC, 0, 0, 100, 100, hMemDC, 0, 0, xWidth, yHeight, SRCCOPY);

      Thanks VM. That helped.
      Knock first as I might be balancing my chakras.

      Comment

      Working...
      X