VC++ 窗口重绘
上次问那些太乱了,说简单一点是这样的:书上说建WIN32APPLICATION工程,并将WINDOWS应用程序的类型设置为:ATYPICAL"HELLOWORLD!"AP...
上次问那些太乱了,说简单一点是这样的:
书上说建WIN32 APPLICATION工程,并将WINDOWS应用程序的类型设置为:A TYPICAL "HELLO WORLD!" APPLICATION.
添加资源后在WndProc()中对WM_PAINT消息处理:
case WM_PAINT:
hdc = BeginPaint(hWnd, &ps);
// TODO: 在此添加任意绘图代码...
HBITMAP hbmp;
HDC srchdc;
hbmp=LoadBitmap(hInst,(LPCTSTR)IDB_BITMAP1);
srchdc=CreateCompatibleDC(hdc);
SelectObject(srchdc,hbmp);
BitBlt(hdc,100,100,500,500,srchdc,0,0,SRCCOPY);
DeleteObject(hbmp);
DeleteObject(srchdc);
EndPaint(hWnd, &ps);
break;
这是完全照书写的,没问题。
可是把这几句移到WndProc()的开始为什么就不行了,变量定义为全局,写成这样:
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
int wmId, wmEvent;
PAINTSTRUCT ps;
HDC hdc;
hdc=GetDC(hWnd);
HBITMAP hbmp;
HDC srchdc;
hbmp=LoadBitmap(hInst,(LPCTSTR)IDB_BITMAP1);
switch (message)
{
case WM_PAINT:
srchdc=CreateCompatibleDC(hdc);
SelectObject(srchdc,hbmp);
BitBlt(hdc,100,100,500,500,srchdc,0,0,SRCCOPY);
DeleteObject(hbmp);
DeleteObject(srchdc);
EndPaint(hWnd, &ps);
break; 展开
书上说建WIN32 APPLICATION工程,并将WINDOWS应用程序的类型设置为:A TYPICAL "HELLO WORLD!" APPLICATION.
添加资源后在WndProc()中对WM_PAINT消息处理:
case WM_PAINT:
hdc = BeginPaint(hWnd, &ps);
// TODO: 在此添加任意绘图代码...
HBITMAP hbmp;
HDC srchdc;
hbmp=LoadBitmap(hInst,(LPCTSTR)IDB_BITMAP1);
srchdc=CreateCompatibleDC(hdc);
SelectObject(srchdc,hbmp);
BitBlt(hdc,100,100,500,500,srchdc,0,0,SRCCOPY);
DeleteObject(hbmp);
DeleteObject(srchdc);
EndPaint(hWnd, &ps);
break;
这是完全照书写的,没问题。
可是把这几句移到WndProc()的开始为什么就不行了,变量定义为全局,写成这样:
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
int wmId, wmEvent;
PAINTSTRUCT ps;
HDC hdc;
hdc=GetDC(hWnd);
HBITMAP hbmp;
HDC srchdc;
hbmp=LoadBitmap(hInst,(LPCTSTR)IDB_BITMAP1);
switch (message)
{
case WM_PAINT:
srchdc=CreateCompatibleDC(hdc);
SelectObject(srchdc,hbmp);
BitBlt(hdc,100,100,500,500,srchdc,0,0,SRCCOPY);
DeleteObject(hbmp);
DeleteObject(srchdc);
EndPaint(hWnd, &ps);
break; 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询