Click here to Skip to main content
6,291,522 members and growing! (13,051 online)
Email Password   helpLost your password?
Desktop Development » Miscellaneous » Custom Controls     Intermediate

A Spin Edit control with popup trackbar

By John Gonzalez

An implementation of the spin-edit control used in Jasc Paint Shop Pro
VC6, VC7, VC7.1, Windows, MFC, VS.NET2003, Dev
Posted:18 Apr 2004
Updated:22 Apr 2004
Views:46,062
Bookmarked:17 times
Announcements
Loading...
 
Search    
Advanced Search
printPrint   Broken Article?Report       add Share
  Discuss Discuss   Recommend Article Email
15 votes for this article.
Popularity: 5.14 Rating: 4.37 out of 5
2 votes, 13.3%
1
1 vote, 6.7%
2
2 votes, 13.3%
3
3 votes, 20.0%
4
7 votes, 46.7%
5

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 value
  • void SetValue(int nValue) - Sets the current value
  • BOOL GetReadOnly() - Gets the readonly state of the edit field
  • void SetReadOnly(BOOL fReadOnly) - Sets the readonly state of the edit field
  • void GetRange(int& nMin,int& nMax) - Gets the allowed value range
  • void SetRange(int nMin,int nMax) - Sets the allowed value range

Styles

  • NES_SPIN - Includes the spin control
  • NES_POPUP - Includes the button on the far right that pops up a floating trackbar
  • NES_LIVEUPDATE - Updates the parent about the value while tracking. NEW
  • NES_METER - Includes the small bar underneath the edit field.NEW

Messages

  • NEM_GETPOS - Returns the current value as return value
  • NEM_SETPOS - Sets the current value. Passed in LPARAM
  • NEM_GETRANGE - Returns allowed range. WPARAM and LPARAM are treated as pointers to int's
  • NEM_SETRANGE - Sets the allowed range. Min is in WPARAM and max in LPARAM
  • NEM_GETREADONLY - Gets the readonly state of the edit field. NEW
  • NEM_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

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

John Gonzalez


Member

Occupation: Software Developer
Location: United States United States

Other popular Miscellaneous articles:

Article Top
You must Sign In to use this message board.
FAQ FAQ 
 
Noise Tolerance  Layout  Per page   
 Msgs 1 to 14 of 14 (Total in Forum: 14) (Refresh)FirstPrevNext
GeneralCan someone convert this for WTL? Pinmemberehaerim10:41 17 Jun '09  
GeneralCrash when I press enter PinmemberMember 575254723:50 6 Dec '08  
GeneralRe: Crash when I press enter Pinmemberehaerim11:08 17 Jun '09  
Generalcontrol have a bug & i correct it Pinmembermohammadmot23:23 26 Aug '08  
Questionquestion about change notification with multiple CNumericEdit controls PinmemberCelticDaddio8:30 17 Apr '08  
AnswerSOLVED Re: question about change notification with multiple CNumericEdit controls PinmemberCelticDaddio9:01 17 Apr '08  
GeneralMake it no activating PinmemberYYuri9:39 14 Sep '06  
GeneralA simple extension PinmemberSteve Johnson (Sven)14:36 13 Jun '05  
GeneralRe: A simple extension Pinmemberniry7:19 18 Aug '05  
GeneralRe: A simple extension PinmemberSteve Johnson (Sven)7:28 18 Aug '05  
GeneralCMyEdit Pinmemberviva dotnet8:42 24 Jun '04  
GeneralDoes not work for VC6. PinmemberWREY12:57 25 Apr '04  
GeneralNice, but two mods needed PinmemberRobin Hilliard0:48 23 Apr '04  
GeneralRe: Nice, but two mods needed Pinmemberviva dotnet8:44 24 Jun '04  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 22 Apr 2004
Editor: Nishant Sivakumar
Copyright 2004 by John Gonzalez
Everything else Copyright © CodeProject, 1999-2009
Web17 | Advertise on the Code Project