`
phinecos
  • 浏览: 342256 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

VC++学习笔记(1)

阅读更多

今天开始学习VC++,照着书上写了几个Win32的程序。

1,#include<windows.h>


LRESULTCALLBACKWndProc(HWNDhwnd,UINTiMsg,WPARAMwParam,LPARAMlParam)
{
HDChdc;
//设备环境句柄
PAINTSTRUCTps;

RECTrect;
POINTpoint;

switch(iMsg)
{
caseWM_PAINT:
{
hdc
=BeginPaint(hwnd,&ps);
GetClientRect(hwnd,
&rect);
DrawText(hdc,
"Hello,VC6.0!",-1,&rect,DT_SINGLELINE|DT_CENTER|DT_VCENTER);
EndPaint(hwnd,
&ps);
return0;
}

caseWM_LBUTTONDOWN:
{
hdc
=GetDC(hwnd);
point.x
=LOWORD(lParam);
point.y
=HIWORD(lParam);
Ellipse(hdc,point.x
-50,point.y-50,point.x+50,point.y+50);
ReleaseDC(hwnd,hdc);
return0;
}

caseWM_DESTROY:
{
PostQuitMessage(
0);
return0;
}

}

returnDefWindowProc(hwnd,iMsg,wParam,lParam);

}


intWINAPIWinMain(HINSTANCEhInstance,HINSTANCEhPrevInstance,LPSTRlpCmdLine,intnShowCmd)
{
staticcharszAppName[]="HelloWin32";//应用程序名
HWNDhwnd;//窗口句柄
MSGmsg;//消息
WNDCLASSEXwndclass;//窗口类
wndclass.cbSize=sizeof(wndclass);//窗口类结构的大小
wndclass.style=CS_HREDRAW|CS_VREDRAW;//类风格:水平和垂直方向重画
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.lpszClassName
=szAppName;
wndclass.lpszMenuName
=NULL;
wndclass.hIconSm
=LoadIcon(NULL,IDI_APPLICATION);

RegisterClassEx(
&wndclass);

hwnd
=CreateWindow(szAppName,
"TheHelloApp",
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);
}


returnmsg.wParam;
}


<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

2//t1.h
classCMyApp:publicCWinApp
{
public:
virtualBOOLInitInstance();
}
;

classCMainWindow:publicCFrameWnd
{
public:
CMainWindow();
protected:
afx_msg
voidOnPaint();
afx_msg
voidOnLButtonDown(UINTnFlags,CPointpoint);
DECLARE_MESSAGE_MAP()
}
;

//t1.cpp
#include<afxwin.h>
#include
"t1.h"

CMyAppmyApp;

BOOLCMyApp::InitInstance()
{
this->m_pMainWnd=newCMainWindow;
this->m_pMainWnd->ShowWindow(this->m_nCmdShow);
this->m_pMainWnd->UpdateWindow();
returnTRUE;
}


BEGIN_MESSAGE_MAP(CMainWindow,CFrameWnd)
ON_WM_PAINT()
ON_WM_LBUTTONDOWN()
END_MESSAGE_MAP()

CMainWindow::CMainWindow()
{
Create(NULL,_T(
"TheMFCApplication"));
}


voidCMainWindow::OnPaint()
{
CPaintDCdc(
this);
CRectrect;
GetClientRect(
&rect);
dc.DrawText(
"WeclometoVC!!",-1,&rect,DT_SINGLELINE|DT_CENTER|DT_VCENTER);

}


voidCMainWindow::OnLButtonDown(UINTnFlags,CPointpoint)
{
CClientDCdc(
this);
CRectrect(point.x
-50,point.y-50,point.x+50,point.y+50);
dc.Ellipse(rect);
}
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics