对话框子窗口的滚动

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
父类
void CDlgXXXX::InitUIRes(CString strCatCode)
{
    if (NULL == m_pDlgSub_)
    {
        m_pDlgSub_ = new CDlgFilterSub(this);
        m_pDlgSub_->Create(CDlgFilterSub::IDD, this);
    }
     
    m_pDlgSub_->InitUI(strCatCode);
 
    CRect rtClient;
    GetWindowRect(&rtClient);
 
    CRect rtDlg;
    m_pDlgSub_->GetClientRect(&rtDlg);
    rtDlg.MoveToY(40);
    rtDlg.left = 0;
    rtDlg.right = rtClient.Width();
    m_pDlgSub_->MoveWindow(rtDlg);
 
    m_pDlgSub_->GetWindowRect(&rtDlg);
    rtClient.bottom = rtDlg.bottom + 10;
    MoveWindow(rtClient);
 
    if (!m_pDlgSub_->IsWindowVisible())
    {
        m_pDlgSub_->ShowWindow(SW_SHOW);
    }
}

  子窗口

1
2
3
void CDlgFilterSub::InitUI(CString strCatCode)
{
    。。。。动态添加按钮rtCtrl最后一排控件的位置}

CRect rtClient;
GetClientRect(rtClient);

SCROLLINFO si;
si.cbSize = sizeof(si);
GetScrollInfo(SB_VERT, &si);
si.nMax = max(rtCtrl.bottom + SPACE, rtClient.bottom);
si.nPos = 0;
SetScrollInfo(SB_VERT, &si);

static int iHeight = rtClient.bottom;
if (rtClient.bottom < rtCtrl.bottom + SPACE)
{
rtClient.bottom = iHeight;
}
else
{
rtClient.bottom = rtCtrl.bottom + SPACE;
}
MoveWindow(rtClient);

  子窗口的初始化

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
BOOL CDlgFilterSub::OnInitDialog()
{
    CBCGPDialog::OnInitDialog();
    COLORREF bgColor = RGB(248, 248, 248);
    SetBackgroundColor(bgColor);
 
    CRect rtClient;
    GetClientRect(rtClient);
    SCROLLINFO si;
    si.cbSize = sizeof(SCROLLINFO);
    si.fMask = SIF_ALL;
    si.nPos = 0;
    si.nMin = 0;
    si.nMax = rtClient.bottom;
    SetScrollInfo(SB_VERT, &si);
 
    return TRUE;
}

  

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
void CDlgFilterSub::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
{
    SCROLLINFO si;
    si.cbSize = sizeof(si);
    si.fMask = SIF_ALL;
    GetScrollInfo(SB_VERT, &si);
    INT nVscroll = si.nPos;
    switch(nSBCode)
    
    case SB_LINEDOWN:
        {
            nVscroll += 20;
            if (nVscroll > (si.nMax - si.nMin - si.nPage ))
            {
                nVscroll = si.nMax - si.nMin - si.nPage;
            }
        }
        break;
    case SB_LINEUP:
        {
            nVscroll -= 20;
            if (nVscroll < si.nMin)
            {
                nVscroll = 0;
            }
        }
        break;
    case SB_PAGEDOWN:
        {
            nVscroll += si.nPage;
            if (nVscroll > (si.nMax - si.nMin - si.nPage))
            {
                nVscroll = si.nMax - si.nMin - si.nPage;
            }
        }
        break;
    case SB_PAGEUP:
        {
            nVscroll -= si.nPage;
            if (nVscroll < si.nMin)
            {
                nVscroll = 0; 
            }
        }
        break;
    case SB_THUMBTRACK:
        {
            nVscroll = nPos;
        }
        break;
    }
 
    if (si.nPos != nVscroll)
    {
        int yAmount = -(nVscroll - si.nPos);
        ScrollWindow(0, yAmount, NULL,NULL);
    }
 
    si.nPos = nVscroll;
    SetScrollInfo(SB_VERT, &si);
 
    CBCGPDialog::OnVScroll(nSBCode, nPos, pScrollBar);
}

  

1
ON_WM_VSCROLL()

  

1
afx_msg void OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar);

  

posted @   曦花  阅读(216)  评论(1编辑  收藏  举报
编辑推荐:
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!
点击右上角即可分享
微信分享提示