【文件属性】:
文件名称:C++面向对象与可视化教程
文件大小:3.24MB
文件格式:RAR
更新时间:2013-07-23 03:47:35
MFC、GUI
#include
#include
#include
#include
LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInst,LPSTR lpszCmdLine,int nCmdShow)
{
HWND hwnd;
MSG Msg;
WNDCLASS wndclass;
char lpszClassName[] = "基本绘图";
char lpszTitle[]= "My_Drawing";
wndclass.style = 0;
wndclass.lpfnWndProc = WndProc ;
wndclass.cbClsExtra = 0 ;
wndclass.cbWndExtra = 0 ;
wndclass.hInstance = hInstance ;
wndclass.hIcon = LoadIcon( NULL, IDI_APPLICATION) ;
wndclass.hCursor = LoadCursor( NULL, IDC_ARROW) ;
wndclass.hbrBackground =(HBRUSH) GetStockObject( WHITE_BRUSH) ;
wndclass.lpszMenuName = NULL ;
wndclass.lpszClassName = lpszClassName ;
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, nCmdShow);
UpdateWindow(hwnd);
while( GetMessage(&Msg, NULL, 0, 0))
{
TranslateMessage(&Msg) ;
DispatchMessage(&Msg) ;
}
return Msg.wParam;
}
LRESULT CALLBACK WndProc(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam)
{ HDC hdc;
PAINTSTRUCT ps;
HPEN hP; //定义画笔句柄
HBRUSH hB; //定义画刷句柄
switch(message)
{
case WM_PAINT: //通过响应WM_PAINT消息完成绘图工作
hdc=BeginPaint(hwnd,&ps); //取得设备环境句柄
SetMapMode(hdc,MM_TEXT); //设置映射模式
Rectangle(hdc,130,60,270,200); //使用当前画笔绘制矩形并填充
hB=CreateHatchBrush(HS_CROSS,RGB(255,0,0)); //自定义一个红色网格状画刷
SelectObject(hdc,hB); //更新画刷为自定义画刷
Ellipse(hdc,130,70,270,190); //绘制椭圆并填充
hP=CreatePen(PS_DASHDOT,1,RGB(0,255,0)); //宽度为1的绿色画笔,画点划线
SelectObject(hdc,hP); //更新画笔为自定义画笔
MoveToEx(hdc,100,130,NULL); //使用当前画笔绘制轴线
LineTo(hdc,300,130);
MoveToEx(hdc,200,30,NULL);
LineTo(hdc,200,230);
EndPaint(hwnd,&ps); //释放设备环境句柄
DeleteObject(hP); //删除画笔句柄
DeleteObject(hB); //删除黑色画刷句柄
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd,message,wParam,lParam);
}
return 0;
}
【文件预览】:
08201Visual C++面向对象与可视化程序设计(第2版)
----08_MFC.pps(238KB)
----07_Resource_SDK.pps(278KB)
----06_vc_KB_mouse.pps(195KB)
----11_SDI_MDI.pps(235KB)
----05_vc_text_font.pps(161KB)
----04_vc_GUI.pps(380KB)
----03_vc_API.pps(341KB)
----01.ppt(1MB)
----09_control.pps(619KB)
----12_MultiMedia.pps(142KB)
----13_database.pps(207KB)
----10_resource_MFC.pps(262KB)
----02_vc.pps(609KB)
----14_iinternet.pps(154KB)