Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Moving controls within the dialog.

Moving controls within the dialog.

Scheduled Pinned Locked Moved C / C++ / MFC
5 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    shiv nand
    wrote on last edited by
    #1

    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.

    E C I S 4 Replies Last reply
    0
    • S shiv nand

      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.

      E Offline
      E Offline
      Emilio Garavaglia
      wrote on last edited by
      #2

      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 with ScreenToClient). 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 with SHGetFolderPath, giving CSIDL_APPDATA as a CSIDL) and, when loading the dialog, change the controls positions (again, with MoveWindow) accordingly to such file (if existent) before showing the dialog.

      2 bugs found. > recompile ... 65534 bugs found. :doh:

      1 Reply Last reply
      0
      • S shiv nand

        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.

        C Offline
        C Offline
        CPallini
        wrote on last edited by
        #3

        jiya-123 wrote:

        hi i want to move button control on mouse LButton down with no Resize

        Use MoveWindow [^] or SetWindowPos [^].

        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]

        1 Reply Last reply
        0
        • S shiv nand

          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.

          I Offline
          I Offline
          Iain Clarke Warrior Programmer
          wrote on last edited by
          #4

          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).

          1 Reply Last reply
          0
          • S shiv nand

            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.

            S Offline
            S Offline
            SandipG
            wrote on last edited by
            #5

            Are you looking for Control Tracker[^] I hope it helps.

            Regards, Sandip.

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups