UIBase.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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 DUILIB_API DUI__Trace(LPCTSTR pstrFormat, ...);
  34. LPCTSTR DUILIB_API DUI__TraceMsg(UINT uMsg);
  35. /////////////////////////////////////////////////////////////////////////////////////
  36. //
  37. class DUILIB_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. CDuiStringPtrMap m_VirtualWndMap;
  47. };
  48. class DUILIB_API CWindowWnd
  49. {
  50. public:
  51. CWindowWnd();
  52. HWND GetHWND() const;
  53. operator HWND() const;
  54. bool RegisterWindowClass();
  55. bool RegisterSuperclass();
  56. HWND Create(HWND hwndParent, LPCTSTR pstrName, DWORD dwStyle, DWORD dwExStyle, const RECT rc, HMENU hMenu = NULL);
  57. 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);
  58. HWND CreateDuiWindow(HWND hwndParent, LPCTSTR pstrWindowName,DWORD dwStyle =0, DWORD dwExStyle =0);
  59. HWND Subclass(HWND hWnd);
  60. void Unsubclass();
  61. void ShowWindow(bool bShow = true, bool bTakeFocus = true);
  62. UINT ShowModal();
  63. void Close(UINT nRet = IDOK);
  64. void CenterWindow(); // ¾ÓÖУ¬Ö§³ÖÀ©Õ¹ÆÁÄ»
  65. void SetIcon(UINT nRes);
  66. LRESULT SendMessage(UINT uMsg, WPARAM wParam = 0, LPARAM lParam = 0L);
  67. LRESULT PostMessage(UINT uMsg, WPARAM wParam = 0, LPARAM lParam = 0L);
  68. void ResizeClient(int cx = -1, int cy = -1);
  69. protected:
  70. virtual LPCTSTR GetWindowClassName() const = 0;
  71. virtual LPCTSTR GetSuperClassName() const;
  72. virtual UINT GetClassStyle() const;
  73. virtual LRESULT HandleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam);
  74. virtual void OnFinalMessage(HWND hWnd);
  75. static LRESULT CALLBACK __WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
  76. static LRESULT CALLBACK __ControlProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
  77. protected:
  78. HWND m_hWnd;
  79. WNDPROC m_OldWndProc;
  80. bool m_bSubclassed;
  81. };
  82. } // namespace DuiLib
  83. #endif // __UIBASE_H__