DuiLib : 做一个没有任务栏图标的Dialog

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

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


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

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

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


工程下载点: src_prj_dlg_no_task_bar_icon_2015_0718_2000.zip

编译环境 : 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.cpp

LRESULT 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.cpp
LONG 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);
}





  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值