将滚动条添加到MFC中的activeX控件 [英] Adding scrollbar to an activeX control in MFC
问题描述
我正在尝试使用Microsoft基础类库创建一个activeX控件.
I'm trying to create an activeX control using Microsoft Foundation Class Library.
我已经创建了控件.这是一个图形控件.我也在控件上放置了一些按钮.
I have created the control. It's a graph control. I have placed some buttons on the control as well.
我正在尝试使用CScrollBar
类将滚动条添加到控件中.
I am trying to add a scrollbar to my control using CScrollBar
class.
我使用CScrollBar::Create
方法创建控件.在应用程序中使用我的activeX控件时,我可以看到该控件.
I create the control using CScrollBar::Create
method. I can see the control when use my activeX control in an application.
我已经将OnHScroll
方法添加到我的控件类中.这是从COleControl
类派生的.
I have added the OnHScroll
method to my control class. This derives from COleControl
class .
滚动时,我使用CScrollBar::GetScrollPos
来获取始终返回零的滚动位置.
When I scroll I use CScrollBar::GetScrollPos
to get the scroll position which I always returns zero.
这是在activeX控件中创建滚动条的代码.
Here is the code for creating the scrollbar in activeX control.
MainClass.h文件中的控制代码:
Code for Control in MainClass.h file:
private:
CScrollBar m_HScrollBar;
protected:
afx_msg void OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar);
DECLARE_MESSAGE_MAP()
用于创建滚动条的OnCreate()
方法中MainClass.cpp中的控制代码:
Code for Control in MainClass.cpp in OnCreate()
method for creating the scrollbar:
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();
在OnHScroll
方法中返回滚动位置并移动滚动条:
In OnHScroll
method to return the scroll position and moving the scrollbar:
int CurPos = m_HScrollBar.GetScrollPos();
m_HScrollBar.SetScrollPos(CurPos);
推荐答案
我替换了CScrollBar并改用了HWND. 所以我的代码就这样改变了:
I replaced the CScrollBar and used HWND instead. 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
));
这篇关于将滚动条添加到MFC中的activeX控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!