Moving controls within the dialog.
-
hi i want to move button control on mouse LButton down with no Resize and position must be saved within the dialog. How it can be done.
First, commas, full-stops and semicolons has a meaning also in natural langage: Your question can be: "hi, I want to move A button control on mouse LButton down, with no Resize; position must be saved within the dialog. How it can be done?" or "hi I want to move button controls on mouse LButton down with no Resize and position. Must be saved within the dialog. How it can be done?" And they are quite different questions. Assuming the first, since a control is a window, just use
MoveWindow
(note: mouse coordinates are obtained in screen coordinates, while move window requires parent client coordinates, so do the proper translation withScreenToClient
). I don't understand what you mean with "saved within the dialog": if you mean "saved within the dialog RESOURCE", then give a look to http://msdn.microsoft.com/en-us/library/ms648004(v=VS.85).aspx[^]. Consider also that, unless you are writing a "resource management tool", modifying the resource result in modifying the "exe", and this is not, in general, a good idea: what does it happen if multiple users attempt to to modify your "exe" if it is shared across a network? It is better to save the control positions in a file stored in a user specific directory (you can get the path withSHGetFolderPath
, givingCSIDL_APPDATA
as a CSIDL) and, when loading the dialog, change the controls positions (again, withMoveWindow
) accordingly to such file (if existent) before showing the dialog.2 bugs found. > recompile ... 65534 bugs found. :doh:
-
hi i want to move button control on mouse LButton down with no Resize and position must be saved within the dialog. How it can be done.
jiya-123 wrote:
hi i want to move button control on mouse LButton down with no Resize
Use
MoveWindow
[^] orSetWindowPos
[^].jiya-123 wrote:
position must be saved within the dialog.
To make new position persistent, you may store coordinate values in a configuration file. :)
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles] -
hi i want to move button control on mouse LButton down with no Resize and position must be saved within the dialog. How it can be done.
Well, what's actually stopping you? I can see a few steps: First, you need this to toggle on and off. If it was on all the time, anyone using this dialog will hate you. "I just tried to press OK, but the damn button keeps moving!" You'll need to subclass your button(s), and override WM_LBUTTONDOWN,WM_MOUSEMOVE,WM_LBUTTONUP. For the button messages, either pass them on as normal, or toggle a "I'm dragging flag". In the mouse button, subtract the current position from the last position, and move the window by that much. Something like:
void CMyMovableButton::OnMouseMove (UINT fFlags, CPoint ptMouse)
{
// Translate point into parent coords
if (m_bDragging) // toggles in OnLButtonDown/Up
{
CWnd *pParent = GetParent ();
// Translate coords to parent coords.
MapWindowPoints (pParent, &ptMouse, 1);
CPoint ptDelta = ptMouse - m_ptMouseLast; // you did save the lbutton down position, I hope!
MoveWindow (ptDelta.x, ptDelta.y);
SetWindowPos (NULL, ptDelta.x, ptDelta.y, 0,0, SWP_NOSIZE | SWP_NOZORDER);
m_ptMouseLast = ptMouse;
}
else
__super::OnMouseMove (fFlags, ptMouse);
}You'll also need to store all your window positions when the dialog closes (or store them whenever a control has finished moving) so that you can use that information next time the dialog is used. Maybe make structure full of CPOints (ie, ptOKButton, ptCancelButton) and save that in the registry for use in you CMyMovableDlg::OnInitDialog function? You might also want to look at CDiagramEditor - DIY vector and dialog editor[^] for an alternate way of doing all this. It sounds like you have a lot of work ahead of you - and I know no shortcut. I hope you have a strong business case for this, and not just "wouldn't it be cool?" Maybe when you're done, you could write an article based on it? Good luck, Iain.
I have now moved to Sweden for love (awwww).
-
hi i want to move button control on mouse LButton down with no Resize and position must be saved within the dialog. How it can be done.