UIBase.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. #ifndef __UIBASE_H__
  2. #define __UIBASE_H__
  3. #pragma once
  4. namespace DuiLib {
  5. /////////////////////////////////////////////////////////////////////////////////////
  6. //
  7. #define UI_WNDSTYLE_CONTAINER (0)
  8. #define UI_WNDSTYLE_FRAME (WS_VISIBLE | WS_OVERLAPPEDWINDOW)
  9. #define UI_WNDSTYLE_CHILD (WS_VISIBLE | WS_CHILD | WS_CLIPSIBLINGS | WS_CLIPCHILDREN)
  10. #define UI_WNDSTYLE_DIALOG (WS_VISIBLE | WS_POPUPWINDOW | WS_CAPTION | WS_DLGFRAME | WS_CLIPSIBLINGS | WS_CLIPCHILDREN)
  11. #define UI_WNDSTYLE_EX_FRAME (WS_EX_WINDOWEDGE)
  12. #define UI_WNDSTYLE_EX_DIALOG (WS_EX_TOOLWINDOW | WS_EX_DLGMODALFRAME)
  13. #define UI_CLASSSTYLE_CONTAINER (0)
  14. #define UI_CLASSSTYLE_FRAME (CS_VREDRAW | CS_HREDRAW)
  15. #define UI_CLASSSTYLE_CHILD (CS_VREDRAW | CS_HREDRAW | CS_DBLCLKS | CS_SAVEBITS)
  16. #define UI_CLASSSTYLE_DIALOG (CS_VREDRAW | CS_HREDRAW | CS_DBLCLKS | CS_SAVEBITS)
  17. /////////////////////////////////////////////////////////////////////////////////////
  18. //
  19. #ifndef ASSERT
  20. #define ASSERT(expr) _ASSERTE(expr)
  21. #endif
  22. #ifdef _DEBUG
  23. #ifndef DUITRACE
  24. #define DUITRACE DUI__Trace
  25. #endif
  26. #define DUITRACEMSG DUI__TraceMsg
  27. #else
  28. #ifndef DUITRACE
  29. #define DUITRACE
  30. #endif
  31. #define DUITRACEMSG _T("")
  32. #endif
  33. void UILIB_API DUI__Trace(LPCTSTR pstrFormat, ...);
  34. LPCTSTR UILIB_API DUI__TraceMsg(UINT uMsg);
  35. /////////////////////////////////////////////////////////////////////////////////////
  36. //
  37. class UILIB_API CNotifyPump
  38. {
  39. public:
  40. bool AddVirtualWnd(CDuiString strName,CNotifyPump* pObject);
  41. bool RemoveVirtualWnd(CDuiString strName);
  42. void NotifyPump(TNotifyUI& msg);
  43. bool LoopDispatch(TNotifyUI& msg);
  44. DUI_DECLARE_MESSAGE_MAP()
  45. private:
  46. CStdStringPtrMap m_VirtualWndMap;
  47. };
  48. class UILIB_API CWindowWnd
  49. {
  50. public:
  51. CWindowWnd();
  52. HWND GetHWND() const;
  53. operator HWND() const;
  54. void EnableUnicode();
  55. bool RegisterWindowClass();
  56. bool RegisterSuperclass();
  57. HWND Create(HWND hwndParent, LPCTSTR pstrName, DWORD dwStyle, DWORD dwExStyle, const RECT rc, HMENU hMenu = NULL);
  58. HWND Create(HWND hwndParent, LPCTSTR pstrName, DWORD dwStyle, DWORD dwExStyle, int x = CW_USEDEFAULT, int y = CW_USEDEFAULT, int cx = CW_USEDEFAULT, int cy = CW_USEDEFAULT, HMENU hMenu = NULL);
  59. HWND CreateDuiWindow(HWND hwndParent, LPCTSTR pstrWindowName,DWORD dwStyle =0, DWORD dwExStyle =0);
  60. HWND Subclass(HWND hWnd);
  61. void Unsubclass();
  62. void ShowWindow(bool bShow = true, bool bTakeFocus = true);
  63. UINT ShowModal();
  64. void ShowModalFake();
  65. void Close(UINT nRet = IDOK);
  66. void CenterWindow(); // ¾ÓÖУ¬Ö§³ÖÀ©Õ¹ÆÁÄ»
  67. void SetIcon(UINT nRes);
  68. LRESULT SendMessage(UINT uMsg, WPARAM wParam = 0, LPARAM lParam = 0L);
  69. LRESULT PostMessage(UINT uMsg, WPARAM wParam = 0, LPARAM lParam = 0L);
  70. void ResizeClient(int cx = -1, int cy = -1);
  71. protected:
  72. virtual LPCTSTR GetWindowClassName() const = 0;
  73. virtual LPCTSTR GetSuperClassName() const;
  74. virtual UINT GetClassStyle() const;
  75. virtual LRESULT HandleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam);
  76. virtual void OnFinalMessage(HWND hWnd);
  77. static LRESULT CALLBACK __WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
  78. static LRESULT CALLBACK __ControlProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
  79. protected:
  80. HWND m_hWnd;
  81. WNDPROC m_OldWndProc;
  82. bool m_bSubclassed;
  83. bool m_bUnicode;
  84. bool m_bFakeModal;
  85. };
  86. } // namespace DuiLib
  87. #endif // __UIBASE_H__