1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
|
int _tmain(int argc, _TCHAR* argv[]) { //获取屏幕DC HDC hDesktopDC = CreateDC(L"DISPLAY", NULL, NULL, NULL); //内存DC HDC hMemoryDC = CreateCompatibleDC(hDesktopDC); //得到屏幕宽度 int nScreenWidth = GetSystemMetrics(SM_CXSCREEN); int nScreenHeight = GetSystemMetrics(SM_CYSCREEN); //根据屏幕DC创建屏幕位图 HBITMAP hCaptureBitmap = CreateCompatibleBitmap(hDesktopDC, nScreenWidth, nScreenHeight); //将位图选择到内存DC中 SelectObject(hMemoryDC, hCaptureBitmap); //将屏幕DC传送到内存DC中 BitBlt(hMemoryDC, 0, 0, nScreenWidth, nScreenHeight, hDesktopDC, 0, 0, SRCCOPY); //得到鼠标位置 POINT pt; GetCursorPos(&pt); //加载鼠标位图 HCURSOR m_hcursor = LoadCursor(NULL, IDC_ARROW); DrawIconEx(hMemoryDC, pt.x, pt.y, m_hcursor, 0, 0, 0, NULL, DI_NORMAL | DI_COMPAT); SelectObject(hMemoryDC, hCaptureBitmap); char str1[50] = "D:/123.bmp"; SaveBMPToFile(hCaptureBitmap, str1, pt.x, pt.y); DeleteDC(hDesktopDC); DeleteDC(hMemoryDC); DeleteObject(hCaptureBitmap); }
|
近期评论