From 7075c4d108c1d370b14bdee1e5f6d36df530b54a Mon Sep 17 00:00:00 2001 From: setoutsoft Date: Mon, 16 Dec 2019 14:36:49 +0800 Subject: [PATCH] add paint.setAntiAlias(m_bAntiAlias) for RenderSkia.FillArc --- SOUI/include/core/SHostWnd.h | 742 +++++++++++++------------- SOUI/include/souistd.h | 3 +- SOUI/src/core/shostwnd.cpp | 61 +++ demo/demo.cpp | 3 + utilities/include/wtl.mini/msgcrack.h | 13 + 5 files changed, 452 insertions(+), 370 deletions(-) diff --git a/SOUI/include/core/SHostWnd.h b/SOUI/include/core/SHostWnd.h index 3d9d0d83..7c3446c6 100644 --- a/SOUI/include/core/SHostWnd.h +++ b/SOUI/include/core/SHostWnd.h @@ -1,375 +1,379 @@ -////////////////////////////////////////////////////////////////////////// -// Class Name: SHostWnd -// Description: Real Container of SWindow -////////////////////////////////////////////////////////////////////////// - -#pragma once - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -namespace SOUI -{ - class SHostWndAttr : public SObject, public ITrCtxProvider - { - SOUI_CLASS_NAME(SHostWndAttr, L"SHostWndAttr") - enum {WT_UNDEFINE=0,WT_APPMAIN=1,WT_NORMAL=2}; - friend class SHostWnd; - public: - SHostWndAttr(void); - - ~SHostWndAttr(); - - void Init(); - - virtual const SStringW & GetTrCtx() const; - - CRect GetMaxInset(int nScale) const; - - CRect GetMargin(int nScale) const; - - CSize GetMinSize(int nScale) const; - - void SetTranslucent(bool bTranslucent) { - m_bTranslucent = bTranslucent; - } - - void SetTrCtx(const SStringW & strTrCtx) - { - m_strTrCtx = strTrCtx; - } - - SOUI_ATTRS_BEGIN() - ATTR_STRINGW(L"trCtx",m_strTrCtx,FALSE) - ATTR_I18NSTRT(L"title",m_strTitle,FALSE) - ATTR_LAYOUTSIZE4(L"maxInset",m_rcMaxInset,FALSE) - ATTR_LAYOUTSIZE4(L"margin",m_rcMargin,FALSE) - ATTR_LAYOUTSIZE2(L"minsize",m_szMin,FALSE) - ATTR_DWORD(L"wndStyle",m_dwStyle,FALSE) - ATTR_DWORD(L"wndStyleEx",m_dwExStyle,FALSE) - ATTR_INT(L"resizable",m_bResizable,FALSE) - ATTR_INT(L"translucent",m_bTranslucent,FALSE) - ATTR_INT(L"sendWheel2Hover",m_bSendWheel2Hover,FALSE) - ATTR_INT(L"appWnd",m_bAppWnd,FALSE) - ATTR_INT(L"toolWindow",m_bToolWnd,FALSE) - ATTR_ICON(L"smallIcon",m_hAppIconSmall,FALSE) - ATTR_ICON(L"bigIcon",m_hAppIconBig,FALSE) - ATTR_UINT(L"alpha",m_byAlpha,FALSE) - ATTR_INT(L"allowSpy",m_bAllowSpy,FALSE) - ATTR_ENUM_BEGIN(L"wndType",DWORD,FALSE) - ATTR_ENUM_VALUE(L"undefine",WT_UNDEFINE) - ATTR_ENUM_VALUE(L"appMain",WT_APPMAIN) - ATTR_ENUM_VALUE(L"normal",WT_NORMAL) - ATTR_ENUM_END(m_byWndType) - SOUI_ATTRS_END() - - protected: - SLayoutSize m_rcMargin[4]; //窗口拉伸的边缘检测大小 - SLayoutSize m_szMin[2]; //窗口最小值 - SLayoutSize m_rcMaxInset[4]; //窗口最大化时超出屏幕的边缘大小。经测试,WS_OVERLAPPED style的窗口该属性无效 - - DWORD m_byAlpha:8; //透明度 - DWORD m_byWndType:8; //主窗口标志,有该标志的窗口关闭时自动发送WM_QUIT - DWORD m_bResizable:1; //窗口大小可调节 - DWORD m_bAppWnd:1; //APP窗口,在任务栏上显示按钮 - DWORD m_bToolWnd:1; //设置WS_ES_TOOLWINDOW属性 - DWORD m_bTranslucent:1; //窗口的半透明属性 - DWORD m_bAllowSpy:1; //允许spy - DWORD m_bSendWheel2Hover:1; //将滚轮消息发送到hover窗口 - - DWORD m_dwStyle; - DWORD m_dwExStyle; - - SStringW m_strTrCtx; //在语言翻译时作为context使用 - STrText m_strTitle; - HICON m_hAppIconSmall; - HICON m_hAppIconBig; - }; - -class SOUI_EXP SHostWnd - : public SwndContainerImpl - , public SNativeWnd - , protected IHostMsgHandler -{ - SOUI_CLASS_NAME(SHostWnd,L"hostwnd") - friend class SDummyWnd; -protected: - SDummyWnd* m_dummyWnd; /**<半透明窗口使用的一个响应WM_PAINT消息的窗口*/ - SHostWndAttr m_hostAttr; /** m_rgnInvalidate; /**<脏区域*/ - SAutoRefPtr m_memRT; /**<绘制缓存*/ - SAutoRefPtr m_privateStylePool; /**<局部style pool*/ - SAutoRefPtr m_privateSkinPool; /**<局部skin pool*/ - SAutoRefPtr m_privateTemplatePool;/**< 局部template pool */ - - SList m_lstUpdateSwnd; /**<等待刷新的非背景混合窗口列表*/ - SList m_lstUpdatedRect; /**<更新的脏矩形列表*/ - BOOL m_bRendering; /**<正在渲染过程中*/ - - MSG m_msgMouse; /**<上一次鼠标按下消息*/ - - SAutoRefPtr m_pScriptModule; /**<脚本模块*/ - - int m_nScale; /**<缩放比例 */ - - CSize m_szAppSetted; /**<应用层设置的窗口大小 */ - int m_nAutoSizing; /**<自动计算大小触发的WM_SIZE消息 */ - bool m_bResizing; /**<执行WM_SIZE*/ - - SAutoRefPtr m_hostAnimation; -public: - SHostWnd(LPCTSTR pszResName = NULL); - virtual ~SHostWnd(); - -public: +////////////////////////////////////////////////////////////////////////// +// Class Name: SHostWnd +// Description: Real Container of SWindow +////////////////////////////////////////////////////////////////////////// + +#pragma once + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +namespace SOUI +{ + class SHostWndAttr : public SObject, public ITrCtxProvider + { + SOUI_CLASS_NAME(SHostWndAttr, L"SHostWndAttr") + enum {WT_UNDEFINE=0,WT_APPMAIN=1,WT_NORMAL=2}; + friend class SHostWnd; + public: + SHostWndAttr(void); + + ~SHostWndAttr(); + + void Init(); + + virtual const SStringW & GetTrCtx() const; + + CRect GetMaxInset(int nScale) const; + + CRect GetMargin(int nScale) const; + + CSize GetMinSize(int nScale) const; + + void SetTranslucent(bool bTranslucent) { + m_bTranslucent = bTranslucent; + } + + void SetTrCtx(const SStringW & strTrCtx) + { + m_strTrCtx = strTrCtx; + } + + SOUI_ATTRS_BEGIN() + ATTR_STRINGW(L"trCtx",m_strTrCtx,FALSE) + ATTR_I18NSTRT(L"title",m_strTitle,FALSE) + ATTR_LAYOUTSIZE4(L"maxInset",m_rcMaxInset,FALSE) + ATTR_LAYOUTSIZE4(L"margin",m_rcMargin,FALSE) + ATTR_LAYOUTSIZE2(L"minsize",m_szMin,FALSE) + ATTR_DWORD(L"wndStyle",m_dwStyle,FALSE) + ATTR_DWORD(L"wndStyleEx",m_dwExStyle,FALSE) + ATTR_INT(L"resizable",m_bResizable,FALSE) + ATTR_INT(L"translucent",m_bTranslucent,FALSE) + ATTR_INT(L"sendWheel2Hover",m_bSendWheel2Hover,FALSE) + ATTR_INT(L"appWnd",m_bAppWnd,FALSE) + ATTR_INT(L"toolWindow",m_bToolWnd,FALSE) + ATTR_ICON(L"smallIcon",m_hAppIconSmall,FALSE) + ATTR_ICON(L"bigIcon",m_hAppIconBig,FALSE) + ATTR_UINT(L"alpha",m_byAlpha,FALSE) + ATTR_INT(L"allowSpy",m_bAllowSpy,FALSE) + ATTR_ENUM_BEGIN(L"wndType",DWORD,FALSE) + ATTR_ENUM_VALUE(L"undefine",WT_UNDEFINE) + ATTR_ENUM_VALUE(L"appMain",WT_APPMAIN) + ATTR_ENUM_VALUE(L"normal",WT_NORMAL) + ATTR_ENUM_END(m_byWndType) + SOUI_ATTRS_END() + + protected: + SLayoutSize m_rcMargin[4]; //窗口拉伸的边缘检测大小 + SLayoutSize m_szMin[2]; //窗口最小值 + SLayoutSize m_rcMaxInset[4]; //窗口最大化时超出屏幕的边缘大小。经测试,WS_OVERLAPPED style的窗口该属性无效 + + DWORD m_byAlpha:8; //透明度 + DWORD m_byWndType:8; //主窗口标志,有该标志的窗口关闭时自动发送WM_QUIT + DWORD m_bResizable:1; //窗口大小可调节 + DWORD m_bAppWnd:1; //APP窗口,在任务栏上显示按钮 + DWORD m_bToolWnd:1; //设置WS_ES_TOOLWINDOW属性 + DWORD m_bTranslucent:1; //窗口的半透明属性 + DWORD m_bAllowSpy:1; //允许spy + DWORD m_bSendWheel2Hover:1; //将滚轮消息发送到hover窗口 + + DWORD m_dwStyle; + DWORD m_dwExStyle; + + SStringW m_strTrCtx; //在语言翻译时作为context使用 + STrText m_strTitle; + HICON m_hAppIconSmall; + HICON m_hAppIconBig; + }; + +class SOUI_EXP SHostWnd + : public SwndContainerImpl + , public SNativeWnd + , protected IHostMsgHandler +{ + SOUI_CLASS_NAME(SHostWnd,L"hostwnd") + friend class SDummyWnd; +protected: + SDummyWnd* m_dummyWnd; /**<半透明窗口使用的一个响应WM_PAINT消息的窗口*/ + SHostWndAttr m_hostAttr; /** m_rgnInvalidate; /**<脏区域*/ + SAutoRefPtr m_memRT; /**<绘制缓存*/ + SAutoRefPtr m_privateStylePool; /**<局部style pool*/ + SAutoRefPtr m_privateSkinPool; /**<局部skin pool*/ + SAutoRefPtr m_privateTemplatePool;/**< 局部template pool */ + + SList m_lstUpdateSwnd; /**<等待刷新的非背景混合窗口列表*/ + SList m_lstUpdatedRect; /**<更新的脏矩形列表*/ + BOOL m_bRendering; /**<正在渲染过程中*/ + + MSG m_msgMouse; /**<上一次鼠标按下消息*/ + + SAutoRefPtr m_pScriptModule; /**<脚本模块*/ + + int m_nScale; /**<缩放比例 */ + + CSize m_szAppSetted; /**<应用层设置的窗口大小 */ + int m_nAutoSizing; /**<自动计算大小触发的WM_SIZE消息 */ + bool m_bResizing; /**<执行WM_SIZE*/ + int m_nTouchY; /**<判断滑动方向只支持上下 */ + + SAutoRefPtr m_hostAnimation; +public: + SHostWnd(LPCTSTR pszResName = NULL); + virtual ~SHostWnd(); + +public: enum { kPulseTimer = 4321, //soui timer. don't use it in app kPulseInterval = 10, - }; -public: - SWindow * GetRoot() const {return (SWindow*)this;} - - SNativeWnd * GetNative(){return this;} - - HWND Create(HWND hWndParent,int x = 0, int y = 0, int nWidth = 0, int nHeight = 0); - HWND Create(HWND hWndParent,DWORD dwStyle,DWORD dwExStyle, int x = 0, int y = 0, int nWidth = 0, int nHeight = 0); - - BOOL InitFromXml(pugi::xml_node xmlNode); - - BOOL AnimateHostWindow(DWORD dwTime,DWORD dwFlags); - - //实现3个供脚本使用的定时器函数 - UINT setTimeout(LPCSTR pszScriptFunc,UINT uElapse); - UINT setInterval(LPCSTR pszScriptFunc,UINT uElapse); - void clearTimer(UINT uID); - - //实现几个常用接口,防止派生类调用时产生歧义 - BOOL DestroyWindow(); - UINT_PTR SetTimer(UINT_PTR nIDEvent,UINT nElapse); - BOOL KillTimer(UINT_PTR id); - CRect GetWindowRect() const; - CRect GetClientRect() const; - - SHostWndAttr & GetHostAttr() { - return m_hostAttr; - } + }; +public: + SWindow * GetRoot() const {return (SWindow*)this;} + + SNativeWnd * GetNative(){return this;} + + HWND Create(HWND hWndParent,int x = 0, int y = 0, int nWidth = 0, int nHeight = 0); + HWND Create(HWND hWndParent,DWORD dwStyle,DWORD dwExStyle, int x = 0, int y = 0, int nWidth = 0, int nHeight = 0); + + BOOL InitFromXml(pugi::xml_node xmlNode); + + BOOL AnimateHostWindow(DWORD dwTime,DWORD dwFlags); + + //实现3个供脚本使用的定时器函数 + UINT setTimeout(LPCSTR pszScriptFunc,UINT uElapse); + UINT setInterval(LPCSTR pszScriptFunc,UINT uElapse); + void clearTimer(UINT uID); + + //实现几个常用接口,防止派生类调用时产生歧义 + BOOL DestroyWindow(); + UINT_PTR SetTimer(UINT_PTR nIDEvent,UINT nElapse); + BOOL KillTimer(UINT_PTR id); + CRect GetWindowRect() const; + CRect GetClientRect() const; + + SHostWndAttr & GetHostAttr() { + return m_hostAttr; + } IToolTip * GetToolTip() const { return m_pTipCtrl; - } - - void SetHostAnimation(IAnimation *pAni,bool startNow = true); - bool StartHostAnimation(); - bool StopHostAnimation(); - void UpdateAutoSizeCount(bool bInc); -protected: - class SHostAnimationHandler : public ITimelineHandler - { - public: - STransformation m_hostTransform; - SHostWnd * m_pHostWnd; - CRect m_rcInit; - protected: - virtual void OnNextFrame()override; - } m_hostAnimationHandler; - - virtual void OnHostAnimationStarted(IAnimation * pAni){} - virtual void OnHostAnimationStoped(IAnimation * pAni){} -protected://辅助函数 - void _Redraw(); - void _UpdateNonBkgndBlendSwnd(); + } + + void SetHostAnimation(IAnimation *pAni,bool startNow = true); + bool StartHostAnimation(); + bool StopHostAnimation(); + void UpdateAutoSizeCount(bool bInc); +protected: + class SHostAnimationHandler : public ITimelineHandler + { + public: + STransformation m_hostTransform; + SHostWnd * m_pHostWnd; + CRect m_rcInit; + protected: + virtual void OnNextFrame()override; + } m_hostAnimationHandler; + + virtual void OnHostAnimationStarted(IAnimation * pAni){} + virtual void OnHostAnimationStoped(IAnimation * pAni){} +protected://辅助函数 + void _Redraw(); + void _UpdateNonBkgndBlendSwnd(); void _RestoreClickState(); - void _Invalidate(LPCRECT prc); -protected: - ////////////////////////////////////////////////////////////////////////// - // Message handler - - void OnPrint(HDC dc, UINT uFlags); - - void OnPaint(HDC dc); - - BOOL OnEraseBkgnd(HDC dc); - - int OnCreate(LPCREATESTRUCT lpCreateStruct); - - void OnDestroy(); - - void OnSize(UINT nType, CSize size); - - void OnMouseMove(UINT nFlags, CPoint point); - - void OnMouseLeave(); - - BOOL OnSetCursor(HWND hWnd, UINT nHitTest, UINT message); - - void OnTimer(UINT_PTR idEvent); - - LRESULT OnMouseEvent(UINT uMsg, WPARAM wParam, LPARAM lParam); - - LRESULT OnKeyEvent(UINT uMsg, WPARAM wParam, LPARAM lParam); - - LRESULT OnActivateApp(UINT uMsg, WPARAM wParam, LPARAM lParam); - - BOOL OnMouseWheel(UINT nFlags, short zDelta, CPoint pt); - - void OnActivate(UINT nState, BOOL bMinimized, HWND wndOther); - - LRESULT OnNcCalcSize(BOOL bCalcValidRects, LPARAM lParam); - - void OnGetMinMaxInfo(LPMINMAXINFO lpMMI); - - BOOL OnNcActivate(BOOL bActive); - - UINT OnWndNcHitTest(CPoint point); - - void OnSetFocus(HWND wndOld); - void OnKillFocus(HWND wndFocus); - - void UpdateHost(HDC dc,const CRect &rc,BYTE byAlpha=255); - void UpdateLayerFromRenderTarget(IRenderTarget *pRT,BYTE byAlpha, LPCRECT prcDirty=NULL); - - void OnCaptureChanged(HWND wnd); - - LRESULT OnScriptTimer(UINT uMsg,WPARAM wParam,LPARAM lParam); - - LRESULT OnMenuExEvent(UINT uMsg,WPARAM wParam,LPARAM lParam); - - void OnWindowPosChanging(LPWINDOWPOS lpWndPos); - - LRESULT OnGetObject(UINT uMsg, WPARAM wParam, LPARAM lParam); - -#ifndef DISABLE_SWNDSPY -protected: - LRESULT OnSpyMsgSetSpy(UINT uMsg,WPARAM wParam,LPARAM lParam); - - LRESULT OnSpyMsgSwndEnum(UINT uMsg,WPARAM wParam,LPARAM lParam); - - LRESULT OnSpyMsgSwndSpy(UINT uMsg,WPARAM wParam,LPARAM lParam); - - LRESULT OnSpyMsgHitTest(UINT uMsg,WPARAM wParam,LPARAM lParam); - - HWND m_hSpyWnd; -#endif - -protected:// IContainer - - virtual BOOL OnFireEvent(EventArgs &evt); - - virtual CRect GetContainerRect() const; - - virtual HWND GetHostHwnd(); - - virtual const SStringW & GetTranslatorContext() const; - - virtual IRenderTarget * OnGetRenderTarget(const CRect & rc,GrtFlag gdcFlags); - - virtual void OnReleaseRenderTarget(IRenderTarget * pRT,const CRect &rc,GrtFlag gdcFlags); - - virtual void OnRedraw(const CRect &rc); - - virtual BOOL OnReleaseSwndCapture(); - - virtual SWND OnSetSwndCapture(SWND swnd); - - virtual BOOL IsTranslucent() const; - - virtual BOOL IsSendWheel2Hover() const; - - virtual BOOL UpdateWindow(); - - virtual void UpdateTooltip(); - - virtual BOOL RegisterTimelineHandler(ITimelineHandler *pHandler); - - virtual BOOL UnregisterTimelineHandler(ITimelineHandler *pHandler); - - virtual SMessageLoop * GetMsgLoop(); - - virtual IScriptModule * GetScriptModule(); - - virtual int GetScale() const; - - virtual void OnCavasInvalidate(SWND swnd); -protected://Swindow 虚方法 - virtual void BeforePaint(IRenderTarget *pRT, SPainter &painter); - virtual void AfterPaint(IRenderTarget *pRT, SPainter &painter); - virtual BOOL IsLayeredWindow() const{return FALSE;} - virtual void UpdateLayout(); - virtual HRESULT OnLanguageChanged(); - virtual void OnScaleChanged(int scale); - -protected: - virtual IToolTip * CreateTooltip() const; - virtual void DestroyTooltip(IToolTip * pTooltip) const; - -protected: - virtual void OnUserXmlNode(pugi::xml_node xmlUser); -protected: - virtual void OnWindowTextChanged(LPCTSTR pszTitle) override; -protected: - virtual void OnHostMsg(bool bRelayout,UINT uMsg, WPARAM wParam, LPARAM lParam) override; -public: - virtual void RequestRelayout(SWND hSource ,BOOL bSourceResizable ); - virtual bool onRootResize(EventArgs *e); - -public://事件处理接口 - virtual BOOL _HandleEvent(EventArgs *pEvt){return FALSE;} - - - BEGIN_MSG_MAP_EX(SHostWnd) - MSG_WM_SIZE(OnSize) - MSG_WM_PRINT(OnPrint) - MSG_WM_PAINT(OnPaint) - MSG_WM_CREATE(OnCreate) - MSG_WM_DESTROY(OnDestroy) - MSG_WM_ERASEBKGND(OnEraseBkgnd) - MSG_WM_MOUSELEAVE(OnMouseLeave) - MSG_WM_MOUSEMOVE(OnMouseMove) - MSG_WM_MOUSEWHEEL(OnMouseWheel) - MSG_WM_ACTIVATE(OnActivate) - MSG_WM_SETFOCUS(OnSetFocus) - MSG_WM_KILLFOCUS(OnKillFocus) - MESSAGE_RANGE_HANDLER_EX(WM_MOUSEFIRST, WM_MOUSELAST, OnMouseEvent) - MESSAGE_RANGE_HANDLER_EX(WM_KEYFIRST, WM_KEYLAST, OnKeyEvent) - MESSAGE_RANGE_HANDLER_EX(WM_IME_STARTCOMPOSITION,WM_IME_KEYLAST,OnKeyEvent) - MESSAGE_HANDLER_EX(WM_IME_CHAR, OnKeyEvent) - MESSAGE_HANDLER_EX(WM_ACTIVATEAPP,OnActivateApp) - MSG_WM_SETCURSOR(OnSetCursor) - MSG_WM_TIMER(OnTimer) - MSG_WM_NCACTIVATE(OnNcActivate) - MSG_WM_NCCALCSIZE(OnNcCalcSize) - MSG_WM_NCHITTEST(OnWndNcHitTest) - MSG_WM_GETMINMAXINFO(OnGetMinMaxInfo) - MSG_WM_CAPTURECHANGED(OnCaptureChanged) - MESSAGE_HANDLER_EX(UM_SCRIPTTIMER,OnScriptTimer) - MESSAGE_HANDLER_EX(UM_MENUEVENT,OnMenuExEvent) - MSG_WM_WINDOWPOSCHANGING(OnWindowPosChanging) - MESSAGE_HANDLER_EX(WM_GETOBJECT,OnGetObject) - #ifndef DISABLE_SWNDSPY - MESSAGE_HANDLER_EX(SPYMSG_SETSPY, OnSpyMsgSetSpy) - MESSAGE_HANDLER_EX(SPYMSG_SWNDENUM, OnSpyMsgSwndEnum) - MESSAGE_HANDLER_EX(SPYMSG_SWNDINFO, OnSpyMsgSwndSpy) - MESSAGE_HANDLER_EX(SPYMSG_HITTEST, OnSpyMsgHitTest) - #endif - REFLECT_NOTIFY_CODE(NM_CUSTOMDRAW) - END_MSG_MAP() -}; - -}//namespace SOUI + void _Invalidate(LPCRECT prc); +protected: + ////////////////////////////////////////////////////////////////////////// + // Message handler + + void OnPrint(HDC dc, UINT uFlags); + + void OnPaint(HDC dc); + + BOOL OnEraseBkgnd(HDC dc); + + int OnCreate(LPCREATESTRUCT lpCreateStruct); + + void OnDestroy(); + + void OnSize(UINT nType, CSize size); + + void OnMouseMove(UINT nFlags, CPoint point); + + void OnMouseLeave(); + + BOOL OnSetCursor(HWND hWnd, UINT nHitTest, UINT message); + + void OnTimer(UINT_PTR idEvent); + + LRESULT OnMouseEvent(UINT uMsg, WPARAM wParam, LPARAM lParam); + + LRESULT OnKeyEvent(UINT uMsg, WPARAM wParam, LPARAM lParam); + + LRESULT OnActivateApp(UINT uMsg, WPARAM wParam, LPARAM lParam); + + BOOL OnMouseWheel(UINT nFlags, short zDelta, CPoint pt); + + LRESULT OnMouseTouch(UINT wParam, LPTSTR lParam); + + void OnActivate(UINT nState, BOOL bMinimized, HWND wndOther); + + LRESULT OnNcCalcSize(BOOL bCalcValidRects, LPARAM lParam); + + void OnGetMinMaxInfo(LPMINMAXINFO lpMMI); + + BOOL OnNcActivate(BOOL bActive); + + UINT OnWndNcHitTest(CPoint point); + + void OnSetFocus(HWND wndOld); + void OnKillFocus(HWND wndFocus); + + void UpdateHost(HDC dc,const CRect &rc,BYTE byAlpha=255); + void UpdateLayerFromRenderTarget(IRenderTarget *pRT,BYTE byAlpha, LPCRECT prcDirty=NULL); + + void OnCaptureChanged(HWND wnd); + + LRESULT OnScriptTimer(UINT uMsg,WPARAM wParam,LPARAM lParam); + + LRESULT OnMenuExEvent(UINT uMsg,WPARAM wParam,LPARAM lParam); + + void OnWindowPosChanging(LPWINDOWPOS lpWndPos); + + LRESULT OnGetObject(UINT uMsg, WPARAM wParam, LPARAM lParam); + +#ifndef DISABLE_SWNDSPY +protected: + LRESULT OnSpyMsgSetSpy(UINT uMsg,WPARAM wParam,LPARAM lParam); + + LRESULT OnSpyMsgSwndEnum(UINT uMsg,WPARAM wParam,LPARAM lParam); + + LRESULT OnSpyMsgSwndSpy(UINT uMsg,WPARAM wParam,LPARAM lParam); + + LRESULT OnSpyMsgHitTest(UINT uMsg,WPARAM wParam,LPARAM lParam); + + HWND m_hSpyWnd; +#endif + +protected:// IContainer + + virtual BOOL OnFireEvent(EventArgs &evt); + + virtual CRect GetContainerRect() const; + + virtual HWND GetHostHwnd(); + + virtual const SStringW & GetTranslatorContext() const; + + virtual IRenderTarget * OnGetRenderTarget(const CRect & rc,GrtFlag gdcFlags); + + virtual void OnReleaseRenderTarget(IRenderTarget * pRT,const CRect &rc,GrtFlag gdcFlags); + + virtual void OnRedraw(const CRect &rc); + + virtual BOOL OnReleaseSwndCapture(); + + virtual SWND OnSetSwndCapture(SWND swnd); + + virtual BOOL IsTranslucent() const; + + virtual BOOL IsSendWheel2Hover() const; + + virtual BOOL UpdateWindow(); + + virtual void UpdateTooltip(); + + virtual BOOL RegisterTimelineHandler(ITimelineHandler *pHandler); + + virtual BOOL UnregisterTimelineHandler(ITimelineHandler *pHandler); + + virtual SMessageLoop * GetMsgLoop(); + + virtual IScriptModule * GetScriptModule(); + + virtual int GetScale() const; + + virtual void OnCavasInvalidate(SWND swnd); +protected://Swindow 虚方法 + virtual void BeforePaint(IRenderTarget *pRT, SPainter &painter); + virtual void AfterPaint(IRenderTarget *pRT, SPainter &painter); + virtual BOOL IsLayeredWindow() const{return FALSE;} + virtual void UpdateLayout(); + virtual HRESULT OnLanguageChanged(); + virtual void OnScaleChanged(int scale); + +protected: + virtual IToolTip * CreateTooltip() const; + virtual void DestroyTooltip(IToolTip * pTooltip) const; + +protected: + virtual void OnUserXmlNode(pugi::xml_node xmlUser); +protected: + virtual void OnWindowTextChanged(LPCTSTR pszTitle) override; +protected: + virtual void OnHostMsg(bool bRelayout,UINT uMsg, WPARAM wParam, LPARAM lParam) override; +public: + virtual void RequestRelayout(SWND hSource ,BOOL bSourceResizable ); + virtual bool onRootResize(EventArgs *e); + +public://事件处理接口 + virtual BOOL _HandleEvent(EventArgs *pEvt){return FALSE;} + + + BEGIN_MSG_MAP_EX(SHostWnd) + MSG_WM_SIZE(OnSize) + MSG_WM_PRINT(OnPrint) + MSG_WM_PAINT(OnPaint) + MSG_WM_CREATE(OnCreate) + MSG_WM_DESTROY(OnDestroy) + MSG_WM_ERASEBKGND(OnEraseBkgnd) + MSG_WM_MOUSELEAVE(OnMouseLeave) + MSG_WM_MOUSEMOVE(OnMouseMove) + MSG_WM_MOUSEWHEEL(OnMouseWheel) + MSG_WM_TOUCH(OnMouseTouch) + MSG_WM_ACTIVATE(OnActivate) + MSG_WM_SETFOCUS(OnSetFocus) + MSG_WM_KILLFOCUS(OnKillFocus) + MESSAGE_RANGE_HANDLER_EX(WM_MOUSEFIRST, WM_MOUSELAST, OnMouseEvent) + MESSAGE_RANGE_HANDLER_EX(WM_KEYFIRST, WM_KEYLAST, OnKeyEvent) + MESSAGE_RANGE_HANDLER_EX(WM_IME_STARTCOMPOSITION,WM_IME_KEYLAST,OnKeyEvent) + MESSAGE_HANDLER_EX(WM_IME_CHAR, OnKeyEvent) + MESSAGE_HANDLER_EX(WM_ACTIVATEAPP,OnActivateApp) + MSG_WM_SETCURSOR(OnSetCursor) + MSG_WM_TIMER(OnTimer) + MSG_WM_NCACTIVATE(OnNcActivate) + MSG_WM_NCCALCSIZE(OnNcCalcSize) + MSG_WM_NCHITTEST(OnWndNcHitTest) + MSG_WM_GETMINMAXINFO(OnGetMinMaxInfo) + MSG_WM_CAPTURECHANGED(OnCaptureChanged) + MESSAGE_HANDLER_EX(UM_SCRIPTTIMER,OnScriptTimer) + MESSAGE_HANDLER_EX(UM_MENUEVENT,OnMenuExEvent) + MSG_WM_WINDOWPOSCHANGING(OnWindowPosChanging) + MESSAGE_HANDLER_EX(WM_GETOBJECT,OnGetObject) + #ifndef DISABLE_SWNDSPY + MESSAGE_HANDLER_EX(SPYMSG_SETSPY, OnSpyMsgSetSpy) + MESSAGE_HANDLER_EX(SPYMSG_SWNDENUM, OnSpyMsgSwndEnum) + MESSAGE_HANDLER_EX(SPYMSG_SWNDINFO, OnSpyMsgSwndSpy) + MESSAGE_HANDLER_EX(SPYMSG_HITTEST, OnSpyMsgHitTest) + #endif + REFLECT_NOTIFY_CODE(NM_CUSTOMDRAW) + END_MSG_MAP() +}; + +}//namespace SOUI diff --git a/SOUI/include/souistd.h b/SOUI/include/souistd.h index a3b10ae0..60f628d4 100644 --- a/SOUI/include/souistd.h +++ b/SOUI/include/souistd.h @@ -15,7 +15,8 @@ // Change these values to use different versions #ifndef WINVER -#define WINVER 0x0500 +#define WINVER 0x0601 //支持触摸事件最低版本 +//#define WINVER 0x0500 #define _WIN32_WINNT 0x0502 #endif//WINVER diff --git a/SOUI/src/core/shostwnd.cpp b/SOUI/src/core/shostwnd.cpp index 0466cf26..6cd0b7f1 100644 --- a/SOUI/src/core/shostwnd.cpp +++ b/SOUI/src/core/shostwnd.cpp @@ -710,6 +710,67 @@ BOOL SHostWnd::OnMouseWheel(UINT nFlags, short zDelta, CPoint pt) return DoFrameEvent(WM_MOUSEWHEEL,MAKEWPARAM(nFlags,zDelta),MAKELPARAM(pt.x,pt.y))!=0; } +LRESULT SHostWnd::OnMouseTouch(UINT wParam, LPTSTR lParam) +{ + unsigned int numInputs = (unsigned int)wParam; // Number of actual per-contact messages + TOUCHINPUT* ti = new TOUCHINPUT[numInputs]; // Allocate the storage for the parameters of the per-contact messages + if (ti == NULL) + { + return 0; + } + // Unpack message parameters into the array of TOUCHINPUT structures, each + // representing a message for one single contact. + if (GetTouchInputInfo((HTOUCHINPUT)lParam, numInputs, ti, sizeof(TOUCHINPUT))) + { + // For each contact, dispatch the message to the appropriate message + // handler. + for (unsigned int i = 0; i < numInputs; ++i) + { + POINT pt; + pt.x = ti[i].x / 100; + pt.y = ti[i].y / 100; + ::ScreenToClient(m_hWnd, &pt); + + if (ti[i].dwFlags & TOUCHEVENTF_DOWN) + { + m_nTouchY = pt.y; + DoFrameEvent(WM_MOUSEHOVER, wParam, MAKELPARAM(pt.x, pt.y)); + } + else if (ti[i].dwFlags & TOUCHEVENTF_MOVE) + { + if (m_nTouchY == pt.y) + { + continue; //去掉无限滑动 + //break; + } + else if (m_nTouchY < pt.y)//滑动方向 + { + m_nTouchY = pt.y; + //CSimpleWnd::SendMessage(WM_MOUSEWHEEL, MAKEWPARAM(0, 120), MAKELPARAM(pt.x, pt.y)); + DoFrameEvent(WM_MOUSEWHEEL, MAKEWPARAM(0, 120), MAKELPARAM(pt.x, pt.y));//上 + } + else + { + m_nTouchY = pt.y; + //CSimpleWnd::SendMessage(WM_MOUSEWHEEL, MAKEWPARAM(0, -120), MAKELPARAM(pt.x, pt.y)); + DoFrameEvent(WM_MOUSEWHEEL, MAKEWPARAM(0, -120), MAKELPARAM(pt.x, pt.y));//下 + + } + } + else if (ti[i].dwFlags & TOUCHEVENTF_UP) + { + m_nTouchY = 0; + m_bTrackFlag = FALSE; + DoFrameEvent(WM_MOUSELEAVE, wParam, MAKELPARAM(pt.x, pt.y)); + } + } + } + CloseTouchInputHandle((HTOUCHINPUT)lParam); + delete[] ti; + + return 0; + +} void SHostWnd::OnActivate( UINT nState, BOOL bMinimized, HWND wndOther ) { diff --git a/demo/demo.cpp b/demo/demo.cpp index 02af54d2..b95ec354 100644 --- a/demo/demo.cpp +++ b/demo/demo.cpp @@ -352,9 +352,12 @@ int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE /*hPrevInstance*/, LPTSTR /* dlgMain.GetNative()->SendMessage(WM_INITDIALOG); dlgMain.CenterWindow(); dlgMain.ShowWindow(SW_SHOWNORMAL); + RegisterTouchWindow(dlgMain.m_hWnd, 0); //触摸屏启用-注册响应触摸事件 SmileyCreateHook smileyHook; //不知道MainDlg里哪块和mhook冲突了,在win10中,如果hook放到dlgmain.create前会导致hook失败。 nRet=theApp->Run(dlgMain.m_hWnd); + + UnregisterTouchWindow(dlgMain.m_hWnd); //反注册响应触摸事件 } delete pNotifyCenter; diff --git a/utilities/include/wtl.mini/msgcrack.h b/utilities/include/wtl.mini/msgcrack.h index 262eba3c..2646bdfb 100644 --- a/utilities/include/wtl.mini/msgcrack.h +++ b/utilities/include/wtl.mini/msgcrack.h @@ -1055,6 +1055,19 @@ public: \ return TRUE; \ } +#ifndef WM_TOUCH +#define WM_TOUCH 0x0240 //触摸支持版本 +#endif +//LRESULT OnTouch(WPARAM wParam, LPARAM lParam); +#define MSG_WM_TOUCH(func) \ + if (uMsg == WM_TOUCH) \ + { \ + SetMsgHandled(TRUE); \ + lResult = (LRESULT)func((int)wParam, (LPTSTR)lParam); \ + if(IsMsgHandled()) \ + return TRUE; \ +} + // void OnLButtonDown(UINT nFlags, CPoint point) #define MSG_WM_LBUTTONDOWN(func) \ if (uMsg == WM_LBUTTONDOWN) \ -- Gitee