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 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);
}

Comment