Click here to Skip to main content
Click here to Skip to main content

CKnobControlST v1.0

, 24 Jun 2003
Rate this:
Please Sign up or sign in to vote.
davide_calabro@yahoo.com

Sample Image

SoftechSoftware homepage
SoftechSoftware Email

Abstract

You need GDI+ installed to use this control.

CKnobControlST is a class derived from MFC CSliderCtrl class. The control has been created as an exercise of converting an existing control written in C# into a new one with the same features written in C++. The conversion was quite simple. You can find the original control here. CKnobControlST code is more robust than the original one.

How to integrate CKnobControlST in your application

In your project include the following files:

  • KnobControlST.h
  • KnobControlST.cpp
With dialog editor create a slider control called, for example, IDC_KNOB.

Then create a member variable for this control:
CKnobControlST m_knbControl;

Now attach the knob control to CKnobControlST. For dialog-based applications, in your OnInitDialog:

// Call the base-class method
CDialog::OnInitDialog();

// Create the IDC_KNOB slider control
m_knbControl.SubclassDlgItem(IDC_KNOB, this);

Or in your DoDataExchange:

// Call the base method
CDialog::DoDataExchange(pDX);

// Create the IDC_KNOB slider control
DDX_Control(pDX, IDC_KNOB, m_knbControl);

The control will have the same default range and start position as in the base MFC class CSliderCtrl. These values can be modified using the same methods of the base class such as, for example, SetRange or SetPos. Following is the list of base class methods currently supported:

  • GetRangeMax
  • GetRangeMin
  • GetRange
  • SetRangeMax
  • SetRangeMin
  • SetRange
  • GetPos
  • SetPos
At this moment other specific CSliderCtrl features are not supported.

Your slider control is now a CKnobControlST!

Class methods

SetIcon

Sets the icon to be displayed. Any previous icon will be removed.

// Parameters:
//     [IN]   nIcon
//            A Windows icon resource ID
//     [IN]   bRepaint
//            If TRUE the control will be immediately repainted
//     [IN]   hInstance
//            Handle of the instance that contains the icon.
//            If NULL the icon will be loaded from the .EXE resources
//
// Return value:
//     KNOBCONTROLST_OK
//        Function executed successfully.
//     KNOBCONTROLST_INVALIDRESOURCE
//        The resource specified cannot be found or loaded.
//
DWORD SetIcon(int nIcon, BOOL bRepaint = TRUE, HINSTANCE hInstance = NULL)

SetIcon

Sets the icon to be displayed. Any previous icon will be removed.

// Parameters:
//     [IN]   hIcon
//            Handle fo the icon to show.
//            Pass NULL to remove any icon from the control.
//     [IN]   bRepaint
//            If TRUE the control will be immediately repainted
//
// Return value:
//     KNOBCONTROLST_OK
//        Function executed successfully.
//     KNOBCONTROLST_INVALIDRESOURCE
//        The resource specified cannot be found or loaded.
//
DWORD SetIcon(HICON hIcon, BOOL bRepaint = TRUE)

SetColors

Sets the foreground and background colors of the control.
// Parameters:
//     [IN]   cFgColor
//            A GDI+ Color object indicating the color of the knob control.
//     [IN]   cBkColor
//            A GDI+ Color object indicating the background color of the <BR>//            knob control.
//     [IN]   bRepaint
//            If TRUE the control will be repainted.
//
void SetColors(Color cFgColor, Color cBkColor, BOOL bRepaint = TRUE)

SetFgColor

Sets the foreground color of the control.
// Parameters:
//     [IN]   cFgColor
//            A GDI+ Color object indicating the color of the knob control.
//     [IN]   bRepaint
//            If TRUE the control will be repainted.
//
void SetFgColor(Color cFgColor, BOOL bRepaint = TRUE)

SetBkColor

Sets the background color of the control.
// Parameters:
//     [IN]   cBkColor
//            A GDI+ Color object indicating the background color of the knob <BR>//            control.
//     [IN]   bRepaint
//            If TRUE the control will be repainted.
//
void SetBkColor(Color cBkColor, BOOL bRepaint = TRUE)

SetScaleColor

Sets the scale color of the control.
// Parameters:
//     [IN]   cColor
//            A GDI+ Color object indicating the scale color of the knob <BR>//            control.
//     [IN]   bRepaint
//            If TRUE the control will be repainted.
//
void SetScaleColor(Color cColor, BOOL bRepaint = TRUE)

