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; }
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