CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8
  1. #1
    Join Date
    May 2008
    Posts
    6

    progress bar mouse events

    Is there a way to change the position of progress bar with mouse events in mfc?

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: progress bar mouse events

    Just use CProgressCtrl methods to advance the progress bar position (like CProgressCtrl::SetPos and so on).
    Of course, you can call them from any mouse message handler.
    Victor Nijegorodov

  3. #3
    Join Date
    May 2008
    Posts
    6

    Re: progress bar mouse events

    I want to set position with the mouse, at mouse events, the event argument is a point, is there any way to match it to the position of progress bar. I need something lbutton_down event of progress control with the event argument as position, not point.

  4. #4
    Join Date
    Sep 2004
    Location
    Holland (land of the dope)
    Posts
    4,123

    Re: progress bar mouse events

    Have you considered using a CSliderCtrl ? This is made exactly for what you are trying to do.

  5. #5
    Join Date
    May 2008
    Posts
    6

    Re: progress bar mouse events

    yes, I know about slider. as functionality it gives what I want but as view it does not. It does not fill the rect progressively. What I am trying to do is just in between slider and progress controlls. functionality like slider, view as progress bar.

  6. #6
    Join Date
    Sep 2004
    Location
    Holland (land of the dope)
    Posts
    4,123

    Re: progress bar mouse events

    I need something lbutton_down event of progress control with the event argument as position, not point.
    If you know the point, you can calculate the position.

    example:
    The scrollbar has a window clientarea-width of 300.
    You scrollbar goes from 1 to 100.
    300 / 100 = 3. So 3 pixels is 1 position in the scrollbar.
    The mouse point inside the scrollbar window is (12, 3). Ignore the 3, the 12 is the x.
    So the scrollbar position is 12 / (300 / 100) = 4.
    Last edited by Skizmo; April 12th, 2010 at 03:57 PM.

  7. #7
    Join Date
    May 2008
    Posts
    6

    Re: progress bar mouse events

    I think there are two possible solutions;

    1- instead of dragging and dropping a progress bar to the dialog, a custom cprogressctrl class can be added. cprogressctrl class is derived from cwind and it has all the mouse events.
    - add mfc class to the solution
    - choose cprogressctrl as base class
    - add mouse message handlers
    - get point and get range x value (if progressbar is horizontal) and calculate the position in propotion to the width of the progress bar
    -set position of the progress bar and do anything else

    2-drag and drop a progress bar control to the dialog from resouce tool
    -add mouse message handlers of the dialog
    -determine if the point is inside the bounding rect of the progressbar
    -if it is, get point and get range x value (if progressbar is horizontal) and calculate the position in propotion to the width of the progress bar
    -set position of the progress bar and do anything else

    with the mouse messages a progress bar can well be used both as a progress bar and a slider like progressing media tracker

  8. #8
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,620

    Re: progress bar mouse events

    In fact solution 1 will work fine even with dropping a progress bar. You just need to bind a variable to your custom class rather than CProgressCtrl.
    Best regards,
    Igor

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured