CKnobControlST v1.0






4.89/5 (27 votes)
Jun 25, 2003
3 min read

145736

7023
davide_calabro@yahoo.com
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
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
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
// 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
// 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
// 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
// callback function. // [IN] lParam // Second 32 bits user specified value that will be passed to the
// 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,
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
// 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
// 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.