Is there a way to change the position of progress bar with mouse events in mfc?
Printable View
Is there a way to change the position of progress bar with mouse events in mfc?
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.
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.
Have you considered using a CSliderCtrl ? This is made exactly for what you are trying to do.
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.
If you know the point, you can calculate the position.Quote:
I need something lbutton_down event of progress control with the event argument as position, not point.
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.
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
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.