Extended Trackbar to get/set position

Defined signal for trackbar position changes
This commit is contained in:
bjorn.olievier 2008-04-07 21:43:44 +00:00
parent fc3d22bfef
commit b976747024
2 changed files with 34 additions and 1 deletions

View File

@ -53,6 +53,7 @@ using namespace win32cpp;
, trackHeight(2)
, thumbHeight(16)
, tickFrequency(0)
, position(0)
{
}
@ -99,6 +100,14 @@ LRESULT Trackbar::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
}
}
break;
case NM_RELEASEDCAPTURE:
{
if (notifyHeader->hwndFrom == this->Handle())
{
this->OnRepositioned();
}
}
break;
}
}
break;
@ -202,6 +211,12 @@ void Trackbar::SetTickFrequency(short tickFrequency)
this->SendMessage(TBM_SETTICFREQ, (WPARAM) this->tickFrequency, NULL);
}
void Trackbar::OnRepositioned()
{
this->position = this->SendMessage(TBM_GETPOS, 0, 0);
this->Repositioned();
}
void Trackbar::SetThumbHeight(short thumbHeight)
{
this->thumbHeight = thumbHeight;
@ -213,3 +228,9 @@ void Trackbar::SetTrackHeight(short trackHeight)
this->trackHeight = trackHeight;
this->Redraw();
}
void Trackbar::SetPosition(short position)
{
this->position = position;
this->SendMessage(TBM_SETPOS, (WPARAM) true, (LPARAM) this->position);
}

View File

@ -54,11 +54,20 @@ enum TrackbarOrientation
/*! */ HorizontalTrack = TBS_HORZ
};
///\brief
///Event used when position on trackbar is changed
///\see
///Trackbar
typedef sigslot::signal0<> TrackbarRepositionedEvent;
///\brief Trackbar allows the user to select a value from a range.
class Trackbar: public Window
{
private: typedef Window base;
///\brief This event is emitted when the position of the slider is changed
public: TrackbarRepositionedEvent Repositioned;
public: /*ctor*/ Trackbar(
short minValue = 0, short maxValue = 100,
TrackbarOrientation orientation = HorizontalTrack);
@ -72,16 +81,19 @@ public: void SetTrackHeight(short trackHeight);
public: short TrackHeight() { return this->trackHeight; }
public: void SetThumbHeight(short thumbHeight);
public: short ThumbHeight() { return this->thumbHeight; }
public: void SetPosition(short position);
public: short Position() const { return this->position; }
// private api
protected: virtual HWND Create(Window* parent);
protected: virtual void OnEraseBackground(HDC hdc);
protected: virtual void OnPaint();
protected: virtual void OnCreated();
protected: virtual void OnRepositioned();
protected: virtual LRESULT OnCustomDraw(NMCUSTOMDRAW& customDraw);
protected: virtual LRESULT WindowProc(UINT message, WPARAM wParam, LPARAM lParam);
protected: short minValue, maxValue, tickFrequency;
protected: short minValue, maxValue, tickFrequency, position;
protected: short trackHeight, thumbHeight;
protected: TrackbarOrientation orientation;
};