UIBase.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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. #ifdef NDEBUG
  20. #define ASSERT(expr) ((void)0)
  21. #else /* NDEBUG */
  22. #ifndef ASSERT
  23. #define ASSERT(expr) _ASSERTE(expr)
  24. #endif
  25. #endif
  26. #ifdef _DEBUG
  27. #ifndef DUITRACE
  28. #define DUITRACE DUI__Trace
  29. #endif
  30. #define DUITRACEMSG DUI__TraceMsg
  31. #else
  32. #ifndef DUITRACE
  33. #define DUITRACE
  34. #endif
  35. #define DUITRACEMSG _T("")
  36. #endif
  37. void UILIB_API DUI__Trace(LPCTSTR pstrFormat, ...);
  38. void UILIB_API DUI__TraceMsg(UINT uMsg);
  39. /////////////////////////////////////////////////////////////////////////////////////
  40. //
  41. class UILIB_API CNotifyPump
  42. {
  43. public:
  44. bool AddVirtualWnd(CDuiString strName,CNotifyPump* pObject);
  45. bool RemoveVirtualWnd(CDuiString strName);
  46. void NotifyPump(TNotifyUI& msg);
  47. bool LoopDispatch(TNotifyUI& msg);
  48. DUI_DECLARE_MESSAGE_MAP()
  49. private:
  50. CStdStringPtrMap m_VirtualWndMap;
  51. };
  52. class UILIB_API CWindowWnd
  53. {
  54. public:
  55. CWindowWnd();
  56. HWND GetHWND() const;
  57. operator HWND() const;
  58. bool RegisterWindowClass();
  59. bool RegisterSuperclass();
  60. HWND Create(HWND hwndParent, LPCTSTR pstrName, DWORD dwStyle, DWORD dwExStyle, const RECT rc, HMENU hMenu = NULL);
  61. 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);
  62. HWND CreateDuiWindow(HWND hwndParent, LPCTSTR pstrWindowName,DWORD dwStyle =0, DWORD dwExStyle =0);
  63. HWND Subclass(HWND hWnd);
  64. void Unsubclass();
  65. void ShowWindow(bool bShow = true, bool bTakeFocus = true);
  66. UINT ShowModal();
  67. virtual void Close(UINT nRet = IDOK);
  68. void CenterWindow(); // ¾ÓÖУ¬Ö§³ÖÀ©Õ¹ÆÁÄ»
  69. void SetIcon(UINT nRes);
  70. LRESULT SendMessage(UINT uMsg, WPARAM wParam = 0, LPARAM lParam = 0L);
  71. LRESULT PostMessage(UINT uMsg, WPARAM wParam = 0, LPARAM lParam = 0L);
  72. void ResizeClient(int cx = -1, int cy = -1);
  73. protected:
  74. virtual LPCTSTR GetWindowClassName() const = 0;
  75. virtual LPCTSTR GetSuperClassName() const;
  76. virtual UINT GetClassStyle() const;
  77. virtual LRESULT HandleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam);
  78. virtual void OnFinalMessage(HWND hWnd);
  79. static LRESULT CALLBACK __WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
  80. static LRESULT CALLBACK __ControlProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
  81. protected:
  82. HWND m_hWnd;
  83. WNDPROC m_OldWndProc;
  84. bool m_bSubclassed;
  85. };
  86. } // namespace DuiLib
  87. #endif // __UIBASE_H__