LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
int wmId, wmEvent;
PAINTSTRUCT ps;
RECT rectMy,rect;
HICON hIco;
static HDC hdc,hMemDC,hMyDC;
static HBITMAP hBitmap,hBmp;
switch (message)
{
case WM_CREATE:
//读取资源位图
hBitmap=LoadBitmap(hInst,MAKEINTRESOURCE(IDB_myBMP));
return 0;
case WM_PAINT:
hdc=BeginPaint(hWnd, &ps);
//先取得客户区大小供后续功能使用
GetClientRect(hWnd,&rect);
/****显示位图资源功能****/
//建立自适应内存DC和位图句柄
hMemDC=CreateCompatibleDC(hdc);
SelectObject(hMemDC,hBitmap);
BitBlt(hdc,0,0,rect.right-rect.left,rect.bottom-rect.top,hMemDC,0,0,SRCCOPY);
DeleteDC(hMemDC);
/****测试创建空白位图对象功能****/
hMyDC=CreateCompatibleDC(hdc);
hBmp=CreateCompatibleBitmap(hdc,rect.right-rect.left,rect.bottom-rect.top);
SelectObject(hMyDC,hBmp);
//可从持有位图资源的hMemDC中复制位图到hMyDC上
//BitBlt(hMyDC,0,0,rect.right-rect.left,rect.bottom-rect.top,hMemDC,0,0,SRCCOPY);
BitBlt(hdc,0,0,rect.right-rect.left,rect.bottom-rect.top,hMyDC,0,0,SRCCOPY);
/****绘制矩形并复制****/
//定义矩形区域坐标
rectMy.left=100;
rectMy.top=100;
rectMy.right=200;
rectMy.bottom=200;
//绘制矩形
Rectangle(hdc,rectMy.left,rectMy.top,rectMy.right,rectMy.bottom);
LineTo(hdc,250,250);
BitBlt(hdc,300,300,100,100,hdc,rectMy.left,rectMy.top,SRCCOPY);
//DeleteDC(hMemDC);
DeleteObject(hBmp);
DeleteObject(hMyDC);
EndPaint(hWnd, &ps);
return 0;
case WM_DESTROY:
DeleteObject(hBitmap);
PostQuitMessage(0);
return 0;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}