WTL-A basic WTL application

1.包含常用头文件和宏定义,用于简化WTL程序编写的自定义头文件:WTLHelper.h
隐藏行号 复制代码 这是一段程序代码。
  1. //WTLHelper.h
  2. #pragma once
  3. #define WINVER 0x0601           //win7
  4. #define _WIN32_WINNT 0x0601     //win7
  5. #define _WIN32_IE 0x0800        //IE 8.0
  6. #define _RICHEDIT_VER 0x0300
  7. #define _WTL_USE_CSTRING    //use CString class in WTL
  8. //ATL header files
  9. #include 
          
          
  10. #include 
          
          
  11. //WTL header files
  12. #include 
          
               
          
          //CWindowImpl
  13. #include 
          
             
          
          //BEGIN_MSG_MAP_EX, message crack
  14. #include 
          
              
          
          //CString, CRect, CSize
  15. #ifndef WTLHELPER_NOT_USE_COMMON_CONTROL_STYLE
  16. #if defined _M_IX86
  17. #pragma comment(linker, "/manifestdependency:/"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='x86' publicKeyToken='6595b64144ccf1df' language='*'/"")
  18. #elif defined _M_IA64
  19. #pragma comment(linker, "/manifestdependency:/"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='ia64' publicKeyToken='6595b64144ccf1df' language='*'/"")
  20. #elif defined _M_X64
  21. #pragma comment(linker, "/manifestdependency:/"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='amd64' publicKeyToken='6595b64144ccf1df' language='*'/"")
  22. #else
  23. #pragma comment(linker, "/manifestdependency:/"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'/"")
  24. #endif
  25. #endif // WTL_NOT_ADD_COMMON_CONTROL_MENIFEST
  26. #ifndef ATLASSERTHR
  27. #define ATLASSERTHR(hr) ATLASSERT(SUCCEEDED((hr)))
  28. #endif  // ATLASSERTHR
<script language="javascript"> function CopyCode(key){var codeElement=null;var trElements=document.all.tags("ol");var i;for(i=0;i 2.预编译头文件:stdafx.h
隐藏行号 复制代码 这是一段程序代码。
  1. //stdafx.h
    
  2. #pragma once
    
  3. #include "WTLHelper.h"
    
  4. 
    
  5. extern CAppModule g_AppModule;
    
<script language="javascript"> function CopyCode(key){var codeElement=null;var trElements=document.all.tags("ol");var i;for(i=0;i  

3.主窗口定义:MainWindow.h
隐藏行号 复制代码 这是一段程序代码。
  1. //MainWindow.h
    
  2. #pragma once
    
  3. #include "stdafx.h"
    
  4. 
    
  5. typedef CWinTraits<WS_OVERLAPPEDWINDOW> CMainWinTraits;
    
  6. class CMainWindow :
    
  7.     public CWindowImpl<CMainWindow, CWindow, CMainWinTraits>
    
  8. {
    
  9. public:
    
  10.     DECLARE_WND_CLASS(_T("Basic_Main_Window"))
    
  11.     BEGIN_MSG_MAP_EX(CMainWindow)
    
  12.         MSG_WM_CREATE(OnCreate)
    
  13.         MSG_WM_DESTROY(OnDestroy)
    
  14.         MSG_WM_PAINT(OnPaint)
    
  15.         MSG_WM_LBUTTONDOWN(OnLButtonDown)
    
  16.     END_MSG_MAP()
    
  17. public:
    
  18.     CMainWindow()
    
  19.     {
    
  20.         CWndClassInfo& wci = GetWndClassInfo();
    
  21.         if(!wci.m_atom)    // The window class has not been register yet
    
  22.         {
    
  23.             //Set the background brush of the window class
    
  24.             wci.m_wc.hbrBackground = AtlGetStockBrush(GRAY_BRUSH);
    
  25.         }
    
  26.     }
    
  27.     int OnCreate(LPCREATESTRUCT /*lpCreateStruct*/)
    
  28.     {
    
  29.         //Create font to draw text in the client window
    
  30.         CLogFont logFont;
    
  31.         TCHAR fontName[] = _T("Arial");
    
  32.         _tcscpy_s(logFont.lfFaceName, fontName);
    
  33.         logFont.lfHeight    = 60;
    
  34.         logFont.lfItalic    = TRUE;
    
  35.         logFont.lfWeight    = FW_BOLD;
    
  36.         logFont.lfStrikeOut    = TRUE;
    
  37.         m_FontText.CreateFontIndirect(&logFont);
    
  38.         return 0;
    
  39.     }
    
  40.     void OnDestroy()
    
  41.     {
    
  42.         PostQuitMessage(0);
    
  43.     }
    
  44.     void OnPaint(CDCHandle)
    
  45.     {
    
  46.         CPaintDC dc(m_hWnd);
    
  47.         //Do painting work here
    
  48.         CRect rc;
    
  49.         GetClientRect(&rc);
    
  50.         dc.SaveDC();
    
  51.         dc.SelectFont(m_FontText);
    
  52.         LPCTSTR lpText = _T("A basic WTL application.");
    
  53.         dc.DrawText(lpText, -1, &rc, DT_CENTER|DT_VCENTER| DT_SINGLELINE);
    
  54.         dc.RestoreDC(-1);
    
  55.     }
    
  56.     void OnLButtonDown(UINT nFlags, CPoint point)
    
  57.     {
    
  58.         MessageBox(_T("left button down!"),_T("Main window message"), MB_OK|MB_ICONINFORMATION);
    
  59.     }
    
  60. private:
    
  61.     CFont m_FontText;
    
  62. };
    
<script language="javascript"> function CopyCode(key){var codeElement=null;var trElements=document.all.tags("ol");var i;for(i=0;i  

4.主程序文件:BasicApp.cpp

 

隐藏行号 复制代码 这是一段程序代码。
  1. #include "stdafx.h"
    
  2. #include "main.h"
    
  3. 
    
  4. CAppModule g_AppModule;
    
  5. int Run(int nShowCmd)
    
  6. {
    
  7.     CMessageLoop msgLoop;
    
  8.     g_AppModule.AddMessageLoop(&msgLoop);
    
  9.     CMainWindow mainWnd;
    
  10.     mainWnd.Create(NULL, NULL, _T("WTL main window"));
    
  11.     mainWnd.ShowWindow(nShowCmd);
    
  12.     mainWnd.CenterWindow();
    
  13.     //Start message loop
    
  14.     int result = msgLoop.Run();
    
  15.     g_AppModule.RemoveMessageLoop();
    
  16.     return result;
    
  17. }
    
  18. int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE pPrevInstance, LPSTR lpCmdLine, int nShowCmd)
    
  19. {
    
  20.     HRESULT hr = g_AppModule.Init(NULL, hInstance);
    
  21.     ATLASSERTHR(hr);
    
  22.     int result = Run(nShowCmd);
    
  23.     g_AppModule.Term();
    
  24.     return result;
    
  25. }
    
<script language="javascript"> function CopyCode(key){var codeElement=null;var trElements=document.all.tags("ol");var i;for(i=0;i
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值