SetAlpha

Sets the alpha component of the colors used to draw the control.
// Parameters:
//     [IN]   byAlpha
//            A BYTE value indicating the alpha component.
//     [IN]   bRepaint
//            If TRUE the control will be repainted.
//
void SetAlpha(BYTE byAlpha, BOOL bRepaint = TRUE)

GetAlpha

Returns the alpha component of the colors used to draw the control.
// Return value:
//     A BYTE indicating the alpha component.
//
BYTE GetAlpha()

ShowLargeScale

Sets if the large scale around the control must be drawn.
// Parameters:
//     [IN]   bShow
//            If TRUE the scale will be drawn.
//     [IN]   bRepaint
//            If TRUE the control will be repainted.
//
void ShowLargeScale(BOOL bShow, BOOL bRepaint = TRUE)

ShowSmallScale

Sets if the small scale around the control must be drawn.
// Parameters:
//     [IN]   bShow
//            If TRUE the scale will be drawn.
//     [IN]   bRepaint
//            If TRUE the control will be repainted.
//
void ShowSmallScale(BOOL bShow, BOOL bRepaint = TRUE)

SetLargeChangeValue

Sets the value of the large control step.
// Parameters:
//     [IN]   nLargeChange
//            New value of the large control step.
//     [IN]   bRepaint
//            If TRUE the control will be repainted.
//
void SetLargeChangeValue(int nLargeChange, BOOL bRepaint = TRUE)

SetSmallChangeValue

Sets the value of the small control step.
// Parameters:
//     [IN]   nSmallChange
//            New value of the large control step.
//     [IN]   bRepaint
//            If TRUE the control will be repainted.
//
void SetSmallChangeValue(int nSmallChange, BOOL bRepaint = TRUE)

SetTooltipText

Sets the text to show in the control tooltip.
// Parameters:
//     [IN]   nId
//            ID number of the string resource containing the text to show.
//     [IN]   bActivate
//            If TRUE the tooltip will be created active.
//
void SetTooltipText(int nId, BOOL bActivate = TRUE)

SetTooltipText

Sets the text to show in the control tooltip.
// Parameters:
//     [IN]   lpszText
//            Pointer to a null-terminated string containing the text to show.
//     [IN]   bActivate
//            If TRUE the tooltip will be created active.
//
void SetTooltipText(LPCTSTR lpszText, BOOL bActivate = TRUE)

ActivateTooltip

Enables or disables the control tooltip.
// Parameters:
//     [IN]   bActivate
//            If TRUE the tooltip will be activated.
//
void ActivateTooltip(BOOL bActivate = TRUE)

SetChangeCallback

Sets the callback message that will be sent to the specified window each time the control reaches a new position.
// Parameters:
//     [IN]   hWnd
//            Handle of the window that will receive the callback message.
//            Pass NULL to remove any previously specified callback message.
//     [IN]   nMessage
//            Callback message to send to window.
//     [IN]   wParam
//            First 32 bits user specified value that will be passed to the <BR>//            callback function.
//     [IN]   lParam
//            Second 32 bits user specified value that will be passed to the <BR>//            callback function.
//
// Remarks:
//      the callback function must be in the form:
//      LRESULT On_ChangeCallback(WPARAM wParam, LPARAM lParam)
//      Where:
//              [IN]    wParam
//                      First 32 bits user specified value.
//              [IN]    lParam
//                      Second 32 bits user specified value.
//
// Return value:
//     KNOBCONTROLST_OK
//        Function executed successfully.
//
DWORD SetChangeCallback(HWND hWnd, UINT nMessage, WPARAM wParam = 0, <BR>                        LPARAM lParam = 0)

DrawTransparent

Enables the transparent mode. Note: this operation is not reversible.

DrawTransparent should be called just after the control is created. Do not use trasparent controls until you really need it (you have a bitmapped background) since each transparent control makes a copy in memory of its background. This may bring unnecessary memory use and execution overload.

// Parameters:
//     [IN]   bRepaint
//            If TRUE the control will be repainted.
//
DWORD DrawTransparent(BOOL bRepaint = FALSE)

OnDrawBackground

This function is called every time the control background needs to be painted.
If the control is in transparent mode this function will NOT be called. This is a virtual function that can be rewritten in CKnobControlST-derived classes.
// Parameters:
//     [IN]   pGfx
//            Pointer to a GDI+ Graphics object that indicates the graphic <BR>//            context.
//     [IN]   pRect
//            Pointer to a CRect object that indicates the bounds of the
//            area to be painted.
//
// Return value:
//     KNOBCONTROLST_OK
//        Function executed successfully.
//
virtual DWORD OnDrawBackground(Graphics* pGfx, LPCRECT pRect)

