[英]Adding scrollbar to an activeX control in MFC
I'm trying to create an activeX control using Microsoft Foundation Class Library. 我正在尝试使用Microsoft基础类库创建一个activeX控件。
I have created the control. 我已经创建了控件。 It's a graph control.
这是一个图形控件。 I have placed some buttons on the control as well.
我也在控件上放置了一些按钮。
I am trying to add a scrollbar to my control using CScrollBar
class. 我正在尝试使用
CScrollBar
类将滚动条添加到我的控件中。
I create the control using CScrollBar::Create
method. 我使用
CScrollBar::Create
方法创建控件。 I can see the control when use my activeX control in an application. 在应用程序中使用我的activeX控件时,我可以看到该控件。
I have added the OnHScroll
method to my control class. 我已经将
OnHScroll
方法添加到控件类中。 This derives from COleControl
class . 这是从
COleControl
类派生的。
When I scroll I use CScrollBar::GetScrollPos
to get the scroll position which I always returns zero. 滚动时,我使用
CScrollBar::GetScrollPos
来获取滚动位置,该位置始终返回零。
Here is the code for creating the scrollbar in activeX control. 这是在activeX控件中创建滚动条的代码。
Code for Control in MainClass.h file: MainClass.h文件中的控制代码:
private:
CScrollBar m_HScrollBar;
protected:
afx_msg void OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar);
DECLARE_MESSAGE_MAP()
Code for Control in MainClass.cpp in OnCreate()
method for creating the scrollbar: 用于创建滚动条的
OnCreate()
方法中MainClass.cpp中的控件代码:
m_HScrollBar.Create(SBS_HORZ | WS_CHILD| WS_VISIBLE , CRect(rcBottomStrip.left ,
rcBottomStrip.bottom ,
rcBottomStrip.right ,
rcBottomStrip.bottom + (tHeight*3)/125),this, 315);
m_HScrollBar.SetScrollRange(0, 2048);
SCROLLINFO ScrollInfo;
ScrollInfo.cbSize = sizeof(ScrollInfo);
ScrollInfo.fMask = SIF_RANGE;
ScrollInfo.nMin = 0;
ScrollInfo.nMax = 1128;
ScrollInfo.nPage = 100;
ScrollInfo.nPos = 0;
ScrollInfo.nTrackPos = 0;
m_HScrollBar.SetScrollInfo(&ScrollInfo);
m_HScrollBar.ShowScrollBar(TRUE);
m_HScrollBar.EnableWindow();
m_HScrollBar.EnableAutomation();
In OnHScroll
method to return the scroll position and moving the scrollbar: 在
OnHScroll
方法中返回滚动位置并移动滚动条:
int CurPos = m_HScrollBar.GetScrollPos();
m_HScrollBar.SetScrollPos(CurPos);
I replaced the CScrollBar and used HWND instead. 我更换了CScrollBar并改用了HWND。 So my code changed like this:
所以我的代码是这样改变的:
//MainClass.h //MainClass.h
HWND m_wndHScrollBar;
//MainClass.cpp //MainClass.cpp
m_wndHScrollBar = (CreateWindowEx(
0, // no extended styles
SCROLLBAR, // scroll bar control class
(PTSTR) NULL, // no window text
WS_CHILD | WS_VISIBLE // window styles
| SBS_HORZ, // horizontal scroll bar style
left, // horizontal position
bottom, // vertical position
right, // width of the scroll bar
height, // height of the scroll bar
m_hWnd, // handle to main window
(HMENU) ID_HSCROLLBAR, // no menu
GetModuleHandle(NULL), // instance owning this window
(PVOID) NULL // pointer not needed
));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.