Moving controls on a dialog
-
I'm writing an app that I want to be able to dynamically move some controls around on my dialog box. I was thinking of simply using ::GetWindowRect() and ::MoveWindow() to do that, but for those functions I need the window handle (HWND). Can the member variable connected to those controls work as the window handle, or houw can this be done? Danny
-
I'm writing an app that I want to be able to dynamically move some controls around on my dialog box. I was thinking of simply using ::GetWindowRect() and ::MoveWindow() to do that, but for those functions I need the window handle (HWND). Can the member variable connected to those controls work as the window handle, or houw can this be done? Danny
bugDanny wrote: Can the member variable connected to those controls work as the window handle, or houw can this be done? Why not just use
CWnd::GetWindowRect()
andCWnd::MoveWindow()
? No handle required.
"One must learn from the bite of the fire to leave it alone." - Native American Proverb
-
I'm writing an app that I want to be able to dynamically move some controls around on my dialog box. I was thinking of simply using ::GetWindowRect() and ::MoveWindow() to do that, but for those functions I need the window handle (HWND). Can the member variable connected to those controls work as the window handle, or houw can this be done? Danny
You can use control variable associated with it.Alternatively ,Use GetDlgItem() for getting control windows and use those.
-
I'm writing an app that I want to be able to dynamically move some controls around on my dialog box. I was thinking of simply using ::GetWindowRect() and ::MoveWindow() to do that, but for those functions I need the window handle (HWND). Can the member variable connected to those controls work as the window handle, or houw can this be done? Danny
Most controls are directly derived from CWnd, in which case you can use the CWnd member function of
::GetWindowRect()
and::MoveWindow()
, meaning :RECT rect;
m_mycontrol.GetWindowRect(&rect);If you absolutley want to use the upper scope functions, you can retrieve the HWND using
GetSafeHwnd()
HWND hWnd = m_mycontrol.GetSafeHwnd()
BTW, you might want to consider also
GetClientRect()
, as well asScreenToClient()
andClientToScreen()
to play around moving controls, because I am afraid that the two functions you mentioned will not be sufficient. Hope this helps, ~RaGE(); -
You can use control variable associated with it.Alternatively ,Use GetDlgItem() for getting control windows and use those.
Depending on what you want to do, there is also some nice articles on here for dynamically moving all controls when resizing dialogues. I tend to map controsl to control variables and use their own move methods, eg: m_btnOK.MoveWindow(...); Rather than: pWnd = GetDlgItem(IDOK) if(pWnd != NULL) pWnd->MoveWindow(...) Mapping variables to the controls uses less code and no need to worry about correct id values, null pointers etc. HTH. Andrew
-
I'm writing an app that I want to be able to dynamically move some controls around on my dialog box. I was thinking of simply using ::GetWindowRect() and ::MoveWindow() to do that, but for those functions I need the window handle (HWND). Can the member variable connected to those controls work as the window handle, or houw can this be done? Danny