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. How to pan client area of a window using C++/VC++ code

How to pan client area of a window using C++/VC++ code

Scheduled Pinned Locked Moved C / C++ / MFC
c++jsontutorial
13 Posts 3 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.
  • U Offline
    U Offline
    User 9307625
    wrote on last edited by
    #1

    HI, Is there any API available to Pan a window, as we can in autocad/pdf file/Pro-e. If not, how pan a window using C++ code. Regards, Maha

    P S 3 Replies Last reply
    0
    • U User 9307625

      HI, Is there any API available to Pan a window, as we can in autocad/pdf file/Pro-e. If not, how pan a window using C++ code. Regards, Maha

      P Offline
      P Offline
      pasztorpisti
      wrote on last edited by
      #2

      What do you mean on panning? Moving? Or scrolling the contents of the displayed stuff?

      U 1 Reply Last reply
      0
      • U User 9307625

        HI, Is there any API available to Pan a window, as we can in autocad/pdf file/Pro-e. If not, how pan a window using C++ code. Regards, Maha

        S Offline
        S Offline
        Software_Developer
        wrote on last edited by
        #3

        There is an article about that right [here].

        U 1 Reply Last reply
        0
        • U User 9307625

          HI, Is there any API available to Pan a window, as we can in autocad/pdf file/Pro-e. If not, how pan a window using C++ code. Regards, Maha

          P Offline
          P Offline
          pasztorpisti
          wrote on last edited by
          #4

          I guess I know what you mean: You press down the pan mouse button while the cursor is over the view and then you pan by moving the mouse cursor until you release the pan mouse button. This panning basically scrolls the visible portion of the stuff you can see in your view. There is no API to do that, you have to implement it by yourself by handling primitive mouse events like mouse button down, mouse move, and mouse button up events. Custom implementation makes sense because its totally dependent on the program which parameters should be modified by the panning operation. In a 2D pdf viewer the program stores some position data about which part of the pdf should be drawn to the view. This position is changed when you are panning. In a 3D CAD program there is a 3d world in which you can find an active camera as well with a position and rotation parameter (and also with horizontal and vertical fov). This camera is used by the rednerer to decide which part of the world should be rendered, the camera is like an eye and you see in the view what this eye looks at in the 3d world. This camera has an up and right direction that defines a plane. When you pan with your mouse you basically calculate a 2D offset from the mouse movement and you add this 2D offset to the camera position on the plane that is defined by the up and right vectors of the camera rotation (maybe not right but left if you are using left handed coordinate system...). Even if you are not good at 3D, the answer to your question is: Those pan functions are implemented by those programs, its custom code in them and not some operating system provided api function calls. How to implement panning: When panning starts (mouse button down) you store the actual pan-start position of the mouse cursor, and also the position value (the 3d cam pos, or the 2d pos in the pdf file) in your program to some variables that wont change during panning. When a mouse move event comes you always calculate the delta between the pan-start mouse pos and the current moved mouse cursor pos, and you use this 2D offset to calculate the pan offset in your world (you can leave it as it is, or any simple transform can do the job, for example multiplying it with something to set panning speed...). When you have your pan offset you add the resulting pan-offset to the stored pan-start position and set the result as the current position. The panning operation is a kind of dragging operation so you should consider implementing it with correct mouse capturing:

          U 1 Reply Last reply
          0
          • P pasztorpisti

            I guess I know what you mean: You press down the pan mouse button while the cursor is over the view and then you pan by moving the mouse cursor until you release the pan mouse button. This panning basically scrolls the visible portion of the stuff you can see in your view. There is no API to do that, you have to implement it by yourself by handling primitive mouse events like mouse button down, mouse move, and mouse button up events. Custom implementation makes sense because its totally dependent on the program which parameters should be modified by the panning operation. In a 2D pdf viewer the program stores some position data about which part of the pdf should be drawn to the view. This position is changed when you are panning. In a 3D CAD program there is a 3d world in which you can find an active camera as well with a position and rotation parameter (and also with horizontal and vertical fov). This camera is used by the rednerer to decide which part of the world should be rendered, the camera is like an eye and you see in the view what this eye looks at in the 3d world. This camera has an up and right direction that defines a plane. When you pan with your mouse you basically calculate a 2D offset from the mouse movement and you add this 2D offset to the camera position on the plane that is defined by the up and right vectors of the camera rotation (maybe not right but left if you are using left handed coordinate system...). Even if you are not good at 3D, the answer to your question is: Those pan functions are implemented by those programs, its custom code in them and not some operating system provided api function calls. How to implement panning: When panning starts (mouse button down) you store the actual pan-start position of the mouse cursor, and also the position value (the 3d cam pos, or the 2d pos in the pdf file) in your program to some variables that wont change during panning. When a mouse move event comes you always calculate the delta between the pan-start mouse pos and the current moved mouse cursor pos, and you use this 2D offset to calculate the pan offset in your world (you can leave it as it is, or any simple transform can do the job, for example multiplying it with something to set panning speed...). When you have your pan offset you add the resulting pan-offset to the stored pan-start position and set the result as the current position. The panning operation is a kind of dragging operation so you should consider implementing it with correct mouse capturing:

            U Offline
            U Offline
            User 9307625
            wrote on last edited by
            #5

            Hello!! Thank you very much for all your reply. Mr pasztorpisti - Thank you much for detailed explanation. I will try to implement this and let you know about the same. -Maha

            P 1 Reply Last reply
            0
            • U User 9307625

              Hello!! Thank you very much for all your reply. Mr pasztorpisti - Thank you much for detailed explanation. I will try to implement this and let you know about the same. -Maha

              P Offline
              P Offline
              pasztorpisti
              wrote on last edited by
              #6

              You are welcome!

              U 1 Reply Last reply
              0
              • P pasztorpisti

                You are welcome!

                U Offline
                U Offline
                User 9307625
                wrote on last edited by
                #7

                HI Pasztorpisti, What the code you have give is to move the window, but what i need to move the client area. I know if there is a api to capture the client area and move it. Regards, Maha

                P 1 Reply Last reply
                0
                • P pasztorpisti

                  What do you mean on panning? Moving? Or scrolling the contents of the displayed stuff?

                  U Offline
                  U Offline
                  User 9307625
                  wrote on last edited by
                  #8

                  Yes, just need to move content and not the window.

                  1 Reply Last reply
                  0
                  • U User 9307625

                    HI Pasztorpisti, What the code you have give is to move the window, but what i need to move the client area. I know if there is a api to capture the client area and move it. Regards, Maha

                    P Offline
                    P Offline
                    pasztorpisti
                    wrote on last edited by
                    #9

                    You have to do exactly the same. You handle the mouse events, and depending on the offset of the mouse move you change an internal variable in your program. In my example program the internal variable to change was the position of the window, but it could be anything else, for example the offset in your picture or pdf file for drawing on the client area of your window. All you have to do is using/changing something else, not the window position, for example the position where you draw your picture on the client area.

                    U 1 Reply Last reply
                    0
                    • P pasztorpisti

                      You have to do exactly the same. You handle the mouse events, and depending on the offset of the mouse move you change an internal variable in your program. In my example program the internal variable to change was the position of the window, but it could be anything else, for example the offset in your picture or pdf file for drawing on the client area of your window. All you have to do is using/changing something else, not the window position, for example the position where you draw your picture on the client area.

                      U Offline
                      U Offline
                      User 9307625
                      wrote on last edited by
                      #10

                      In your program you have used SetWindowPos() to change the position of window. But to move the client area, which API should i use. Say, Mouse button down 1) capture initial position of mouse using GetCursorPos() Mouse move. 2) Calculate the difference of x and y coordinates using previous cursor position and current cursor position Mouse button UP 3)After calculating the latest value as said about, which api should be used to move the client coordinates. (in your program you have used SetWindowPos()) -Maha

                      P 1 Reply Last reply
                      0
                      • U User 9307625

                        In your program you have used SetWindowPos() to change the position of window. But to move the client area, which API should i use. Say, Mouse button down 1) capture initial position of mouse using GetCursorPos() Mouse move. 2) Calculate the difference of x and y coordinates using previous cursor position and current cursor position Mouse button UP 3)After calculating the latest value as said about, which api should be used to move the client coordinates. (in your program you have used SetWindowPos()) -Maha

                        P Offline
                        P Offline
                        pasztorpisti
                        wrote on last edited by
                        #11

                        What do you mean on moving the client area? You can't move it. All you can do is drawing something on it and changing some of the parameters of the drawing when you are panning. Alternatively you could change the positions of some child controls on the window but that has not much usefulness.

                        U 1 Reply Last reply
                        0
                        • S Software_Developer

                          There is an article about that right [here].

                          U Offline
                          U Offline
                          User 9307625
                          wrote on last edited by
                          #12

                          I want to pan the client area using left button of mouse. As one that works with PDF file. And i want to implement this using MFC/WIN32 -Thanks in advance.

                          1 Reply Last reply
                          0
                          • P pasztorpisti

                            What do you mean on moving the client area? You can't move it. All you can do is drawing something on it and changing some of the parameters of the drawing when you are panning. Alternatively you could change the positions of some child controls on the window but that has not much usefulness.

                            U Offline
                            U Offline
                            User 9307625
                            wrote on last edited by
                            #13

                            I cant achieve this still, can any one of you give me a sample code. To pan the client area of a window. Thanks in advance.

                            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