如何将滚动条附加到对话框

时间:2014-01-22 10:28:33

标签: c++ image

我必须找到将滚动条附加到由应用程序动态创建的一组图像的正确方法。 在我的代码中,我创建了滚动条,但它无法正常工作。主窗口不滚动以查看所有图像。

int currentLength = iImage * (WIDTH + SPACER); 
picName.Format(_T("Image %d"),iImage);
CPoint topLeft(currentLength,0);
CPoint bottomRigth(currentLength + (WIDTH), HEIGHT);

CRect miniCRect(topLeft, bottomRigth);
Miniature[iImage] = new CStatic();
Miniature[iImage]->Create(picName, WS_CHILD|WS_VISIBLE|SS_BITMAP, miniCRect, this);   

if((bottomRigth.x > 500) && (currentLength <= 500))
{
    //creo la scrool bar
    CPoint ptnrigin(0,210);
    CPoint endptn(bottomRigth.x,230);
    CRect workingArea(ptnrigin,endptn);
    cs.Create(WS_VISIBLE,workingArea,this,0);
    cs.EnableScrollBar(ESB_ENABLE_BOTH);
    SCROLLINFO info;
    info.cbSize = sizeof(SCROLLINFO);     
    info.fMask = SIF_ALL;     
    info.nMin = 1;     
    info.nMax = 10; 
    info.nPage = 2;     
    info.nPos = 5;    
    info.nTrackPos = 5; 
    cs.SetScrollInfo(&info);
}

HDC hDCScreen_mini = ::CreateDC(_T("DISPLAY"), NULL, NULL, NULL);
HDC hDCMem_mini = ::CreateCompatibleDC(hDCScreen_mini);
// create a compatible bitmap and select it in the memory DC
HBITMAP hBitmap_mini = ::CreateCompatibleBitmap(hDCScreen_mini, miniCRect.Width(), miniCRect.Height());
HBITMAP hBmpOld_mini = (HBITMAP)::SelectObject(hDCMem_mini, hBitmap_mini);

BitBlt(hDCMem_mini, 0, 0, desktopRect.Width(), desktopRect.Height(), hDCScreen_mini, desktopRect.left, desktopRect.top, dwRop);

Miniature[iImage]->SetBitmap(hBitmap_mini);
Invalidate();

// restore the memory DC and perform cleanup
SelectObject(hDCMem_mini, hBmpOld_mini);
DeleteDC(hDCMem_mini);
DeleteDC(hDCScreen_mini);
//end capture

有人可以帮助我吗?

1 个答案:

答案 0 :(得分:0)

滚动条不会滚动窗口或其内容。它仅提供用户输入的代码,您必须编写该代码才能重新定位图像。此类代码通常使用ScrollWindow移动可见部分,然后在WM_PAINT中添加新显示的部分。

一种不同的方法(为你滚动)就是将图像放在一个所有者绘制的列表框中。

相关问题