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.
I am trying to add a scrollbar to my control using CScrollBar
class.
I create the control using CScrollBar::Create
method. I can see the control when use my activeX control in an application.
I have added the OnHScroll
method to my control class. This derives from COleControl
class .
When I scroll I use CScrollBar::GetScrollPos
to get the scroll position which I always returns zero.
Here is the code for creating the scrollbar in activeX control.
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()
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();
In OnHScroll
method to return the scroll position and moving the scrollbar:
int CurPos = m_HScrollBar.GetScrollPos();
m_HScrollBar.SetScrollPos(CurPos);
I replaced the CScrollBar and used HWND instead. So my code changed like this:
//MainClass.h
HWND m_wndHScrollBar;
//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
));
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.