VC++面向对象与可视化程序设计 04 GUI - 图文

BOOL InitWindowsClass(HINSTANCE hInstance);

BOOL InitWindows(HINSTANCE hInstance,int nCmdShow);

//主函数

( HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow)MSG Message;

if(!InitWindowsClass(hInstance))return FALSE;if(!InitWindows(hInstance,nCmdShow))return FALSE;while(GetMessage(&Message,0,0,0))//消息循环{

TranslateMessage(&Message);DispatchMessage(&Message);}

return Message.wParam;

{

}

long WINAPI WndProc(HWND hWnd,UINT iMessage,消息处理函数UINT wParam,LONG lParam) {HDC hDC; //定义指向设备的句柄HBRUSH hBrush; //定义指向画刷的句柄HPEN hPen;//定义指向画笔的句柄PAINTSTRUCT PtStr;//定义指向包含绘图信息的结构体变量switch(iMessage) //处理消息{case WM_PAINT://处理绘图消息hDC=BeginPaint(hWnd,&PtStr);SetMapMode(hDC,MM_ANISOTROPIC); //设置映像模式hPen=(HPEN)GetStockObject(BLACK_PEN);//黑色画笔hBrush=(HBRUSH)GetStockObject(DKGRAY_BRUSH); //画刷SelectObject(hDC,hBrush); //选择画刷下面只改变画刷,不改变笔SelectObject(hDC,hPen); //选择画笔RoundRect(hDC,50,120,100,200,15,15); //绘制圆角矩形hBrush=(HBRUSH)GetStockObject(LTGRAY_BRUSH); //采用亮灰色画刷SelectObject(hDC,hBrush); //选择画刷

Ellipse(hDC,150,50,200,150); SelectObject(hDC,hBrush); EndPaint(hWnd,&PtStr);

//绘制椭圆//选择画刷//结束绘图

//结束应用程序

hBrush=(HBRUSH)GetStockObject(HOLLOW_BRUSH); //虚画刷Pie(hDC,250,50,300,100,250,50,300,50); //绘制饼形

return 0;case WM_DESTROY:

PostQuitMessage(0); return 0;

default:}

//其他消息处理程序

return(DefWindowProc(hWnd,iMessage,wParam,lParam)) ;

}

BOOL InitWindows(HINSTANCE hInstance,int nCmdShow)//初始化窗口{HWND hWnd;

hWnd=CreateWindow(\生成窗口

\填充示例程序\

WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,0,

CW_USEDEFAULT,0,NULL,NULL,

hInstance,NULL);

if(!hWnd)return FALSE;ShowWindow(hWnd,nCmdShow);//显示窗口UpdateWindow(hWnd);return TRUE;

}

联系客服:779662525#qq.com(#替换为@)