I am trying to get a 500x500 screenshot from the 0x0 (top-left) position of screen and put it in a window.
Here is my code (hwnd
is my Window Handle):
HDC appDc = GetDC(hwnd);
HDC dc = GetDC(NULL);
HBITMAP bitmap = CreateCompatibleBitmap(dc, 500, 500);
HDC memoryDc = CreateCompatibleDC(dc);
SelectObject(memoryDc, bitmap);
BitBlt(appDc, 0, 0, 500, 500, dc, 0, 0, SRCCOPY);
ShowWindow(hwnd, SW_SHOW);
SetWindowText(hwnd, _T("Window"));
What am I missing here? I am getting black inside the window instead of the screen capture.
EDIT
It works after I changed memoryDc
to dc
It previously was BitBlt(appDc, 0, 0, 500, 500, memoryDc, 0, 0, SRCCOPY);
But now the problem is SelectObject is not working.I meant Its not putting the Image in HBITMAP. However BitBlt is copying from dc
to appDc