void DisSrceen() { int x = 10, y = 10; int BitWidth = GetSystemMetrics(SM_CXSCREEN); int BitHeight = GetSystemMetrics(SM_CYSCREEN); //Define Variable HDC hdcmy,hbufferdc; HBITMAP hBit,hOldBitmap; //Create DesktopDC hdcmy = CreateDC("DISPLAY",NULL,NULL,NULL); hbufferdc = CreateCompatibleDC(hdcmy); //Create Hbitmap hBit = CreateCompatibleBitmap(hdcmy, BitWidth, BitHeight); //Get bit to Buffer hOldBitmap = (HBITMAP)SelectObject(hbufferdc, hBit); StretchBlt(hbufferdc, 0, 0, BitWidth, BitHeight, hdcmy, 0, 0, BitWidth, BitHeight, SRCCOPY); //Get finally bit hBit = (HBITMAP)SelectObject(hbufferdc, hOldBitmap); //Release Memory DeleteObject(hOldBitmap); ReleaseDC(NULL,hdcmy); ReleaseDC(NULL,hbufferdc); HBITMAP hbitmap = hBit; //get desktop dc CDC *dc = CDC::FromHandle(::GetWindowDC(::GetDesktopWindow())); CDC dcMemory; dcMemory.CreateCompatibleDC(dc); CBitmap *bitmap = new CBitmap(); if(hbitmap) { bitmap->Attach(hbitmap); } else { AfxMessageBox("ERROR: hbitmap is NULL."); goto END; } long bmWidth,bmHeight; BITMAP bm; bitmap->GetBitmap(&bm); bmWidth=bm.bmWidth; bmHeight=bm.bmHeight; dcMemory.SelectObject(bitmap); dc->BitBlt( 100, 100, bmWidth, bmHeight, &dcMemory, 0, 0, SRCCOPY); END: dc->Detach(); dcMemory.Detach(); bitmap->Detach(); }
|