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 a window

Moving a window

Scheduled Pinned Locked Moved C / C++ / MFC
tutorial
8 Posts 6 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.
  • K Offline
    K Offline
    kk tvm
    wrote on last edited by
    #1

    Hi friends How to move a window using its mousemove function thanx

    -RisKhan-

    H C 2 Replies Last reply
    0
    • K kk tvm

      Hi friends How to move a window using its mousemove function thanx

      -RisKhan-

      H Offline
      H Offline
      Hamid Taebi
      wrote on last edited by
      #2

      You can use of MoveWindow.

      1 Reply Last reply
      0
      • K kk tvm

        Hi friends How to move a window using its mousemove function thanx

        -RisKhan-

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

        do you mean you want to move your window by dragging it by clicking on anywhere on the dialog?

        K 1 Reply Last reply
        0
        • C chandu004

          do you mean you want to move your window by dragging it by clicking on anywhere on the dialog?

          K Offline
          K Offline
          kk tvm
          wrote on last edited by
          #4

          yes

          -RisKhan-

          P M 2 Replies Last reply
          0
          • K kk tvm

            yes

            -RisKhan-

            P Offline
            P Offline
            pierre_ribery
            wrote on last edited by
            #5

            Handle WM_NCHITTEST and always return HTCAPTION.

            O 1 Reply Last reply
            0
            • P pierre_ribery

              Handle WM_NCHITTEST and always return HTCAPTION.

              O Offline
              O Offline
              ovidiucucu
              wrote on last edited by
              #6

              Just a little aside note. "Moving your window by dragging it by clicking on anywhere on the dialog" is OK in one particular case: it has no menu, no system menu, no maximize/minimize/close button, no scrollbars and is not resizeable. Returning always HTCAPTION from WM_NCHITTEST message handler leads in the impossibility of using menus,... and all enumerated above. A little bit better approach is to apply the trick only for the client area. Here is an example:

              UINT CMyDialog::OnNcHitTest(CPoint point) 
              {
                 UINT nRet = CDialog::OnNcHitTest(point);
                 if(HTCLIENT == nRet)
                 {
                    nRet = HTCAPTION;
                 }
                 return nRet;
              }
              

              Ovidiu Cucu Microsoft MVP - Visual C++

              K 1 Reply Last reply
              0
              • K kk tvm

                yes

                -RisKhan-

                M Offline
                M Offline
                Marimuthu r
                wrote on last edited by
                #7

                Add the following line of code in your LButton Down handler. PostMessage(WM_NCLBUTTONDOWN, HTCAPTION, MAKELPARAM(point.x, point.y));

                1 Reply Last reply
                0
                • O ovidiucucu

                  Just a little aside note. "Moving your window by dragging it by clicking on anywhere on the dialog" is OK in one particular case: it has no menu, no system menu, no maximize/minimize/close button, no scrollbars and is not resizeable. Returning always HTCAPTION from WM_NCHITTEST message handler leads in the impossibility of using menus,... and all enumerated above. A little bit better approach is to apply the trick only for the client area. Here is an example:

                  UINT CMyDialog::OnNcHitTest(CPoint point) 
                  {
                     UINT nRet = CDialog::OnNcHitTest(point);
                     if(HTCLIENT == nRet)
                     {
                        nRet = HTCAPTION;
                     }
                     return nRet;
                  }
                  

                  Ovidiu Cucu Microsoft MVP - Visual C++

                  K Offline
                  K Offline
                  kk tvm
                  wrote on last edited by
                  #8

                  Thanks Mr. Ovidiu Cucu It works fine !!! But another problem, i like to move window in one direction ( in Horizontal only, y value is same), is it possible ?

                  -RisKhan-

                  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