CKnobControlST v1.0






4.89/5 (27投票s)
2003年6月25日
3分钟阅读

147300

7023
davide_calabro@yahoo.com
SoftechSoftware 主页
SoftechSoftware 电子邮件
摘要
您需要安装 GDI+ 才能使用此控件。CKnobControlST
是一个从 MFC CSliderCtrl
类派生的类。该控件是作为将用 C# 编写的现有控件转换为用 C++ 编写的具有相同功能的新控件的练习而创建的。转换非常简单。您可以在此处找到原始控件。CKnobControlST
代码比原始代码更健壮。
如何在您的应用程序中集成 CKnobControlST
在你的项目中包含以下文件
- KnobControlST.h
- KnobControlST.cpp
IDC_KNOB
的滑动条控件。然后为此控件创建一个成员变量
CKnobControlST m_knbControl;
现在将旋钮控件附加到 CKnobControlST
。对于基于对话框的应用程序,在您的 OnInitDialog 中
// Call the base-class method CDialog::OnInitDialog(); // Create the IDC_KNOB slider control m_knbControl.SubclassDlgItem(IDC_KNOB, this);
或者在您的 DoDataExchange
中
// Call the base method CDialog::DoDataExchange(pDX); // Create the IDC_KNOB slider control DDX_Control(pDX, IDC_KNOB, m_knbControl);
该控件将具有与基本 MFC 类 CSliderCtrl
相同的默认范围和起始位置。这些值可以使用基本类的方法进行修改,例如,SetRange
或 SetPos
。以下是当前支持的基本类方法列表
GetRangeMax
GetRangeMin
GetRange
SetRangeMax
SetRangeMin
SetRange
GetPos
SetPos
CSliderCtrl
功能。您的滑动条控件现在是一个
CKnobControlST
!类方法
SetIcon
设置要显示的图标。任何先前的图标都将被删除。
// 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)
设置图标
设置要显示的图标。任何先前的图标都将被删除。
// 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
设置控件的前景色和背景色。// 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
设置控件的前景色。// 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
设置控件的背景色。// 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
设置控件的刻度颜色。// 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
设置用于绘制控件的颜色的 alpha 分量。// 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
返回用于绘制控件的颜色的 alpha 分量。// Return value: // A BYTE indicating the alpha component. // BYTE GetAlpha()
ShowLargeScale
设置是否必须绘制控件周围的大刻度。// 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
设置是否必须绘制控件周围的小刻度。// 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
设置大控件步长的值。// 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
设置小控件步长的值。// 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
设置在控件工具提示中显示的文本。// 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
设置在控件工具提示中显示的文本。// 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
启用或禁用控件工具提示。// Parameters: // [IN] bActivate // If TRUE the tooltip will be activated. // void ActivateTooltip(BOOL bActivate = TRUE)
SetChangeCallback
设置将在控件达到新位置时发送到指定窗口的回调消息。// 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
启用透明模式。注意:此操作不可逆。DrawTransparent
应在创建控件后立即调用。在您真正需要它之前不要使用透明控件(您有一个位图背景),因为每个透明控件都会在其内存中复制其背景。这可能会带来不必要的内存使用和执行过载。
// Parameters: // [IN] bRepaint // If TRUE the control will be repainted. // DWORD DrawTransparent(BOOL bRepaint = FALSE)
OnDrawBackground
每次需要绘制控件背景时都会调用此函数。如果控件处于透明模式,则不会调用此函数。这是一个虚拟函数,可以在
CKnobControlST
派生类中重写。// 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
每次需要绘制与控件关联的图标时都会调用此函数。如果控件没有图标,则不会调用此函数。这是一个虚拟函数,可以在
CKnobControlST
派生类中重写。// 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
以短数值形式返回类版本。// Return value: // Class version. Divide by 10 to get actual version. // static short GetVersionI()
GetVersionC
以字符串值的形式返回类版本。// Return value: // Pointer to a null-terminated string containig the class version. // static LPCTSTR GetVersionC()
历史
- v1.0 (2003 年 6 月 15 日)
首次发布
免责声明
本软件及随附文件按“原样”分发,没有任何明示或暗示的保证。对于可能造成的损害或甚至功能,不承担任何责任。用户必须承担使用本软件的全部风险。