OnDrawIcon

This function is called every time the icon associated to the control needs to be painted.
If the control has no icon this function will NOT be called. This is a virtual function that can be rewritten in CKnobControlST-derived classes.
// Parameters:
//     [IN]   pGfx
//            Pointer to a GDI+ Graphics object that indicates the graphic <BR>//            context.
//     [IN]   rpKnob
//            Pointer to a GDI+ Rect object that indicates the bounds of the
//            area taken by the control.
//
// Return value:
//     KNOBCONTROLST_OK
//        Function executed successfully.
//
virtual DWORD OnDrawIcon(Graphics* pGfx, Rect* rpKnob)

GetVersionI

Returns the class version as a short value.
// Return value:
//     Class version. Divide by 10 to get actual version.
//
static short GetVersionI()

GetVersionC

Returns the class version as a string value.
// Return value:
//     Pointer to a null-terminated string containig the class version.
//
static LPCTSTR GetVersionC()

History

  • v1.0 (15/June/2003)
    First release

Disclaimer

THE SOFTWARE AND THE ACCOMPANYING FILES ARE DISTRIBUTED "AS IS" AND WITHOUT ANY WARRANTIES WHETHER EXPRESSED OR IMPLIED. NO REPONSIBILITIES FOR POSSIBLE DAMAGES OR EVEN FUNCTIONALITY CAN BE TAKEN. THE USER MUST ASSUME THE ENTIRE RISK OF USING THIS SOFTWARE.

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

Share

About the Author

Davide Calabro
Web Developer
Italy Italy
No Biography provided

Comments and Discussions

 
QuestionUsing the control in ActiveX Pinmemberpvn2332015-Jan-09 4:23 
GeneralBug with negative range Pinmemberprcarp15-Feb-05 5:16 
GeneralRe: Fix for negative range Pinmemberprcarp15-Feb-05 5:28 
GeneralRe: Fix for negative range Pinmembertheboton10-Dec-06 20:11 
GeneralI cant use it. PinmemberBahman Tahayori4-Oct-04 4:31 
GeneralRe: I cant use it. PinmemberDavide Calabro4-Oct-04 5:05 
GeneralRe: I cant use it. PinmemberBahman Tahayori4-Oct-04 20:59 
GeneralRe: I cant use it. Pinmemberhwoh26-Dec-06 14:39 
Generalvery good ,but don't support bitmap background ! Pinmemberwenjie wu2-Mar-04 15:37 
GeneralVersion 1.1 is available PinmemberDavide Calabro29-Jun-03 12:30 
GeneralBug PinmemberHans Dietrich27-Jun-03 4:51 
GeneralRe: Bug PinmemberDavide Calabro27-Jun-03 5:31 
GeneralRe: Bug PinmemberHans Dietrich27-Jun-03 7:08 
GeneralRe: Bug PinmemberDavide Calabro27-Jun-03 7:25 
GeneralRe: Bug PinmemberHans Dietrich27-Jun-03 10:00 
GeneralNice! PinmemberRavi Bhavnani26-Jun-03 20:33 
GeneralRe: Nice! PinmemberDavide Calabro26-Jun-03 20:42 
GeneralAwesome! PinmemberHans Dietrich26-Jun-03 18:14 
GeneralRe: Awesome! PinmemberDavide Calabro26-Jun-03 20:43 
GeneralVC6 on Win2000 no GDI+ PinmemberNikolai Teofilov25-Jun-03 23:09 
GeneralRe: VC6 on Win2000 no GDI+ PinmemberDavide Calabro25-Jun-03 23:33 
GeneralRe: VC6 on Win2000 no GDI+ Pinmemberwhymegod4-Dec-03 11:18 
GeneralRe: VC6 on Win2000 no GDI+ Pinsussldlance5-Dec-04 14:50 
Generalsome functional improvements for this nice control PinmemberDavide Pizzolato25-Jun-03 20:01 
GeneralRe: some functional improvements for this nice control PinmemberDavide Calabro25-Jun-03 22:12 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web02 | 2.8.140814.1 | Last Updated 25 Jun 2003
Article Copyright 2003 by Davide Calabro
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid