大家帮我看看这代码,为什么运行是什么都没看到啊?急
设置映射与映射模式,本例要求程序的的初始阶段按模式MM_TEXT绘图,用户通过单击鼠标以改变映射模式。用户点鼠标左键时,通过应用程序设置映射模式为ISOTROPIC,并调用InvalidateRect函数刷新用户区;单击右键时,映射模式设置为ANSIOTROPIC,同时刷新用户区。
运行时什么都看不到!郁闷中……,大家帮帮忙看看,谢谢
代码如下:
#include <windows.h>
#include <string.h>
#include <stdlib.h>
#include<stdio.h>
int nMode;
LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,
LPSTR lpCmdLine,int nShowCmd)
{
HWND hwnd;
MSG Msg;
WNDCLASS wndclass;
char lpszClassName[]="映射模式";
char lpszTitle[]="my_map_mode";
wndclass.cbClsExtra=0;
wndclass.cbWndExtra=0;
wndclass.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);
wndclass.hCursor=LoadIcon(NULL,IDC_ARROW);
wndclass.hIcon=LoadIcon(NULL,IDI_APPLICATION);
wndclass.hInstance=hInstance;
wndclass.lpfnWndProc=WndProc;
wndclass.lpszClassName=lpszClassName;
wndclass.lpszMenuName=NULL;
wndclass.style=0;
if(RegisterClass(&wndclass))
{
MessageBeep(0);return FALSE;
}
hwnd=CreateWindow(lpszClassName,lpszTitle,WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,
NULL,NULL,hInstance,NULL);
ShowWindow(hwnd,nShowCmd);
UpdateWindow(hwnd);
while(GetMessage(&Msg,NULL,0,0))
{
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
return Msg.lParam;
}
LRESULT CALLBACK WndProc(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam)
{
HDC hdc;
PAINTSTRUCT ps;
HBRUSH hB1,hB2;
switch(message)
{
case WM_LBUTTONDOWN:
nMode=MM_ISOTROPIC;
InvalidateRect(hwnd,NULL,1);break;
case WM_PAINT:
hdc=BeginPaint(hwnd,&ps);
SetMapMode(hdc,nMode);
SetWindowExtEx(hdc,150,150,NULL);
SetViewportExtEx(hdc,150,100,NULL);
SetViewportOrgEx(hdc,150,60,NULL);
hB1=(HBRUSH)GetStockObject(WHITE_BRUSH);
hB2=(HBRUSH)GetStockObject(BLACK_BRUSH);
SelectObject(hdc,hB1);
RoundRect(hdc,0,0,150,150,30,30);
SelectObject(hdc,hB2);
Ellipse(hdc,0,10,150,140);
EndPaint(hwnd,&ps);
DeleteObject(hB1);
DeleteObject(hB2);
break;
case WM_DESTROY:
PostQuitMessage(0);break;
case WM_RBUTTONDOWN:
nMode=MM_ANISOTROPIC;
InvalidateRect(hwnd,NULL,1);break;
default:
return DefWindowProc(hwnd,message,wParam,lParam);
}
return 0;
}