今天开始学习VC++,照着书上写了几个Win32的程序。
LRESULT CALLBACK WndProc(HWND hwnd, UINT iMsg, WPARAM wParam,LPARAM lParam)
hdc = BeginPaint(hwnd,&ps);
GetClientRect(hwnd,&rect);
DrawText(hdc,"Hello,VC6.0!",-1,&rect,DT_SINGLELINE|DT_CENTER|DT_VCENTER);
point.x = LOWORD(lParam);
point.y = HIWORD(lParam);
Ellipse(hdc,point.x-50,point.y-50,point.x+50,point.y+50);
return DefWindowProc(hwnd,iMsg,wParam,lParam);
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nShowCmd)
static char szAppName[] = "HelloWin32";//应用程序名
WNDCLASSEX wndclass;//窗口类
wndclass.cbSize = sizeof(wndclass);//窗口类结构的大小
wndclass.style = CS_HREDRAW|CS_VREDRAW;//类风格:水平和垂直方向重画
wndclass.lpfnWndProc = WndProc;//窗口过程
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,
ShowWindow(hwnd,nShowCmd);
while(GetMessage(&msg,NULL,0,0))
class CMyApp:public CWinApp
virtual BOOL InitInstance();
class CMainWindow:public CFrameWnd
afx_msg void OnLButtonDown(UINT nFlags,CPoint point);
BOOL CMyApp::InitInstance()
this->m_pMainWnd = new CMainWindow;
this->m_pMainWnd->ShowWindow(this->m_nCmdShow);
this->m_pMainWnd->UpdateWindow();
BEGIN_MESSAGE_MAP(CMainWindow,CFrameWnd)
CMainWindow::CMainWindow()
Create(NULL,_T("The MFC Application"));
void CMainWindow::OnPaint()
dc.DrawText("Weclome to VC!!",-1,&rect,DT_SINGLELINE|DT_CENTER|DT_VCENTER);
void CMainWindow::OnLButtonDown(UINT nFlags,CPoint point)
CRect rect(point.x-50,point.y-50,point.x+50,point.y+50);
本文转自Phinecos(洞庭散人)博客园博客,原文链接:http://www.cnblogs.com/phinecos/archive/2007/03/30/694562.html,如需转载请自行联系原作者