LRESULT CALLBACK WndProc(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam)
{
static HBITMAP hBitmap;
static int cxClient,cyClient,cxSource,cySource;
BITMAP bitmap;
HDC hdc,hdcMem;
HINSTANCE hInstance;
int x,y;
PAINTSTRUCT ps;
switch(message)
{
case WM_CREATE:
//实例句柄
hInstance=((LPCREATESTRUCT)lParam)->hInstance;
//载入图片
hBitmap=LoadBitmap(hInstance,TEXT("Bricks"));
//该函数得到指定图形对象的信息
GetObject(hBitmap,sizeof(BITMAP),&bitmap);
cxSource=bitmap.bmWidth;
cySource=bitmap.bmHeight;
return 0;
case WM_SIZE:
cxClient=LOWORD(lParam);
cyClient=HIWORD(lParam);
return 0;
case WM_PAINT:
hdc=BeginPaint(hwnd,&ps);
//创建设备上下文
hdcMem=CreateCompatibleDC(hdc);
//把hBitmap选入设备
SelectObject(hdcMem,hBitmap);
for(y=0;y<cyClient;y+=cySource)
for(x=0;x<cxClient;x+=cxSource)
//把设备环境中的图像进行块转换,放入目标设备中
BitBlt(hdc,x,y,cxSource,cySource,hdcMem,0,0,SRCCOPY);
//删除设备环境
DeleteDC(hdcMem);
EndPaint(hwnd,&ps);
return 0;
case WM_DESTROY:
//删除hBitmap
DeleteObject(hBitmap);
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hwnd,message,wParam,lParam);
}
《Windows程序设计》之位块传输
最新推荐文章于 2021-02-12 20:02:11 发布