From b976747024097a7dcf3c05081133d9f9f809e869 Mon Sep 17 00:00:00 2001 From: "bjorn.olievier" Date: Mon, 7 Apr 2008 21:43:44 +0000 Subject: [PATCH] Extended Trackbar to get/set position Defined signal for trackbar position changes --- src/win32cpp/Trackbar.cpp | 21 +++++++++++++++++++++ src/win32cpp/Trackbar.hpp | 14 +++++++++++++- 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/src/win32cpp/Trackbar.cpp b/src/win32cpp/Trackbar.cpp index ab576a69e..96bc56cfc 100644 --- a/src/win32cpp/Trackbar.cpp +++ b/src/win32cpp/Trackbar.cpp @@ -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); +} diff --git a/src/win32cpp/Trackbar.hpp b/src/win32cpp/Trackbar.hpp index c30536c82..88a19d9b7 100644 --- a/src/win32cpp/Trackbar.hpp +++ b/src/win32cpp/Trackbar.hpp @@ -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; };