程序框架
上面几篇文章大致介绍了下皮肤配置的情况,有个大概的了解,下面我会介绍下搭建程序的框架。
首先新建一个cpp文件,作为我们主程序的入口,里面必须的是入口函数:
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
if (!InitSkin(hInstance))//初始化皮肤的函数,后面会讲解
goto endapp;
//实例化两个窗口,这里的两个窗口类后面会讲解他们的来历
g_pMainWnd = new CUMFCMainWindow(_T("UMFCMainWindow"));
g_pLoginWnd = new CUMFCLoginWindow(_T("UMFCLoginWindow"));
//下面代码是创建windows窗口
RECT rcMain = {0,0,800,600};
HWND hWnd = g_pMainWnd->Create(NULL, ST_STR(11), (WS_POPUP| WS_SYSMENU|WS_MAXIMIZEBOX|WS_MINIMIZEBOX|WS_CLIPCHILDREN) , 0, rcMain );
if (!hWnd || !IsWindow(hWnd))
goto endapp;
g_pMainWnd->CenterWindow();
if (!InitFtpClient(hWnd))
goto endapp;
RECT rcLogin = {0,0,400,300};
hWnd = g_pLoginWnd->Create(NULL, ST_STR(21), (WS_POPUP|WS_VISIBLE|WS_SYSMENU|WS_MAXIMIZEBOX|WS_MINIMIZEBOX|WS_CLIPCHILDREN) , WS_EX_TOPMOST, rcLogin );
if (!hWnd || !IsWindow(hWnd))
goto endapp;
//消息循环
MSG msg = { 0 };
while( ::GetMessage(&msg, NULL, 0, 0) )
{
::TranslateMessage(&msg);
::DispatchMessage(&msg);
}
//清理工作
endapp:
SAFE_RELEASE_OBJ(g_pMainWnd);
SAFE_RELEASE_OBJ(g_pLoginWnd);
return static_cast<int>(msg.wParam);
{
if (!InitSkin(hInstance))//初始化皮肤的函数,后面会讲解
goto endapp;
//实例化两个窗口,这里的两个窗口类后面会讲解他们的来历
g_pMainWnd = new CUMFCMainWindow(_T("UMFCMainWindow"));
g_pLoginWnd = new CUMFCLoginWindow(_T("UMFCLoginWindow"));
//下面代码是创建windows窗口
RECT rcMain = {0,0,800,600};
HWND hWnd = g_pMainWnd->Create(NULL, ST_STR(11), (WS_POPUP| WS_SYSMENU|WS_MAXIMIZEBOX|WS_MINIMIZEBOX|WS_CLIPCHILDREN) , 0, rcMain );
if (!hWnd || !IsWindow(hWnd))
goto endapp;
g_pMainWnd->CenterWindow();
if (!InitFtpClient(hWnd))
goto endapp;
RECT rcLogin = {0,0,400,300};
hWnd = g_pLoginWnd->Create(NULL, ST_STR(21), (WS_POPUP|WS_VISIBLE|WS_SYSMENU|WS_MAXIMIZEBOX|WS_MINIMIZEBOX|WS_CLIPCHILDREN) , WS_EX_TOPMOST, rcLogin );
if (!hWnd || !IsWindow(hWnd))
goto endapp;
//消息循环
MSG msg = { 0 };
while( ::GetMessage(&msg, NULL, 0, 0) )
{
::TranslateMessage(&msg);
::DispatchMessage(&msg);
}
//清理工作
endapp:
SAFE_RELEASE_OBJ(g_pMainWnd);
SAFE_RELEASE_OBJ(g_pLoginWnd);
return static_cast<int>(msg.wParam);
}
上面入口函数还是满简单的,下面我们来看一下 InitSkin初始化皮肤:
bool InitSkin(HINSTANCE hInstance)
{
G_UIMAN.SetAppInstance(hInstance);//设置应用程序实例句柄
TCHAR pszCurDir[MAX_PATH] = {0};
::GetCurrentDirectory(MAX_PATH, pszCurDir);
tstring strStrTable = pszCurDir;
tstring strSkinPath = pszCurDir;
tstring strXmlFile = pszCurDir;
strStrTable += _T("\\Language\\simplechinese.ch");//字符串数据表的文件路径,以后会讲如何更换语言
strSkinPath += _T("\\Skin\\"); //皮肤文件(图片文件或者打包后的包文件)路径
strXmlFile += _T("\\Skin\\skin.xml");//皮肤配置文件路径
if (!G_STRTABLE.Init(strStrTable.c_str()))//初始化字符串表
{
return false;
}
//皮肤初始化
G_UIMAN
就是
#define G_UIMAN g_ultrantUIManager
if (!G_UIMAN.Init(strSkinPath.c_str(), strXmlFile.c_str()))
{
return false;
}
return true;
}
{
G_UIMAN.SetAppInstance(hInstance);//设置应用程序实例句柄
TCHAR pszCurDir[MAX_PATH] = {0};
::GetCurrentDirectory(MAX_PATH, pszCurDir);
tstring strStrTable = pszCurDir;
tstring strSkinPath = pszCurDir;
tstring strXmlFile = pszCurDir;
strStrTable += _T("\\Language\\simplechinese.ch");//字符串数据表的文件路径,以后会讲如何更换语言
strSkinPath += _T("\\Skin\\"); //皮肤文件(图片文件或者打包后的包文件)路径
strXmlFile += _T("\\Skin\\skin.xml");//皮肤配置文件路径
if (!G_STRTABLE.Init(strStrTable.c_str()))//初始化字符串表
{
return false;
}
//皮肤初始化
G_UIMAN
就是
#define G_UIMAN g_ultrantUIManager
if (!G_UIMAN.Init(strSkinPath.c_str(), strXmlFile.c_str()))
{
return false;
}
return true;
}
这样主程序部分就ok了,是不是很简单,明天会接着讲解上面那两个窗口类的来历,等把基本程序框架讲解完(包括事件映射和处理)