5#include "FrameworkElement.h"
6#include "HitTestResult.h"
7#include "IComparable.h"
43 static thread_local WndBase *_pendingInit;
52 static thread_local HHOOK _pendingHook;
88 bool _focused =
false;
93 bool _isDestroyed =
false;
98 bool _isControl =
false;
932 static int _NextControlId();
控件
Definition Control.h:12
框架元素类,提供数据上下文和绑定功能
Definition FrameworkElement.h:36
将Win32 window包装为SimpleWindow对象
Definition HwndWrapper.h:12
相等性比较接口
Definition IComparable.h:14
为支持ToString方法的类提供统一接口
Definition IToString.h:13
值转换器接口
Definition IValueConverter.h:14
表示界面中的元素
Definition UIElement.h:67
表示一个Windows窗口,是所有窗口和控件的基类
Definition WndBase.h:29
const ReadOnlyProperty< sw::Rect > ClientRect
用户区尺寸
Definition WndBase.h:159
virtual bool OnPaint()
接收到WM_PAINT时调用该函数
virtual bool OnMouseWheel(int wheelDelta, const Point &mousePosition, MouseKey keyState)
接收到WM_MOUSEWHEEL时调用该函数
BOOL PostMessageW(UINT uMsg, WPARAM wParam, LPARAM lParam) const noexcept
发送消息(UNICODE)并立即返回
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 WndBase * GetParent() const override
获取逻辑树中的父元素
virtual bool OnSysKeyDown(VirtualKey key, const KeyFlags &flags)
接收到WM_SYSKEYDOWN时调用该函数
void SetStyle(DWORD style) noexcept
设置窗口样式
static bool IsPtrValid(const WndBase *ptr) noexcept
检查指针是否指向有效的WndBase对象
virtual void SetInternalText(const std::wstring &value)
修改窗口文本,该函数默认实现为调用SetWindowTextW
virtual LRESULT WndProc(ProcMsg &refMsg)
对WndProc的封装
DWORD GetThreadId() const noexcept
获取当前窗口所属线程的线程id
bool CheckAccess() const noexcept
判断当前线程是否为窗口所属线程
const ReadOnlyProperty< std::wstring > ClassName
窗口类名
Definition WndBase.h:209
virtual bool OnMouseRightButtonUp(const Point &mousePosition, MouseKey keyState)
接收到WM_RBUTTONUP时调用该函数
const ReadOnlyProperty< double > ClientHeight
用户区高度
Definition WndBase.h:169
const Property< bool > AcceptFiles
是否接受拖放文件
Definition WndBase.h:199
virtual bool OnMouseLeftButtonDown(const Point &mousePosition, MouseKey keyState)
接收到WM_LBUTTONDOWN时调用该函数
WndBase * GetParentWnd() const noexcept
获取当前窗口对应的Win32父窗口(HWND父)的WndBase包装
const Property< double > Width
宽度
Definition WndBase.h:149
DWORD GetStyle() const noexcept
获取窗口样式
virtual bool OnMouseLeftButtonUp(const Point &mousePosition, MouseKey keyState)
接收到WM_LBUTTONUP时调用该函数
virtual int GetChildCount() const override
获取逻辑树中的子元素数量
virtual bool OnSetFocus(HWND hPrevFocus)
接收到WM_SETFOCUS时调用该函数
virtual void HandleInitialized(HWND hwnd)
窗口句柄初始化完成
const ReadOnlyProperty< bool > IsControl
当前对象是否是控件
Definition WndBase.h:204
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:139
const Property< sw::FontWeight > FontWeight
字体粗细
Definition WndBase.h:129
virtual bool OnSysKeyUp(VirtualKey key, const KeyFlags &flags)
接收到WM_SYSKEYUP时调用该函数
const Property< double > Height
高度
Definition WndBase.h:154
const Property< sw::Font > Font
字体
Definition WndBase.h:114
virtual bool OnNcPaint(HRGN hRgn)
接收到WM_NCPAINT时调用该函数
const ReadOnlyProperty< bool > IsDestroyed
是否已销毁,当该值为true时不应该继续使用当前对象
Definition WndBase.h:194
virtual bool OnMouseMiddleButtonDown(const Point &mousePosition, MouseKey keyState)
接收到WM_MBUTTONDOWN时调用该函数
bool IsVisible() const noexcept
判断当前对象在界面中是否可视,与Visible属性不同的是该函数返回值会受父窗口的影响
LRESULT SendMessageA(UINT uMsg, WPARAM wParam, LPARAM lParam) const
发送消息(ASCII)
virtual bool OnKeyUp(VirtualKey key, const KeyFlags &flags)
接收到WM_KEYUP时调用该函数
const Property< bool > IsGroupStart
窗口是否为一组控件中的第一个控件
Definition WndBase.h:215
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时调用该函数
virtual bool OnSysChar(wchar_t ch, const KeyFlags &flags)
接收到WM_SYSCHAR时调用该函数
const ReadOnlyProperty< bool > IsMouseCaptured
鼠标是否被当前窗口捕获
Definition WndBase.h:220
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:144
virtual bool OnKillFocus(HWND hNextFocus)
接收到WM_KILLFOCUS时调用该函数
virtual bool OnDrawItem(int id, DRAWITEMSTRUCT *pDrawItem)
接收到WM_DRAWITEM时调用该函数
const Property< bool > Focused
窗口是否拥有焦点
Definition WndBase.h:189
virtual bool OnVerticalScroll(int event, int pos)
接收到WM_VSCROLL时调用目标控件的该函数
const Property< std::wstring > FontName
字体名称
Definition WndBase.h:119
virtual bool OnEnabledChanged(bool newValue)
接收到WM_ENABLE时调用该函数
const Property< sw::Rect > Rect
位置和尺寸
Definition WndBase.h:134
virtual bool OnDrawItemSelf(DRAWITEMSTRUCT *pDrawItem)
父窗口接收到WM_DRAWITEM后且父窗口OnDrawItem函数返回false时调用发出通知控件的该函数
virtual bool OnCreate()
接收到WM_CREATE时调用该函数
const Property< bool > Visible
窗口或控件是否可见
Definition WndBase.h:179
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
virtual void OnAcceleratorCommand(int id)
当WM_COMMAND接收到快捷键命令时调用该函数
const ReadOnlyProperty< double > ClientWidth
用户区宽度
Definition WndBase.h:164
virtual bool OnMove(const Point &newClientPosition)
接收到WM_MOVE时调用该函数
virtual bool OnDestroy()
接收到WM_DESTROY时调用该函数
const Property< std::wstring > Text
窗口标题或控件文本
Definition WndBase.h:184
virtual bool OnDropFiles(HDROP hDrop)
接收到WM_DROPFILES时调用该函数
bool InvokeAsync(const Action<> &action)
在窗口线程上执行指定委托,并立即返回
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时调用对应控件的该函数
Point PointToScreen(const Point &point) const noexcept
获取用户区点在屏幕上点的位置
virtual bool OnMouseLeave()
接收到WM_MOUSELEAVE时调用该函数
virtual bool OnSetCursor(HWND hwnd, HitTestResult hitTest, int message, bool &result)
接收到WM_SETCURSOR消息时调用该函数
HFONT GetFontHandle() const noexcept
获取字体句柄
void Update()
该函数调用UpdateWindow
bool InitControl(LPCWSTR lpClassName, LPCWSTR lpWindowName, DWORD dwStyle, DWORD dwExStyle, LPVOID lpParam=NULL)
初始化为控件,该函数会调用CreateWindowExW
BOOL PostMessageA(UINT uMsg, WPARAM wParam, LPARAM lParam) const noexcept
发送消息(ASCII)并立即返回
const ReadOnlyProperty< HWND > Handle
窗口句柄
Definition WndBase.h:109
virtual UIElement * ToUIElement()
尝试将对象转换成UIElement
virtual void FontChanged(HFONT hfont)
字体改变时调用该函数
const Property< double > FontSize
字体大小
Definition WndBase.h:124
virtual bool OnMouseLeftButtonDoubleClick(const Point &mousePosition, MouseKey keyState)
接收到WM_LBUTTONDBLCLK时调用该函数
LRESULT SendMessageW(UINT uMsg, WPARAM wParam, LPARAM lParam) const
发送消息(UNICODE)
virtual bool OnContextMenu(bool isKeyboardMsg, const Point &mousePosition)
接收到WM_CONTEXTMENU后调用目标控件的该函数
virtual WndBase & GetChildAt(int index) const override
获取逻辑树中指定索引处的子元素
virtual bool OnDeadChar(wchar_t ch, const KeyFlags &flags)
接收到WM_DEADCHAR时调用该函数
const Property< bool > Enabled
窗口或控件是否可用
Definition WndBase.h:174
virtual void OnEndPaint()
在OnPaint函数完成之后调用该函数
virtual void OnTextChanged()
Text属性更改时调用此函数
void UpdateInternalText()
同步窗口文本到内部记录的字符串
void Show(int nCmdShow)
该函数调用ShowWindow
bool InitWindow(LPCWSTR lpWindowName, DWORD dwStyle, DWORD dwExStyle)
初始化为窗口,该函数会调用CreateWindowExW
void Invoke(const Action<> &action)
在窗口线程上执行指定委托
virtual bool OnMouseMiddleButtonDoubleClick(const Point &mousePosition, MouseKey keyState)
接收到WM_MBUTTONDBLCLK时调用该函数
virtual bool OnSize(const Size &newClientSize)
接收到WM_SIZE时调用该函数
void SetExtendedStyle(DWORD style) noexcept
设置扩展窗口样式
virtual bool OnSysDeadChar(wchar_t ch, const KeyFlags &flags)
接收到WM_SYSDEADCHAR时调用该函数
virtual bool OnNotify(NMHDR *pNMHDR, LRESULT &result)
接收到WM_NOTIFY后调用该函数
virtual bool OnMouseMiddleButtonUp(const Point &mousePosition, MouseKey keyState)
接收到WM_MBUTTONUP时调用该函数
virtual void VisibleChanged(bool newVisible)
Visible属性改变时调用此函数
Point PointFromScreen(const Point &screenPoint) const noexcept
获取屏幕上点在当前用户区点的位置
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 GetExtendedStyle() const noexcept
获取扩展窗口样式
virtual bool OnEraseBackground(HDC hdc, LRESULT &result)
接收到WM_ERASEBKGND时调用该函数
virtual void OnMenuCommand(int id)
当WM_COMMAND接收到菜单命令时调用该函数
SimpleWindow框架的顶级命名空间,所有公共类型、控件、枚举和工具函数均定义于此。
Definition Alignment.h:4
MouseKey
鼠标事件时用于判断按键状态
Definition Keys.h:291
VirtualKey
虚拟按键
Definition Keys.h:65
HitTestResult
NcHitTest(WM_NCHITTEST)的返回值
Definition HitTestResult.h:10
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