8#include "HitTestResult.h"
9#include "IComparable.h"
12#include "ObservableObject.h"
33 using SimpleAction = Action<>;
52 const uint32_t _check;
82 bool _focused =
false;
87 bool _isDestroyed =
false;
92 bool _isControl =
false;
97 WNDPROC _originalWndProc = NULL;
270 void InitWindow(LPCWSTR lpWindowName, DWORD dwStyle, DWORD dwExStyle);
275 void InitControl(LPCWSTR lpClassName, LPCWSTR lpWindowName, DWORD dwStyle, DWORD dwExStyle, LPVOID lpParam = NULL);
595 virtual bool OnSetCursor(HWND hwnd, HitTestResult hitTest,
int message,
bool &result);
621 virtual bool OnNotify(NMHDR *pNMHDR, LRESULT &result);
669 virtual bool OnColor(HDC hdc, HBRUSH &hRetBrush);
764 void Redraw(
bool erase =
false,
bool updateWindow =
false);
901 static LRESULT CALLBACK _WndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
906 static WndBase *_GetControlInitContainer();
911 static int _NextControlId();
918 static void _SetWndBase(HWND hwnd,
WndBase &wnd);
926 template <
typename TDerived,
typename TProperty>
928 -> typename std::enable_if<
930 typename TProperty::TValue>::type
933 return getter(*
this);
941 template <
typename TDerived,
typename TProperty>
942 auto SetProperty(TProperty TDerived::*prop, typename TProperty::TSetterParam value)
943 -> typename std::enable_if<
947 setter(*
this, std::forward<typename TProperty::TSetterParam>(value));
控件
Definition Control.h:12
将Win32 window包装为SimpleWindow对象
Definition HwndWrapper.h:12
相等性比较接口
Definition IComparable.h:14
为支持ToString方法的类提供统一接口
Definition IToString.h:13
可观察对象基类,实现属性更改通知功能
Definition ObservableObject.h:14
属性
Definition Property.h:1743
只读属性
Definition Property.h:1828
static auto GetPropertySetter(TProperty T::*prop) -> typename std::enable_if< std::is_base_of< DynamicObject, T >::value &&_IsWritableProperty< TProperty >::value, Delegate< void(DynamicObject &, typename TProperty::TSetterParam)> >::type
获取属性的Setter委托
Definition Reflection.h:354
static auto GetPropertyGetter(TProperty T::*prop) -> typename std::enable_if< std::is_base_of< DynamicObject, T >::value &&_IsReadableProperty< TProperty >::value, Delegate< typename TProperty::TValue(DynamicObject &)> >::type
获取属性的Getter委托
Definition Reflection.h:318
表示界面中的元素
Definition UIElement.h:90
表示一个Windows窗口,是所有窗口和控件的基类
Definition WndBase.h:41
const ReadOnlyProperty< sw::Rect > ClientRect
用户区尺寸
Definition WndBase.h:153
virtual bool OnPaint()
接收到WM_PAINT时调用该函数
void SetExtendedStyle(DWORD mask, bool value)
打开或关闭指定的扩展样式
void SetExtendedStyle(DWORD style)
设置扩展窗口样式
bool CheckAccess(const WndBase &other) const
判断当前对象所属线程是否与另一个WndBase对象所属线程相同
virtual bool OnMouseWheel(int wheelDelta, const Point &mousePosition, MouseKey keyState)
接收到WM_MOUSEWHEEL时调用该函数
virtual bool OnClose()
接收到WM_CLOSE时调用该函数
virtual bool OnMenuSelect(HMENU hMenu, int id, int flags)
接收到WM_MENUSELECT后调用该函数
bool Equals(const WndBase &other) const
判断当前对象与另一个WndBase是否相等
virtual bool OnMeasureItemSelf(MEASUREITEMSTRUCT *pMeasure)
父窗口接收到WM_MEASUREITEM后且父窗口OnMeasureItem函数返回false时调用发出通知控件的该函数
virtual void OnNcHitTest(const Point &testPoint, HitTestResult &result)
接收到WM_NCHITTEST后调用该函数
virtual bool OnMouseRightButtonDown(const Point &mousePosition, MouseKey keyState)
接收到WM_RBUTTONDOWN时调用该函数
virtual bool OnSysKeyDown(VirtualKey key, const KeyFlags &flags)
接收到WM_SYSKEYDOWN时调用该函数
static bool IsPtrValid(const WndBase *ptr) noexcept
检查指针是否指向有效的WndBase对象
virtual void SetInternalText(const std::wstring &value)
修改窗口文本,该函数默认实现为调用SetWindowTextW
virtual LRESULT WndProc(ProcMsg &refMsg)
对WndProc的封装
Point PointToScreen(const Point &point) const
获取用户区点在屏幕上点的位置
bool GetExtendedStyle(DWORD mask)
判断窗口是否设有指定扩展样式
virtual Window * ToWindow()
尝试将对象转换成Window
HFONT GetFontHandle()
获取字体句柄
LRESULT SendMessageA(UINT uMsg, WPARAM wParam, LPARAM lParam)
发送消息(ASCII)
void SetStyle(DWORD mask, bool value)
打开或关闭指定的样式
bool CheckAccess() const
判断当前线程是否为窗口所属线程
void Invoke(const SimpleAction &action)
在窗口线程上执行指定委托
const ReadOnlyProperty< std::wstring > ClassName
窗口类名
Definition WndBase.h:208
virtual bool OnMouseRightButtonUp(const Point &mousePosition, MouseKey keyState)
接收到WM_RBUTTONUP时调用该函数
const ReadOnlyProperty< double > ClientHeight
用户区高度
Definition WndBase.h:163
const Property< bool > AcceptFiles
是否接受拖放文件
Definition WndBase.h:198
virtual bool OnMouseLeftButtonDown(const Point &mousePosition, MouseKey keyState)
接收到WM_LBUTTONDOWN时调用该函数
const Property< double > Width
宽度
Definition WndBase.h:143
Point PointFromScreen(const Point &screenPoint) const
获取屏幕上点在当前用户区点的位置
virtual bool OnMouseLeftButtonUp(const Point &mousePosition, MouseKey keyState)
接收到WM_LBUTTONUP时调用该函数
void InitWindow(LPCWSTR lpWindowName, DWORD dwStyle, DWORD dwExStyle)
初始化为窗口,该函数会调用CreateWindowExW
BOOL PostMessageA(UINT uMsg, WPARAM wParam, LPARAM lParam)
发送消息(ASCII)并立即返回
virtual bool OnSetFocus(HWND hPrevFocus)
接收到WM_SETFOCUS时调用该函数
virtual void HandleInitialized(HWND hwnd)
窗口句柄初始化完成
const ReadOnlyProperty< bool > IsControl
当前对象是否是控件
Definition WndBase.h:203
virtual void ParentChanged(WndBase *newParent)
父窗口改变时调用此函数
virtual void OnEndNcPaint()
在OnNcPaint函数完成之后调用该函数
virtual bool OnMeasureItem(int id, MEASUREITEMSTRUCT *pMeasure)
接收到WM_MEASUREITEM时调用该函数
const Property< double > Left
左边
Definition WndBase.h:133
const Property< sw::FontWeight > FontWeight
字体粗细
Definition WndBase.h:123
virtual bool OnSysKeyUp(VirtualKey key, const KeyFlags &flags)
接收到WM_SYSKEYUP时调用该函数
const Property< double > Height
高度
Definition WndBase.h:148
const Property< sw::Font > Font
字体
Definition WndBase.h:108
virtual bool OnNcPaint(HRGN hRgn)
接收到WM_NCPAINT时调用该函数
const ReadOnlyProperty< bool > IsDestroyed
是否已销毁,当该值为true时不应该继续使用当前对象
Definition WndBase.h:193
virtual bool OnMouseMiddleButtonDown(const Point &mousePosition, MouseKey keyState)
接收到WM_MBUTTONDOWN时调用该函数
virtual bool OnKeyUp(VirtualKey key, const KeyFlags &flags)
接收到WM_KEYUP时调用该函数
const Property< bool > IsGroupStart
窗口是否为一组控件中的第一个控件
Definition WndBase.h:214
virtual bool SetParent(WndBase *parent)
设置父窗口
virtual bool OnNotified(NMHDR *pNMHDR, LRESULT &result)
父窗口接收到WM_NOTIFY后且父窗口OnNotify函数返回false时调用发出通知控件的该函数
virtual void OnCommand(int code)
当父窗口接收到控件的WM_COMMAND时调用该函数
virtual bool OnChar(wchar_t ch, const KeyFlags &flags)
接收到WM_CHAR时调用该函数
auto GetProperty(TProperty TDerived::*prop) -> typename std::enable_if< std::is_base_of< WndBase, TDerived >::value &&_IsReadableProperty< TProperty >::value, typename TProperty::TValue >::type
获取属性值
Definition WndBase.h:927
virtual bool OnSysChar(wchar_t ch, const KeyFlags &flags)
接收到WM_SYSCHAR时调用该函数
const ReadOnlyProperty< bool > IsMouseCaptured
鼠标是否被当前窗口捕获
Definition WndBase.h:219
virtual std::wstring & GetInternalText()
获取内部记录窗口文本的字符串引用
virtual void OnControlCommand(WndBase *pControl, int code, int id)
当WM_COMMAND接收到控件命令时调用该函数
virtual bool OnMouseRightButtonDoubleClick(const Point &mousePosition, MouseKey keyState)
接收到WM_RBUTTONDBLCLK时调用该函数
void Redraw(bool erase=false, bool updateWindow=false)
重画
virtual ~WndBase()=0
析构函数,这里用纯虚函数使该类成为抽象类
const Property< double > Top
顶边
Definition WndBase.h:138
virtual bool OnKillFocus(HWND hNextFocus)
接收到WM_KILLFOCUS时调用该函数
virtual bool OnDrawItem(int id, DRAWITEMSTRUCT *pDrawItem)
接收到WM_DRAWITEM时调用该函数
const Property< bool > Focused
窗口是否拥有焦点
Definition WndBase.h:183
virtual bool OnVerticalScroll(int event, int pos)
接收到WM_VSCROLL时调用目标控件的该函数
const Property< std::wstring > FontName
字体名称
Definition WndBase.h:113
virtual bool OnEnabledChanged(bool newValue)
接收到WM_ENABLE时调用该函数
const Property< sw::Rect > Rect
位置和尺寸
Definition WndBase.h:128
virtual bool OnDrawItemSelf(DRAWITEMSTRUCT *pDrawItem)
父窗口接收到WM_DRAWITEM后且父窗口OnDrawItem函数返回false时调用发出通知控件的该函数
const ReadOnlyProperty< WndBase * > Parent
父窗口
Definition WndBase.h:188
virtual bool OnCreate()
接收到WM_CREATE时调用该函数
const Property< bool > Visible
窗口或控件是否可见
Definition WndBase.h:173
virtual bool OnMouseMove(const Point &mousePosition, MouseKey keyState)
接收到WM_MOUSEMOVE时调用该函数
HitTestResult NcHitTest(const Point &testPoint)
测试指定点在窗口的哪一部分
static WndBase * GetWndBase(HWND hwnd) noexcept
通过窗口句柄获取WndBase
void UpdateInternalRect()
同步窗口位置和尺寸到内部记录的Rect
DWORD GetThreadId() const
获取当前窗口所属线程的线程id
virtual void OnAcceleratorCommand(int id)
当WM_COMMAND接收到快捷键命令时调用该函数
bool IsVisible() const
判断当前对象在界面中是否可视,与Visible属性不同的是该函数返回值会受父窗口的影响
const ReadOnlyProperty< double > ClientWidth
用户区宽度
Definition WndBase.h:158
virtual bool OnMove(const Point &newClientPosition)
接收到WM_MOVE时调用该函数
virtual bool OnDestroy()
接收到WM_DESTROY时调用该函数
void InvokeAsync(const SimpleAction &action)
在窗口线程上执行指定委托,并立即返回
const Property< std::wstring > Text
窗口标题或控件文本
Definition WndBase.h:178
virtual bool OnDropFiles(HDROP hDrop)
接收到WM_DROPFILES时调用该函数
virtual bool OnCtlColor(WndBase *pControl, HDC hdc, HBRUSH &hRetBrush)
接收到WM_CTLCOLORxxx时调用该函数
LRESULT DefaultWndProc(const ProcMsg &msg)
调用默认的WndProc,对于窗口则调用DefWindowProcW,控件则调用_controlOldWndProc
virtual bool OnColor(HDC hdc, HBRUSH &hRetBrush)
父窗口接收到WM_CTLCOLORxxx时调用对应控件的该函数
virtual bool OnMouseLeave()
接收到WM_MOUSELEAVE时调用该函数
virtual bool OnSetCursor(HWND hwnd, HitTestResult hitTest, int message, bool &result)
接收到WM_SETCURSOR消息时调用该函数
void Update()
该函数调用UpdateWindow
bool GetStyle(DWORD mask) const
判断窗口是否设有指定样式
const ReadOnlyProperty< HWND > Handle
窗口句柄
Definition WndBase.h:103
virtual UIElement * ToUIElement()
尝试将对象转换成UIElement
virtual void FontChanged(HFONT hfont)
字体改变时调用该函数
DWORD GetExtendedStyle() const
获取扩展窗口样式
const Property< double > FontSize
字体大小
Definition WndBase.h:118
virtual bool OnMouseLeftButtonDoubleClick(const Point &mousePosition, MouseKey keyState)
接收到WM_LBUTTONDBLCLK时调用该函数
virtual bool OnContextMenu(bool isKeyboardMsg, const Point &mousePosition)
接收到WM_CONTEXTMENU后调用目标控件的该函数
virtual bool OnDeadChar(wchar_t ch, const KeyFlags &flags)
接收到WM_DEADCHAR时调用该函数
LRESULT SendMessageW(UINT uMsg, WPARAM wParam, LPARAM lParam)
发送消息(UNICODE)
const Property< bool > Enabled
窗口或控件是否可用
Definition WndBase.h:168
virtual void OnEndPaint()
在OnPaint函数完成之后调用该函数
virtual void OnTextChanged()
Text属性更改时调用此函数
void UpdateInternalText()
同步窗口文本到内部记录的字符串
void Show(int nCmdShow)
该函数调用ShowWindow
virtual Control * ToControl()
尝试将对象转换成Control
virtual bool OnMouseMiddleButtonDoubleClick(const Point &mousePosition, MouseKey keyState)
接收到WM_MBUTTONDBLCLK时调用该函数
BOOL PostMessageW(UINT uMsg, WPARAM wParam, LPARAM lParam)
发送消息(UNICODE)并立即返回
virtual bool OnSize(const Size &newClientSize)
接收到WM_SIZE时调用该函数
virtual bool OnSysDeadChar(wchar_t ch, const KeyFlags &flags)
接收到WM_SYSDEADCHAR时调用该函数
virtual bool OnNotify(NMHDR *pNMHDR, LRESULT &result)
接收到WM_NOTIFY后调用该函数
void InitControl(LPCWSTR lpClassName, LPCWSTR lpWindowName, DWORD dwStyle, DWORD dwExStyle, LPVOID lpParam=NULL)
初始化为控件,该函数会调用CreateWindowExW
virtual bool OnMouseMiddleButtonUp(const Point &mousePosition, MouseKey keyState)
接收到WM_MBUTTONUP时调用该函数
virtual void VisibleChanged(bool newVisible)
Visible属性改变时调用此函数
auto SetProperty(TProperty TDerived::*prop, typename TProperty::TSetterParam value) -> typename std::enable_if< std::is_base_of< WndBase, TDerived >::value &&_IsWritableProperty< TProperty >::value >::type
设置属性值
Definition WndBase.h:942
virtual std::wstring ToString() const
获取当前对象的描述字符串
virtual bool OnKeyDown(VirtualKey key, const KeyFlags &flags)
接收到WM_KEYDOWN时调用该函数
virtual bool OnHorizontalScroll(int event, int pos)
接收到WM_HSCROLL时调用目标控件的该函数
DWORD GetStyle() const
获取窗口样式
void SetStyle(DWORD style)
设置窗口样式
virtual bool OnEraseBackground(HDC hdc, LRESULT &result)
接收到WM_ERASEBKGND时调用该函数
virtual void OnMenuCommand(int id)
当WM_COMMAND接收到菜单命令时调用该函数
https://learn.microsoft.com/en-us/windows/win32/inputdev/about-keyboard-input#keystroke-message-flags
Definition Keys.h:12
表示相对于左上角的点坐标
Definition Point.h:15
对Windows窗口消息的封装
Definition ProcMsg.h:10
表示一个矩形区域
Definition Rect.h:17
判断类型是否为可读属性的辅助模板
Definition Property.h:132
判断类型是否为可写属性的辅助模板
Definition Property.h:140