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程序设计》之位块传输
最新推荐文章于 2025-01-15 15:38:09 发布
本文介绍了一个使用Windows API进行绘图的基本示例。通过加载位图资源并将其绘制到窗口中,展示了如何响应窗口大小调整及重绘消息。示例包括了加载位图、创建兼容的设备上下文、选择位图对象、位块传送等关键步骤。

951

被折叠的 条评论
为什么被折叠?



