DuiLib : 做一个没有任务栏图标的Dialog
发布日期:2021-06-30 22:06:11 浏览次数:2 分类:技术文章

本文共 2843 字,大约阅读时间需要 9 分钟。

看到有些软件在桌面右下角弹框时, 任务栏没有图标, 看起来像是从托盘程序弹出的。

实际上是一个单独的exe, 在Create时, 将 WS_EX_APPWINDOW 屏蔽掉了,就有这效果.

这次, 将设置Create风格的实现直接挪到DuiLib中, 形成2个虚函数. 

如果要实现的Dlg需要不同的风格, 就重载这两个虚函数.  

这么搞, 以后再也不会忘记设置风格的代码如何写. 因为GetStyle和GetExStyle很容易记忆.

工程下载点: 

编译环境 : vs2010 vc++ DuiLib

效果图:

\DuiLib\Utils\WinImplBase.h	virtual LONG GetStyle();        virtual LONG GetExStyle();	};\srcMain\dlgNotify\MainDlg.h	virtual void InitWindow();    	virtual LONG GetStyle();\DuiLib\Utils\WinImplBase.cppLRESULT WindowImplBase::OnCreate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled){    LONG styleValue = 0;    styleValue = GetStyle();    ::SetWindowLong(*this, GWL_STYLE, styleValue);    styleValue = GetExStyle();    ::SetWindowLong(*this, GWL_EXSTYLE, styleValue);    //...LONG WindowImplBase::GetStyle(){	LONG styleValue = ::GetWindowLong(*this, GWL_STYLE);	styleValue &= ~WS_CAPTION;    styleValue |= WS_CLIPSIBLINGS;    styleValue |= WS_CLIPCHILDREN;    return styleValue;}LONG WindowImplBase::GetExStyle(){    LONG styleValue = ::GetWindowLong(*this, GWL_EXSTYLE);    return styleValue;}\srcMain\dlgNotify\MainDlg.cppLONG CMainDlg::GetStyle(){    long dwStyle = __super::GetStyle();    dwStyle &= ~WS_MAXIMIZEBOX;    return dwStyle;}LONG CMainDlg::GetExStyle(){    long dwStyle = __super::GetExStyle();    dwStyle |= WS_EX_TOOLWINDOW;    dwStyle &= ~(WS_EX_APPWINDOW);    return dwStyle;}
为了将窗体挪到桌面的右下角, 参考 CWindowWnd::CenterWindow(), 写了一个 CMainDlg::MoveMyWindowToDesktopRightBottom()

临时用一下, 没有进行重构.

void CMainDlg::MoveMyWindowToDesktopRightBottom(){    ASSERT(::IsWindow(m_hWnd));    ASSERT((GetWindowStyle(m_hWnd)&WS_CHILD)==0);    RECT rcDlg = { 0 };    ::GetWindowRect(m_hWnd, &rcDlg);    RECT rcArea = { 0 };    RECT rcCenter = { 0 };    HWND hWnd=*this;    HWND hWndParent = ::GetParent(m_hWnd);    HWND hWndCenter = ::GetWindowOwner(m_hWnd);    if (hWndCenter!=NULL)        hWnd=hWndCenter;    // 处理多显示器模式下屏幕居中    MONITORINFO oMonitor = {};    oMonitor.cbSize = sizeof(oMonitor);    ::GetMonitorInfo(::MonitorFromWindow(hWnd, MONITOR_DEFAULTTONEAREST), &oMonitor);    rcArea = oMonitor.rcWork;    if( hWndCenter == NULL )        rcCenter = rcArea;    else        ::GetWindowRect(hWndCenter, &rcCenter);    int DlgWidth = rcDlg.right - rcDlg.left;    int DlgHeight = rcDlg.bottom - rcDlg.top;    // Find dialog's upper left based on rcCenter    int xLeft = rcCenter.right - DlgWidth;    int yTop = rcCenter.bottom - DlgHeight;    // The dialog is outside the screen, move it inside    if( xLeft < rcArea.left )        xLeft = rcArea.left;    else if( xLeft + DlgWidth > rcArea.right )         xLeft = rcArea.right - DlgWidth;    if( yTop < rcArea.top )        yTop = rcArea.top;    else if( yTop + DlgHeight > rcArea.bottom )         yTop = rcArea.bottom - DlgHeight;    ::SetWindowPos(m_hWnd, NULL, xLeft, yTop, -1, -1, SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);}

转载地址:https://lostspeed.blog.csdn.net/article/details/46944917 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:MFC : 在主窗口不透明的情况下, 建立一个半透明的子窗体带透明的TreeCtrl
下一篇:安装python-2.7.10.amd64, 再安装libxml2-python-2.7.7.win32-py2.7的注册表修改

发表评论

最新留言

做的很好,不错不错
[***.243.131.199]2024年04月26日 09时32分52秒