Visual C++ 7.1Visual C++ 7.0Visual Studio .NET 2003Visual C++ 6.0MFCIntermediateDevVisual StudioWindowsC++
A Spin Edit control with popup trackbar






4.62/5 (14 votes)
Apr 19, 2004
2 min read

94365

3397
An implementation of the spin-edit control used in Jasc Paint Shop Pro
Introduction
I've wanted to post an item for some time, so when I started working on this
component, I decided it was going to be it. The image editing software "Paint
Shop Pro" from Jasc software utilizes a unique combination of an edit, spin, and
trackbar functionality. I decided to try to derive my own version of this and
this is the result. Check the upper left are on the screenshot. I used VS 2003
but I see no reason why it can't be compiled and used with an earlier version.
The only requirement is that IE5 is required because it requires 32 bit calls
such as the GetPos32()
API.
Using the code
Methods
int GetValue()
- Get the current valuevoid SetValue(int nValue)
- Sets the current valueBOOL GetReadOnly()
- Gets the readonly state of the edit fieldvoid SetReadOnly(BOOL fReadOnly)
- Sets the readonly state of the edit fieldvoid GetRange(int& nMin,int& nMax)
- Gets the allowed value rangevoid SetRange(int nMin,int nMax)
- Sets the allowed value range
Styles
NES_SPIN
- Includes the spin controlNES_POPUP
- Includes the button on the far right that pops up a floating trackbarNES_LIVEUPDATE
- Updates the parent about the value while tracking. NEWNES_METER
- Includes the small bar underneath the edit field.NEW
Messages
NEM_GETPOS
- Returns the current value as return valueNEM_SETPOS
- Sets the current value. Passed inLPARAM
NEM_GETRANGE
- Returns allowed range.WPARAM
andLPARAM
are treated as pointers to int'sNEM_SETRANGE
- Sets the allowed range. Min is inWPARAM
and max inLPARAM
NEM_GETREADONLY
- Gets the readonly state of the edit field. NEWNEM_SETREADONLY
- Sets the readonly state of the edit field. NEW
Notifications
NEN_CHANGED
- Sent to the owner window when the value changes
// Declare a CNumericEdit CNumericEdit m_Edit; // // Creating the control // CRect rcRect(10,10,142,40); m_Edit.Create(WS_VISIBLE | WS_TABSTOP | NES_SPIN | NES_POPUP,rcRect,this,0); m_Edit.SetValue(50); m_Edit.SetRange(0,100);
Todo
- Make the popup trackbar size configurable
- XP support ??
- Bitmap in popup trackbar (just like Paint Shop Pro) ?
History
4/13/2004 - 1.0
- Initial version
4/20/2004 - 1.01
- Fixed bug where the edit would only accept hex digits. Also now allow negative sign "-" to be entered
- Added
NES_METER
style to make the small bar under the edit field optional - Control will now reconfigure itself when changing style bits
- Fixed max value bug. The full range is now accesible with the popup
- Added
NES_LIVEUPDATE
style. This style allows the control to notify it's parent during value tracking. Without this style, the parent is updated only at the end of tracking - Demo has been updated to show the new features
- Added
DDX_NumericEdit()
function for DDX support - Now using the active window caption color for the bar colors
- Changed hardcoded custom messages to use windows registered messages so as not to cause any conflict with other custom messages