Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/visual-studio-2010/4.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
C++ 滚动条赢得';mfc应用程序中的t工作_C++_Visual Studio 2010_Mfc_Scrollbar - Fatal编程技术网

C++ 滚动条赢得';mfc应用程序中的t工作

C++ 滚动条赢得';mfc应用程序中的t工作,c++,visual-studio-2010,mfc,scrollbar,C++,Visual Studio 2010,Mfc,Scrollbar,我的mfc应用程序有一个视图类,它继承了CSrollView类,以提供所谓的简单滚动条支持。我可以让滚动条出现在某个点上,比如当我放大视图中显示的内容时,但是当我尝试向左滚动时,什么也没有发生。我已经在网上研究了几个小时,但我不能确定我做得不对。下面是视图类中的OnDraw()和OnInitialUpdate()方法: void CWaveEditView::OnDraw(CDC* pDC) { CWaveEditDoc* pDoc = GetDocument(); ASSERT

我的mfc应用程序有一个视图类,它继承了CSrollView类,以提供所谓的简单滚动条支持。我可以让滚动条出现在某个点上,比如当我放大视图中显示的内容时,但是当我尝试向左滚动时,什么也没有发生。我已经在网上研究了几个小时,但我不能确定我做得不对。下面是视图类中的OnDraw()和OnInitialUpdate()方法:

void CWaveEditView::OnDraw(CDC* pDC)
{
    CWaveEditDoc* pDoc = GetDocument();
    ASSERT_VALID(pDoc);
    if (!pDoc)
        return;
// TODO: add draw code for native data here
    WaveFile * wave = &pDoc->wave;

    if (wave->hdr==NULL) {
        return;
    }

    // Get dimensions of the window.
    CRect rect;
    GetClientRect(rect);


    // Set color in pen and brush for wave
    COLORREF color = RGB( 0, 255, 0 );
    CPen pen2( PS_SOLID, 0, color );
    pDC->SelectObject( &pen2 );
    CBrush brush2(color);
    pDC->SelectObject( &brush2 );

     // Draw selection if any
    if (selectionStart != selectionEnd) {
        pDC->Rectangle(selectionStart, 0, selectionEnd, rect.Height());
    }

    // Draw the wave
    pDC->MoveTo(0,0);
    int x;
    for (x=0; x < zoomAmount*wave->lastSample/scaling; x++) {
        // Assuming the whole file will be fit in the window, for every x value in the window
        // we need to find the equivalent sample in the wave file.
        float val = wave->get_sample((int) (x*scaling/zoomAmount) );

        // We need to fit the sound also in the y axis. The y axis goes from 0 in the
        // top of the window to rect.Height at the bottom. The sound goes from -32768 to 32767
        // we scale it in that way.
        int y = (int) ((val+32768) * (rect.Height()-1) / (32767+32768));
        pDC->LineTo(x,rect.Height() - y);
    }
    CSize totalSize;
    totalSize.cx = x;
    SetScrollSizes(MM_TEXT,totalSize);
}

void CWaveEditView::OnInitialUpdate()
{
    CScrollView::OnInitialUpdate();

    // Initial scroll sizes
    CSize sizeTotal;
    CRect rect;
    CWaveEditDoc *doc = GetDocument();
    WaveFile * wave = &doc->wave;
    GetClientRect(rect);
    scaling = wave->lastSample/rect.Width();
    sizeTotal.cx = 700;
    sizeTotal.cy = 700;
    SetScrollSizes(MM_TEXT, sizeTotal);
}
void CWaveEditView::OnDraw(CDC*pDC)
{
CWaveEditDoc*pDoc=GetDocument();
断言有效(pDoc);
if(!pDoc)
返回;
//TODO:在此处添加本机数据的绘图代码
波形文件*wave=&pDoc->wave;
如果(波形->hdr==NULL){
返回;
}
//获取窗口的尺寸。
正确无误;
GetClientRect(rect);
//设置波浪笔和画笔的颜色
COLORREF color=RGB(0,255,0);
CPen pen2(PS_固体,0,颜色);
pDC->选择对象(&pen2);
cbrush2(彩色);
pDC->选择对象(&2);
//绘制所选内容(如果有)
如果(selectionStart!=selectionEnd){
pDC->矩形(selectionStart,0,selectionEnd,rect.Height());
}
//招手
pDC->移动到(0,0);
int x;
对于(x=0;xlastSample/scaling;x++){
//假设窗口中的每个x值都适合整个文件
//我们需要在wave文件中找到等效样本。
float val=wave->get_sample((int)(x*scaling/zoomAmount));
//我们还需要在y轴上拟合声音,y轴从0开始
//从窗口顶部到矩形。底部的高度。声音从-32768到32767
//我们用这种方式来衡量它。
int y=(int)((val+32768)*(rect.Height()-1)/(32767+32768));
pDC->LineTo(x,垂直高度()-y);
}
csizetotalsize;
totalSize.cx=x;
设置CrollSize(MM_文本,总尺寸);
}
void CWaveEditView::OnInitialUpdate()
{
CScrollView::OnInitialUpdate();
//初始卷轴大小
CSize sizeTotal;
正确无误;
CWaveEditDoc*doc=GetDocument();
波形文件*波形=&doc->wave;
GetClientRect(rect);
scaling=wave->lastSample/rect.Width();
sizeTotal.cx=700;
sizeTotal.cy=700;
设置CrollSizes(MM_文本,sizeTotal);
}

您有OnScroll功能吗?如果是这样的话,那又有什么用呢?没关系,我知道了。我在头文件中正确继承了类,但是mfc生成了一些代码,我忘记了将继承更改为CScrollView。MFC是我见过的最大的f***集群,我只是把它用于一个学校项目,因为我们不得不这么做。很高兴你把它整理好了。MFC不是很好,但它比编写没有框架的Windows应用程序要好!我相信Qt更好,但遗憾的是,我没能尝试。至少现在我们有了stl来代替很多MFC的渣滓……请注意:千万不要试图在OnDraw中调用像SetScrollSizes这样的函数!这会导致不必要的递归出现问题。。。OnDraw仅用于绘图。当视图更改(OnUpdate)时,您应该设置滚动大小。