安裝好vs和wtl開發環境後,就可以進行wtl開發了。
wtl提供了windows圖形界面開發架構,可以利用wtl開發出想要的windows圖形視窗界面程式。
首先我們簡單的建立一個wtl的程式,看看wtl的代碼邏輯和圖形界面是如何來搭建代碼積木的。
打開vs工具,
1、建立項目——>在已安裝——>Visual C++ ——>WTL
——> ATL/WT Application Wizard
名稱寫wtl_work,
Application Type選Dialog Based。
建好工程後,配置一下工程屬性,
給C/C++附加包含目錄:D:\WTL91_5270_Beta\Include
給資源附加包含目錄:D:\WTL91_5270_Beta\Include
建好工程後,wtl已經有了一個簡單的對話框視窗。
你可以編譯運作一下,
程式樣子如下圖:
![](https://img.laitimes.com/img/9ZDMuAjOiMmIsIjOiQnIsISMzEjN0cTNxEjNxETM1EDMy8CX0Vmbu4GZzNmLn9Gbi1yZtl2Lc9CX6MHc0RHaiojIsJye.jpg)
點選about,彈出對話框:
在vs工具解決方案資料總管裡檢視建立工程的包含檔案如下圖:
看看wtl_work.cpp代碼,
裡面包含兩個函數_tWinMain和Run。
int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE /*hPrevInstance*/, LPTSTR lpstrCmdLine, int nCmdShow)
{
HRESULT hRes = ::CoInitialize(NULL);
// If you are running on NT 4.0 or higher you can use the following call instead to
// make the EXE free threaded. This means that calls come in on a random RPC thread.
// HRESULT hRes = ::CoInitializeEx(NULL, COINIT_MULTITHREADED);
ATLASSERT(SUCCEEDED(hRes));
// this resolves ATL window thunking problem when Microsoft Layer for Unicode (MSLU) is used
::DefWindowProc(NULL, , , L);
AtlInitCommonControls(ICC_BAR_CLASSES); // add flags to support other controls
hRes = _Module.Init(NULL, hInstance);
ATLASSERT(SUCCEEDED(hRes));
int nRet = Run(lpstrCmdLine, nCmdShow);
_Module.Term();
::CoUninitialize();
return nRet;
}
int Run(LPTSTR /*lpstrCmdLine*/ = NULL, int nCmdShow = SW_SHOWDEFAULT)
{
CMessageLoop theLoop;
_Module.AddMessageLoop(&theLoop);
CMainDlg dlgMain;
if(dlgMain.Create(NULL) == NULL)
{
ATLTRACE(_T("Main dialog creation failed!\n"));
return ;
}
dlgMain.ShowWindow(nCmdShow);
int nRet = theLoop.Run();
_Module.RemoveMessageLoop();
return nRet;
}