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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Need help on how to move line between two horizontal sliders with slider position [modified]

Need help on how to move line between two horizontal sliders with slider position [modified]

Scheduled Pinned Locked Moved C / C++ / MFC
helptutorial
12 Posts 2 Posters 1 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.
  • J Offline
    J Offline
    John502
    wrote on last edited by
    #1

    Hi, I want to move one line between two horizontal sliders, with respect to slider position... I am able to move slider tic, but not able to move line to exact sliders tic... Is there any way to get pixels information from the slider control.. If so please kindly let me know ... It is very urgent requirement for me.. Thanks in advance..

    modified on Tuesday, February 17, 2009 10:17 AM

    _ 1 Reply Last reply
    0
    • J John502

      Hi, I want to move one line between two horizontal sliders, with respect to slider position... I am able to move slider tic, but not able to move line to exact sliders tic... Is there any way to get pixels information from the slider control.. If so please kindly let me know ... It is very urgent requirement for me.. Thanks in advance..

      modified on Tuesday, February 17, 2009 10:17 AM

      _ Offline
      _ Offline
      _Superman_
      wrote on last edited by
      #2

      It should be possible to use GetWindowRect on the slider control to get the total width of the slider and then the GetPos method to get the current tic position to calculate the width of the line you want to draw.

      «_Superman_»

      J 2 Replies Last reply
      0
      • _ _Superman_

        It should be possible to use GetWindowRect on the slider control to get the total width of the slider and then the GetPos method to get the current tic position to calculate the width of the line you want to draw.

        «_Superman_»

        J Offline
        J Offline
        John502
        wrote on last edited by
        #3

        Hi, I have tried with your solution, I am calling m_pDlg->m_slider_bar1.GetWindowRect(&rect1); this control from my app for getting pixels position. after that i am trying to change the slider position like below mentioned way: int pos = m_pDlg->m_slider_bar1.GetPos(); m_pDlg->m_slider_bar1.SetPos(slide_pos); m_pDlg->m_slider_bar2.SetPos(slide_pos); every time i am getting rectangle pixels like :- 86,110,283,565 only. how i have to move line now to moved position. please kindly help me regarding this.. Thanks in advance..

        modified on Tuesday, February 17, 2009 10:18 AM

        _ 1 Reply Last reply
        0
        • _ _Superman_

          It should be possible to use GetWindowRect on the slider control to get the total width of the slider and then the GetPos method to get the current tic position to calculate the width of the line you want to draw.

          «_Superman_»

          J Offline
          J Offline
          John502
          wrote on last edited by
          #4

          Hi Can you please kindly help me on this ASAP, as it is very urgent requirement for me..

          1 Reply Last reply
          0
          • J John502

            Hi, I have tried with your solution, I am calling m_pDlg->m_slider_bar1.GetWindowRect(&rect1); this control from my app for getting pixels position. after that i am trying to change the slider position like below mentioned way: int pos = m_pDlg->m_slider_bar1.GetPos(); m_pDlg->m_slider_bar1.SetPos(slide_pos); m_pDlg->m_slider_bar2.SetPos(slide_pos); every time i am getting rectangle pixels like :- 86,110,283,565 only. how i have to move line now to moved position. please kindly help me regarding this.. Thanks in advance..

            modified on Tuesday, February 17, 2009 10:18 AM

            _ Offline
            _ Offline
            _Superman_
            wrote on last edited by
            #5

            If slider range has been set from 0 to 100 and SetPos returns 50, you know that it is 50%. So the position of the tic is at (283 - 86) / 2. Now you can do a MoveTo and LineTo from X1 which is ((283 - 86) / 2, bottom of slider1) to X2 which is at ((283 - 86) / 2, top of slider 2).

            «_Superman_»

            J 1 Reply Last reply
            0
            • _ _Superman_

              If slider range has been set from 0 to 100 and SetPos returns 50, you know that it is 50%. So the position of the tic is at (283 - 86) / 2. Now you can do a MoveTo and LineTo from X1 which is ((283 - 86) / 2, bottom of slider1) to X2 which is at ((283 - 86) / 2, top of slider 2).

              «_Superman_»

              J Offline
              J Offline
              John502
              wrote on last edited by
              #6

              Hi Superman, I have written the code like this, but still it's not working while (slide_pos <= 100) { m_pDlg->m_slider_bar1.GetWindowRect(&rect1); m_pDlg->m_slider_bar2.GetWindowRect(&rect2); int pos = m_pDlg->m_slider_bar1.GetPos(); m_pDlg->x1 = ((rect1.left-rect1.top)/100); m_pDlg->y1 = rect1.bottom; m_pDlg->x1 = ((rect1.left-rect1.top)/100); m_pDlg->y2 = rect2.top; m_pDlg->m_slider_bar1.SetPos(slide_pos); m_pDlg->m_slider_bar2.SetPos(slide_pos); slide_pos = slide_pos + 5; m_pDlg->InvalidateRect(NULL); Sleep(1000); } rect1 values are :- top=86,bottom=110,left=283,right=565 rect2 values are :- top=259,bottom=283,left=283, right=565. Can you please look into the code what i have written and let me know where i did wrong..?

              modified on Tuesday, February 17, 2009 10:18 AM

              _ 1 Reply Last reply
              0
              • J John502

                Hi Superman, I have written the code like this, but still it's not working while (slide_pos <= 100) { m_pDlg->m_slider_bar1.GetWindowRect(&rect1); m_pDlg->m_slider_bar2.GetWindowRect(&rect2); int pos = m_pDlg->m_slider_bar1.GetPos(); m_pDlg->x1 = ((rect1.left-rect1.top)/100); m_pDlg->y1 = rect1.bottom; m_pDlg->x1 = ((rect1.left-rect1.top)/100); m_pDlg->y2 = rect2.top; m_pDlg->m_slider_bar1.SetPos(slide_pos); m_pDlg->m_slider_bar2.SetPos(slide_pos); slide_pos = slide_pos + 5; m_pDlg->InvalidateRect(NULL); Sleep(1000); } rect1 values are :- top=86,bottom=110,left=283,right=565 rect2 values are :- top=259,bottom=283,left=283, right=565. Can you please look into the code what i have written and let me know where i did wrong..?

                modified on Tuesday, February 17, 2009 10:18 AM

                _ Offline
                _ Offline
                _Superman_
                wrote on last edited by
                #7

                It looks like I have mis-interpreted your question. Let me try and get it right. You have 2 sliders. When one of the slider is moved you want the other one also to move along. Is that what you need?

                «_Superman_»

                J 1 Reply Last reply
                0
                • _ _Superman_

                  It looks like I have mis-interpreted your question. Let me try and get it right. You have 2 sliders. When one of the slider is moved you want the other one also to move along. Is that what you need?

                  «_Superman_»

                  J Offline
                  J Offline
                  John502
                  wrote on last edited by
                  #8

                  Hi, Yes that is only the part of my requirement. I have two horizontal sliders on my dialog. Now i want to create one verical line in between the two sliders. Whenever i have clicked on Start button then slider tics will get moved and incremented by 5, i am able to move two slider tics at the same time. but now what i want is to move line along with the tics. I am not able the slider position where it is exactly moved in terms of pixels.

                  modified on Tuesday, February 17, 2009 10:29 AM

                  _ 1 Reply Last reply
                  0
                  • J John502

                    Hi, Yes that is only the part of my requirement. I have two horizontal sliders on my dialog. Now i want to create one verical line in between the two sliders. Whenever i have clicked on Start button then slider tics will get moved and incremented by 5, i am able to move two slider tics at the same time. but now what i want is to move line along with the tics. I am not able the slider position where it is exactly moved in terms of pixels.

                    modified on Tuesday, February 17, 2009 10:29 AM

                    _ Offline
                    _ Offline
                    _Superman_
                    wrote on last edited by
                    #9

                    You can get the (x1, y1) and (x2, y2) positions for drawing the line using the following code

                    m_slider1.GetThumbRect(&rect1);
                    m_slider2.GetThumbRect(&rect2);

                    m_slider1.ClientToScreen(&rect1);
                    m_slider2.ClientToScreen(&rect2);

                    ScreenToClient(&rect1);
                    ScreenToClient(&rect2);

                    int x1 = rect1.left + ((rect1.right - rect1.left) / 2);
                    int y1 = rect1.bottom;
                    int x2 = x1;
                    int y2 = rect2.top;

                    Then you can draw the line using the following code

                    CDC* pDC = GetDC();

                    CPen pen(PS_SOLID, 1, RGB(0, 0, 0));
                    pDC->SelectObject(&pen);

                    pDC->MoveTo(x1, y1);
                    pDC->LineTo(x2, y2);

                    ReleaseDC(pDC);

                    You may need to erase the previously drawn line. For that you will need to store the previous line coordinates and draw over it using the same color of the dialog.

                    «_Superman_»

                    J 1 Reply Last reply
                    0
                    • _ _Superman_

                      You can get the (x1, y1) and (x2, y2) positions for drawing the line using the following code

                      m_slider1.GetThumbRect(&rect1);
                      m_slider2.GetThumbRect(&rect2);

                      m_slider1.ClientToScreen(&rect1);
                      m_slider2.ClientToScreen(&rect2);

                      ScreenToClient(&rect1);
                      ScreenToClient(&rect2);

                      int x1 = rect1.left + ((rect1.right - rect1.left) / 2);
                      int y1 = rect1.bottom;
                      int x2 = x1;
                      int y2 = rect2.top;

                      Then you can draw the line using the following code

                      CDC* pDC = GetDC();

                      CPen pen(PS_SOLID, 1, RGB(0, 0, 0));
                      pDC->SelectObject(&pen);

                      pDC->MoveTo(x1, y1);
                      pDC->LineTo(x2, y2);

                      ReleaseDC(pDC);

                      You may need to erase the previously drawn line. For that you will need to store the previous line coordinates and draw over it using the same color of the dialog.

                      «_Superman_»

                      J Offline
                      J Offline
                      John502
                      wrote on last edited by
                      #10

                      Hi Superman, Thanks for your effort on this..I am able to move slider position correctly, but not able to move along with the sliders, below i am copying my code snippet, please review it and let me know where i am doing wrong..? Below code i have written in OnStart funciton():- int slider_pos = 5; while(slider_pos <= 50) { m_slider1.GetThumbRect(&rect1); m_slider2.GetThumbRect(&rect2); m_slider1.ClientToScreen(&rect1); m_slider2.ClientToScreen(&rect2); ScreenToClient(&rect1); ScreenToClient(&rect2); m_slider1.SetPos(slider_pos); m_slider2.SetPos(slider_pos); int x1 = rect1.left + ((rect1.right - rect1.left) / 2); int y1 = rect1.bottom; int x2 = x1; int y2 = rect2.top; slider_pos += 5; InvalidateRect(rect1,FALSE); InvalidateRect(rect2,FALSE); Sleep(1000); } Below i have written in OnPaint() CDC* pDC = GetDC(); pDC->MoveTo(old_x1,old_y1); pDC->LineTo(old_x2,old_y2); pDC->MoveTo(x1,y1); pDC->LineTo(x2,y2); old_x1 = x1; old_y1 = y1; old_x2 = x2; old_y2 = y2; Please help me regarding this..? Thanks in advance..

                      _ 1 Reply Last reply
                      0
                      • J John502

                        Hi Superman, Thanks for your effort on this..I am able to move slider position correctly, but not able to move along with the sliders, below i am copying my code snippet, please review it and let me know where i am doing wrong..? Below code i have written in OnStart funciton():- int slider_pos = 5; while(slider_pos <= 50) { m_slider1.GetThumbRect(&rect1); m_slider2.GetThumbRect(&rect2); m_slider1.ClientToScreen(&rect1); m_slider2.ClientToScreen(&rect2); ScreenToClient(&rect1); ScreenToClient(&rect2); m_slider1.SetPos(slider_pos); m_slider2.SetPos(slider_pos); int x1 = rect1.left + ((rect1.right - rect1.left) / 2); int y1 = rect1.bottom; int x2 = x1; int y2 = rect2.top; slider_pos += 5; InvalidateRect(rect1,FALSE); InvalidateRect(rect2,FALSE); Sleep(1000); } Below i have written in OnPaint() CDC* pDC = GetDC(); pDC->MoveTo(old_x1,old_y1); pDC->LineTo(old_x2,old_y2); pDC->MoveTo(x1,y1); pDC->LineTo(x2,y2); old_x1 = x1; old_y1 = y1; old_x2 = x2; old_y2 = y2; Please help me regarding this..? Thanks in advance..

                        _ Offline
                        _ Offline
                        _Superman_
                        wrote on last edited by
                        #11

                        You are using x1, y1, x2 and y2 in 2 functions. I'm assuming you're creating the variables as member variables. If so remove the int keyword from within the while loop. Also, in OnPaint you must call BeginPaint instead of GetDC. And instead of 2 InvalidateRect calls, do a single Invalidate call.

                        «_Superman_»

                        J 1 Reply Last reply
                        0
                        • _ _Superman_

                          You are using x1, y1, x2 and y2 in 2 functions. I'm assuming you're creating the variables as member variables. If so remove the int keyword from within the while loop. Also, in OnPaint you must call BeginPaint instead of GetDC. And instead of 2 InvalidateRect calls, do a single Invalidate call.

                          «_Superman_»

                          J Offline
                          J Offline
                          John502
                          wrote on last edited by
                          #12

                          Hi, I made these changes, PAINTSTRUCT ps; CDC* paintDC = BeginPaint(&ps); //paintDC->MoveTo(old_x1,old_y1); //paintDC->LineTo(old_x2,old_y2); paintDC->MoveTo(x1,y1); paintDC->LineTo(x2,y2); old_x1 = x1; old_y1 = y1; old_x2 = x2; old_y2 = y2; EndPaint(&ps); but line is displaying at last slider position, that to in wrong pixels.. can you please tell me where i am doing wrong..? Thnaks 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