16,551
社区成员
发帖
与我相关
我的任务
分享HDC hdc;
HDC yin_hdc=CreateCompatibleDC(hdc);
PAINTSTRUCT ps;
RECT rc;
HBITMAP hBmp = CreateCompatibleBitmap(hdc,1000,600);
HBITMAP hOldBmp = (HBITMAP)SelectObject(yin_hdc,hBmp);
。。。。。
case WM_CREATE:
SetTimer(hwnd,1,100,NULL); //建立计时器,每?秒发出WM_TIMER消息.
hdc=GetDC(hwnd);
hdctkr = CreateCompatibleDC(yin_hdc);
hdctkg = CreateCompatibleDC(yin_hdc);
hdctkt = CreateCompatibleDC(yin_hdc);
。。。。。
case WM_PAINT:
yin_hdc=BeginPaint(hwnd,&ps);
GetClientRect(hwnd,&rc);
。。。。。
DrawTransBitmap(yin_hdc,x1,y1,60,60,hdctkr,0,0,SRCPAINT);
DrawTransBitmap(yin_hdc,x2,y2,60,60,hdctkg,0,0,SRCPAINT);
BitBlt(hdc,0,0,1000,600,yin_hdc,0,0,SRCCOPY);
SelectObject(yin_hdc,hOldBmp);
EndPaint(hwnd,&ps);
break;
case WM_TIMER: //处理由计时器发出的消息.
InvalidateRect(hwnd,NULL,1); //刷新用户区.
break;
case WM_DESTROY:
。。。。。。HDC hdc,yin_hdc;
HBITMAP hBmp,hOldBmp;
。。。。。
case WM_CREATE:
hdc=GetDC(hwnd);
yin_hdc=CreateCompatibleDC(hdc);
hBmp = CreateCompatibleBitmap(hdc,1000,600);
hOldBmp = (HBITMAP)SelectObject(yin_hdc,hBmp);
//定时器放到最后
SetTimer(hwnd,1,100,NULL); //建立计时器,每?秒发出WM_TIMER消息.
break;
case WM_PAINT:
全部绘图到yin_hdc;
hdc=GetDC(hwnd);
BitBlt(hdc,0,0,1000,600,yin_hdc,0,0,SRCCOPY); //一次性Blt到hdc屏幕
ReleaseDC(hwnd,hdc);
break;
case WM_TIMER: //处理由计时器发出的消息.
InvalidateRect(hwnd,NULL,1); //刷新用户区.
break;
case WM_DESTROY:
DeleteObject(hBmp);
DeleteDC(yin_hdc);
删除计时器;
break;
The following example code, from an application that captures an image of the entire desktop, creates a compatible device context and a bitmap with the appropriate dimensions, selects the bitmap into the compatible DC, and then copies the image using the BitBlt function.
// Create a normal DC and a memory DC for the entire screen. The
// normal DC provides a "snapshot" of the screen contents. The
// memory DC keeps a copy of this "snapshot" in the associated
// bitmap.
hdcScreen = CreateDC("DISPLAY", NULL, NULL, NULL);
hdcCompatible = CreateCompatibleDC(hdcScreen);
// Create a compatible bitmap for hdcScreen.
hbmScreen = CreateCompatibleBitmap(hdcScreen,
GetDeviceCaps(hdcScreen, HORZRES),
GetDeviceCaps(hdcScreen, VERTRES));
if (hbmScreen == 0)
errhandler("hbmScreen", hwnd);
// Select the bitmaps into the compatible DC.
if (!SelectObject(hdcCompatible, hbmScreen))
errhandler("Compatible Bitmap Selection", hwnd);
// Hide the application window.
ShowWindow(hwnd, SW_HIDE);
//Copy color data for the entire display into a
//bitmap that is selected into a compatible DC.
if (!BitBlt(hdcCompatible,
0,0,
bmp.bmWidth, bmp.bmHeight,
hdcScreen,
0,0,
SRCCOPY))
errhandler("Screen to Compat Blt Failed", hwnd);
// Redraw the application window.
ShowWindow(hwnd, SW_SHOW);