duilib duilib introductory tutorial simple tutorial 3. The first Hello World program

Little friends can not wait yet, take a look at it Hello World: A new space win32 project, create a main.cpp file, copy the following code into it:

  1. #include <windows.h>
  2. #include <tchar.h>
  3. int APIENTRY _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow)
  4. {
  5.     ::MessageBox(NULL, _T("Hello World !"), NULL, NULL);
  6.     return 0;
  7. }
Copy the code




    Run to see the following results:
     

    Hey, this is not a win32 program it, you fooled me kid?
    ~ O (∩_∩) O ~ This is Alberl want to say: duilib just a win32-based UI library only, not with the duilib later, it is not a win32 program.
Ask how many small partners Gato plate, add program icons and so on, you may feel duilib should provide as many as MFC classes packaged in the group; or feel duilib achieve functional tray; or feel duilib completely replace the win32 and MFC . So here under Alberl reminder: duilib did not like the MFC did all the things the whole package, it just wraps the UI part of it, others still need to use win32, MFC's knowledge, so in addition to the UI part, the other and duilib wood relationship, small partners to directly search the keyword windows on the line.
    Again: the duilib as a class library with, rather than a language, IDE, framework ~ (^ o ^) / ~

    Let's take a look at duilib of Hello World.
( Note:
1, this tutorial using duilib latest code, does not download the latest code, please read the [ 2013 duilib Concise Guide to Getting Started - VS environment configuration (2) ]
2, a compilation error, indicating that the configuration has not the environment, read the [ 2013 duilib concise Guide to Getting Started - VS environment configuration (2) ]
3, in view of the back of many users have a variety of small problems, it is recommended that you first download the entire source code tutorial , download Come [2013 duilib Concise Guide to Getting Started - Summary (20) ]
)   

  1. #pragma once
  2. #include <UIlib.h>
  3. using namespace DuiLib;
  4. #ifdef _DEBUG
  5. #   ifdef _UNICODE
  6. #       pragma comment(lib, "DuiLib_ud.lib")
  7. #   else
  8. #       pragma comment(lib, "DuiLib_d.lib")
  9. #   endif
  10. #else
  11. #   ifdef _UNICODE
  12. #       pragma comment(lib, "DuiLib_u.lib")
  13. #   else
  14. #       pragma comment(lib, "DuiLib.lib")
  15. #   endif
  16. #endif
  17. class CDuiFrameWnd : public CWindowWnd, public INotifyUI
  18. {
  19. public:
  20.     virtual LPCTSTR GetWindowClassName() const { return _T("DUIMainFrame"); }
  21.     virtual void    Notify(TNotifyUI& msg) {}
  22.     virtual LRESULT HandleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam)
  23.     {
  24.         LRESULT lRes = 0;
  25.         if( uMsg == WM_CREATE ) 
  26.         {
  27.             CControlUI *pWnd = new CButtonUI;
  28.             pWnd-> SetText (_T ( "Hello World")); // set the text
  29.             pWnd-> SetBkColor (0xFF00FF00); // set the background color
  30.             m_PaintManager.Init(m_hWnd);
  31.             m_PaintManager.AttachDialog(pWnd);
  32.             return lRes;
  33.         }
  34.         if( m_PaintManager.MessageHandler(uMsg, wParam, lParam, lRes) ) 
  35.         {
  36.             return lRes;
  37.         }
  38.         return __super::HandleMessage(uMsg, wParam, lParam);
  39.     }
  40. protected:
  41.     CPaintManagerUI m_PaintManager;
  42. };
  43. int APIENTRY _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow)
  44. {
  45.     CPaintManagerUI::SetInstance(hInstance);
  46.     CDuiFrameWnd duiFrame;
  47.     duiFrame.Create(NULL, _T("DUIWnd"), UI_WNDSTYLE_FRAME, WS_EX_WINDOWEDGE);
  48.     duiFrame.ShowModal();
  49.     return 0;
  50. }
Copy the code




    


    A Hello World is complete, it is not very simple ^ _ ^
    PS: In addition to the above code displays the text beyond, has the following characteristics:
    1, the mouse moves over the client area (the green part), the mouse turns into a hand-type style
    2, when the window is resized and maximized, Hello World will be adaptive window size, it has been centered
    3, if you want to change the background color, then a direct call SetBkColor on the line, is not better than win32 and MFC easy to do ~ (^ o ^ ) / ~

Guess you like

Origin www.cnblogs.com/blogpro/p/11427036.html