Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/visual-studio/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Visual studio 在MFC中将滚动条添加到activeX控件 我试图用微软基金会类库创建一个ActiveX控件。_Visual Studio_Winapi_Mfc_Activex - Fatal编程技术网

Visual studio 在MFC中将滚动条添加到activeX控件 我试图用微软基金会类库创建一个ActiveX控件。

Visual studio 在MFC中将滚动条添加到activeX控件 我试图用微软基金会类库创建一个ActiveX控件。,visual-studio,winapi,mfc,activex,Visual Studio,Winapi,Mfc,Activex,我已经创建了控件。这是一个图形控件。我也在控件上放置了一些按钮 我正在尝试使用CScrollBar类向控件添加滚动条 我使用CScrollBar::create方法创建控件。在应用程序中使用activeX控件时,我可以看到该控件 我已经将OnHScroll方法添加到我的控件类中。这源于COleControl类 当我滚动时,我使用CScrollBar::GetScrollPos获取滚动位置,我总是返回零 下面是在activeX控件中创建滚动条的代码 MainClass.h文件中的控件代码: pri

我已经创建了控件。这是一个图形控件。我也在控件上放置了一些按钮

我正在尝试使用CScrollBar类向控件添加滚动条

我使用CScrollBar::create方法创建控件。在应用程序中使用activeX控件时,我可以看到该控件

我已经将OnHScroll方法添加到我的控件类中。这源于COleControl类

当我滚动时,我使用CScrollBar::GetScrollPos获取滚动位置,我总是返回零

下面是在activeX控件中创建滚动条的代码

MainClass.h文件中的控件代码:

private:
CScrollBar m_HScrollBar;

protected:
afx_msg void OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar); 
DECLARE_MESSAGE_MAP()
用于创建滚动条的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();
int CurPos = m_HScrollBar.GetScrollPos();
m_HScrollBar.SetScrollPos(CurPos);
在OnHScroll方法中,返回滚动位置并移动滚动条:

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();
int CurPos = m_HScrollBar.GetScrollPos();
m_HScrollBar.SetScrollPos(CurPos);

我替换了CScrollBar,并使用了HWND。 因此,我的代码更改如下:

//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 
                ));