HElpppppppppppp
-
LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { HDC hdc ; PAINTSTRUCT ps ; RECT rect ; HDC hdcWindow; static int nScreenWidth, nScreenHeight; switch (message) { case WM_CREATE: nScreenWidth = GetSystemMetrics(SM_CXSCREEN); nScreenHeight = GetSystemMetrics(SM_CYSCREEN); SetTimer( hwnd,0,2000,NULL); return 0 ; case WM_LBUTTONDOWN: { HWND tBarHandle= NULL; return 0; } case WM_PAINT: { hdc = BeginPaint (hwnd, &ps) ; hdcWindow = GetWindowDC( hwnd); HWND hDesktopWnd = GetDesktopWindow(); HDC Source = GetDC(hDesktopWnd); HDC Destination = CreateCompatibleDC(Source); HBITMAP hCaptureBitmap =CreateCompatibleBitmap(Source, nScreenWidth, nScreenHeight); SelectObject(Destination,hCaptureBitmap); BitBlt(Destination,0,0,nScreenWidth,nScreenHeight, Source, 0, 0, SRCCOPY); BitBlt(hdc,0,0 , nScreenWidth, nScreenHeight, Source, 0,0, SRCCOPY); ReleaseDC(hDesktopWnd,Destination); DeleteDC(Source); DeleteObject(hCaptureBitmap); EndPaint (hwnd, &ps) ; } return 0 ; case WM_TIMER: GetClientRect(hwnd,&rect); InvalidateRect( hwnd, &rect, true); return 0; case WM_DESTROY: PostQuitMessage (0) ; return 0 ; } return DefWindowProc (hwnd, message, wParam, lParam) ; } How to convert DDB format to DIB format using GETDIBits() function ????
-
LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { HDC hdc ; PAINTSTRUCT ps ; RECT rect ; HDC hdcWindow; static int nScreenWidth, nScreenHeight; switch (message) { case WM_CREATE: nScreenWidth = GetSystemMetrics(SM_CXSCREEN); nScreenHeight = GetSystemMetrics(SM_CYSCREEN); SetTimer( hwnd,0,2000,NULL); return 0 ; case WM_LBUTTONDOWN: { HWND tBarHandle= NULL; return 0; } case WM_PAINT: { hdc = BeginPaint (hwnd, &ps) ; hdcWindow = GetWindowDC( hwnd); HWND hDesktopWnd = GetDesktopWindow(); HDC Source = GetDC(hDesktopWnd); HDC Destination = CreateCompatibleDC(Source); HBITMAP hCaptureBitmap =CreateCompatibleBitmap(Source, nScreenWidth, nScreenHeight); SelectObject(Destination,hCaptureBitmap); BitBlt(Destination,0,0,nScreenWidth,nScreenHeight, Source, 0, 0, SRCCOPY); BitBlt(hdc,0,0 , nScreenWidth, nScreenHeight, Source, 0,0, SRCCOPY); ReleaseDC(hDesktopWnd,Destination); DeleteDC(Source); DeleteObject(hCaptureBitmap); EndPaint (hwnd, &ps) ; } return 0 ; case WM_TIMER: GetClientRect(hwnd,&rect); InvalidateRect( hwnd, &rect, true); return 0; case WM_DESTROY: PostQuitMessage (0) ; return 0 ; } return DefWindowProc (hwnd, message, wParam, lParam) ; } How to convert DDB format to DIB format using GETDIBits() function ????
Something like this maybe... (warning - I haven't provided for a color table of any kind!! This means this won't work for a palette-based video mode or a non BI_RGB DIB, which is why I force it to BI_RGB)
int nScreenWidth = ::GetSystemMetrics(SM_CXSCREEN);
int nScreenHeight = ::GetSystemMetrics(SM_CYSCREEN);HDC Source = ::GetDC(0);
HDC Destination = ::CreateCompatibleDC(Source);
HBITMAP hCaptureBitmap = ::CreateCompatibleBitmap(Source, nScreenWidth, nScreenHeight);
HGDIOBJ hOldBm = ::SelectObject(Destination, hCaptureBitmap);
::BitBlt(Destination,0,0,nScreenWidth,nScreenHeight, Source, 0, 0, SRCCOPY);
::SelectObject(Destination, hOldBm);BITMAPINFO bmi;
memset(&bmi, 0, sizeof(BITMAPINFO));
bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);// Fill the BITMAPINFO struct with info from the DDB
::GetDIBits(Source, hCaptureBitmap, 0, nScreenHeight, NULL, &bmi, DIB_RGB_COLORS);// Normally, you'd want to reallocate the BITMAPINFO struct so there's enough room for
// any color table or bitfield entries here!!// *optional* Adjust the BITMAPINFO struct to the desired DIB format here
bmi.bmiHeader.biCompression = BI_RGB;BYTE *pPixelBytes = new BYTE[bmi.bmiHeader.biSizeImage];
// Get the DIB pixel bytes from the DDB
::GetDIBits(Source, hCaptureBitmap, 0, nScreenHeight, pPixelBytes, &bmi, DIB_RGB_COLORS);// Do something with the DIB here
::ReleaseDC(0, Source);
::DeleteDC(Destination);
::DeleteObject(hCaptureBitmap);
delete[] pPixelBytes;Also make sure you use the correct ReleaseDC/DeleteDC calls on the appropriate DCs. Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder