Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

CResizeWnd, Handle a Dialog Resizing Without Dialog Border

0.00/5 (No votes)
22 Dec 2014 1  
Use CResizeWnd as an add-on to any dialog

Introduction

Sometimes, I need a custom dialog without the default border or a caption, but the dialog can't be resized without the style "WS_CAPTION" or "DS_MODALFRAME". So I try to use a transparent window to cover on the custom dialog and control the resizing behavior, that's CResizeWnd.

Using the Code

To use CResizeWnd, just declare CResizeWnd as a member in the dialog.

private:
    CResizeWnd    m_WndResize;

Then, create it at the create time, and send pointer this as parent.

int CResizeWndDemoDlg::OnCreate(LPCREATESTRUCT lpCreateStruct) 
{
    if (CDialog::OnCreate(lpCreateStruct) == -1)
        return -1;

    m_WndResize.Create(this);
    m_WndResize.ShowWindow(SW_SHOW);

    return 0;
}

And remember to fit CResizeWnd to the dialog everytime after it changes size. It will usually be OnInitDialog(), OnSize() and OnMove(). Call SetWindowPos() with the "SWP_NOACTIVATE" to avoid CResizeWnd took dialog focus.

BOOL CResizeWndDemoDlg::OnInitDialog()
{
   ....
   ....
   .... 

   CRect rcWindow;
    GetWindowRect(&rcWindow);
    m_WndResize.SetWindowPos(&wndNoTopMost, rcWindow.left, 
        rcWindow.top, rcWindow.Width(), rcWindow.Height(), SWP_NOACTIVATE);

    return TRUE;  // return TRUE  unless you set the focus to a control
}

void CResizeWndDemoDlg::OnSize(UINT nType, int cx, int cy) 
{
    CRect rcWindow;
    GetWindowRect(&rcWindow);
    m_WndResize.SetWindowPos(&wndNoTopMost, rcWindow.left, 
        rcWindow.top, rcWindow.Width(), rcWindow.Height(), SWP_NOACTIVATE);
}

void CResizeWndDemoDlg::OnMove(int x, int y)
{
    CRect rcWindow;
    GetWindowRect(&rcWindow);
    m_WndResize.SetWindowPos(&wndNoTopMost, rcWindow.left, 
        rcWindow.top, rcWindow.Width(), rcWindow.Height(), SWP_NOACTIVATE);
}

That is very easy to use. And there is a demo in the download list, I left it in a very beginning look from a new MFC project. Hope it will be easier to understand how to make it work.

History

  • 2014-12-22: First published

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here