游客已登陆 (0)未知
笔行证 257310
昵称 kuan 
笔贝 Score1
加为好友 发送短信
<< << 2009 一月 >> >>
123
45678910
11121314151617
18192021222324
25262728293031

访问计数:26967
本文:240 今天:1 本月 100

本地音乐播放器



 
       对_Windows应用程序的类封装_的修改
2007-06-28 晴



#include<windows.h>
#include<stdio.h>

//定义全局变量
HINSTANCE hInst;
HINSTANCE hInstance;

MSG msg;
char lpszClassName[]="窗口";
char *ShowText;

//函数声明
LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);



//------------------窗口类----------------------------------
class CFrameWnd
{
public:
HWND hWnd;
public:
int RegisterWindow();
void Create(LPCTSTR lpClassName,
LPCTSTR lpWindowName
);
void ShowWindow(int mCmdShow);
void UpdateWindow();
};

//窗口类的成员函数
int CFrameWnd::RegisterWindow()
{
WNDCLASS wc;
wc.style=0;
wc.lpfnWndProc=WndProc;
wc.cbClsExtra=0;
wc.cbWndExtra=0;
wc.hInstance=hInstance;
wc.hIcon=LoadIcon(NULL,IDI_APPLICATION);
wc.hCursor=LoadCursor(NULL,IDC_ARROW);
wc.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);
wc.lpszMenuName=NULL;
wc.lpszClassName=lpszClassName;
return RegisterClass(&wc);

}
void CFrameWnd::Create(LPCTSTR lpClassName,LPCTSTR lpWindowName)
{
RegisterWindow();
hInst=hInstance;
hWnd=CreateWindow(lpszClassName,
lpWindowName,
WS_OVERLAPPEDWINDOW,
120,50,800,600,
NULL,
NULL,
hInstance,
NULL);

}
void CFrameWnd::ShowWindow(int nCmdShow)
{
::ShowWindow(hWnd,nCmdShow);
}
void CFrameWnd::UpdateWindow()
{
::UpdateWindow(hWnd);
}




//-------------应用程序类----------------
//把主函数中的函数体看成一个对象,把它叫应用程序
class CWinApp
{
public:
CFrameWnd *m_pMainWnd;
public:
virtual BOOL InitInstance(int nCmdShow); //声明为虚函数---就改这里
int Run();
};


//应用程序成员函数
BOOL CWinApp::InitInstance(int nCmdShow)
{
m_pMainWnd= new CFrameWnd;
m_pMainWnd->Create(NULL,"封装的Windows程序");
m_pMainWnd->ShowWindow(nCmdShow);
m_pMainWnd->UpdateWindow();
return TRUE;
}
int CWinApp::Run()
{
while(GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}

//-------由CwinApp类派生CMyApp类,加了这个
class CMyApp: public CWinApp
{
public:
BOOL InitInstance(int nCmdShow); //重新定义InitInstance函数
};//注意分号

//重新定义的成员函数InitInstance.加了这个
CMyApp::InitInstance(int nCmdShow)
{
m_pMainWnd= new CFrameWnd;
m_pMainWnd->Create(NULL,"用新的InitInstance函数的程序");
m_pMainWnd->ShowWindow(nCmdShow);
m_pMainWnd->UpdateWindow();
return TRUE;
}


//CWinApp theApp;
//这里要改一下
CMyApp theApp;


//主函数______________________________________________________
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
int ResultCode=-1;
theApp.InitInstance(nCmdShow);
return ResultCode=theApp.Run();
}


//窗口函数--------------------------------------------

LRESULT CALLBACK WndProc(HWND hWnd,
UINT message,
WPARAM wParam,
LPARAM lParam)
{
PAINTSTRUCT ps;
HDC hdc;
switch(message)
{
case WM_LBUTTONDOWN:
ShowText="kuanlovefeng";
InvalidateRect(hWnd,NULL,1);
break;
case WM_PAINT:
hdc=BeginPaint(hWnd,&ps);
TextOut(hdc,50,50,ShowText,12);
EndPaint(hWnd,&ps);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd,message,wParam,lParam);

}
return 0;
}.
# posted by kuan @ 2007-06-28 13:30:52 评论(0)
 








 
笔 名:
*
评 论:
最多1000字。当前字数:0
*
联系方式: