滚动条,在debug和release下运行结果不一样
h文件里
INT m_nVscroll_;
CBCGPScrollBar m_scroll_bar_;
cpp文件里:
BOOL CDlgXXX::OnInitDialog()
{
CBCGPDialog::OnInitDialog();
SCROLLINFO si;
si.cbSize = sizeof(SCROLLINFO);
si.nMin = 0;
si.nMax = 100;
si.nPage = 5;
si.nPos = 0; //必须初始化,否则release下默认为16
si.fMask = SIF_POS | SIF_RANGE | SIF_PAGE;
m_scroll_bar_.SetScrollInfo(&si, TRUE);
CRect rtClient;
GetClientRect(rtClient);
m_rt_vScroll_ = rtClient;
m_rt_vScroll_.left = rtClient.right - 10;
m_scroll_bar_.MoveWindow(&m_rt_vScroll_); //滚动条所在的位置
InitUI(0);
void CDlgXXX::InitUI(int yScroll)
{
const int BTN_WIDTH = 82;
const int TITLE_WIDTH = 50;
const int TITLE_HEIGHT = 25;
const int SPACE = 5;
const int LEFT_SPACE = 40 + 20;
//分割线'
CRect rtClient;
GetClientRect(rtClient);
CRect rtCtrl;
rtCtrl.left = LEFT_SPACE - 20;
rtCtrl.right = rtCtrl.left + 1;
rtCtrl.top = yScroll;
rtCtrl.bottom = rtCtrl.top + rtClient.bottom + 800;
m_st_vline0_.MoveWindow(&rtCtrl); //左侧线
rtCtrl.right = rtClient.right;
rtCtrl.left = rtCtrl.right - 1;
rtCtrl.top = yScroll;
rtCtrl.bottom = rtClient.bottom + yScroll + 800;
m_st_vline1_.MoveWindow(&rtCtrl); //右侧线
int iPosX = LEFT_SPACE;
int iPosY = SPACE * 3 + yScroll; //这里注意相对位置yScroll
m_st_title_.SetWindowPos(NULL, iPosX, iPosY, TITLE_WIDTH * 2, 30, SWP_NOZORDER);
iPosY += 30 + SPACE;
int iLineWidth = rtClient.Width();
m_st_hline1_.SetWindowPos(NULL, LEFT_SPACE - 20, iPosY, iLineWidth, 1, SWP_NOZORDER);
//墙
iPosY += SPACE * 3;
m_title_wall_.SetWindowPos(NULL, iPosX, iPosY, TITLE_WIDTH, TITLE_HEIGHT, SWP_NOZORDER);
iPosY += TITLE_HEIGHT;
m_btn_wall_.SetWindowPos(NULL, iPosX, iPosY, BTN_WIDTH, BTN_WIDTH, SWP_NOZORDER);
iPosX += BTN_WIDTH + 3;
m_btn_room_.SetWindowPos(NULL, iPosX, iPosY, BTN_WIDTH, BTN_WIDTH, SWP_NOZORDER);
iPosX += BTN_WIDTH + 3;
m_btn_region_.SetWindowPos(NULL, iPosX, iPosY, BTN_WIDTH, BTN_WIDTH, SWP_NOZORDER);
}
void CDlgXXX::OnSize(UINT nType, int cx, int cy)
{
CBCGPDialog::OnSize(nType, cx, cy);
if (CMainFrame::gThis != NULL && m_scroll_bar_.m_hWnd != NULL)
{
BOOL b1 = CMainFrame::gThis->IsZoomed();
if (!b1)
{
CRect rtClient;
GetClientRect(rtClient);
m_rt_vScroll_ = rtClient;
m_rt_vScroll_.left = rtClient.right - 10;
m_scroll_bar_.MoveWindow(&m_rt_vScroll_);
m_scroll_bar_.SetScrollRange(0, 250);
}
m_scroll_bar_.ShowWindow(FALSE);
}
int sy= -m_nVscroll_;
if (m_st_vline0_.m_hWnd)
{
InitUI(sy);
}
}
滚动条的相应:
void CDlgXXX::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
{
SCROLLINFO si;
si.cbSize = sizeof(si);
m_scroll_bar_.GetScrollInfo(&si, SIF_POS | SIF_PAGE | SIF_RANGE);
m_nVscroll_ = si.nPos;
switch(nSBCode)
{
case SB_LINEDOWN:
{
m_nVscroll_ += 20;
if (m_nVscroll_ > (si.nMax - si.nMin - si.nPage ))
{
m_nVscroll_ = si.nMax - si.nMin - si.nPage;
}
}
break;
case SB_LINEUP:
{
m_nVscroll_ -= 20;
if (m_nVscroll_ < si.nMin)
{
m_nVscroll_ = 0;
}
}
break;
case SB_PAGEDOWN:
{
m_nVscroll_ += 8 * si.nPage;
if (m_nVscroll_ > (si.nMax - si.nMin - si.nPage))
{
m_nVscroll_ = si.nMax - si.nMin - si.nPage;
}
}
break;
case SB_PAGEUP:
{
m_nVscroll_ -= 8 * si.nPage;
if (m_nVscroll_ < si.nMin)
{
m_nVscroll_ = 0;
}
}
break;
case SB_THUMBTRACK:
{
m_nVscroll_ = nPos;
}
break;
}
if (si.nPos != m_nVscroll_)
{
ScrollWindow(0, -(m_nVscroll_ - si.nPos), NULL ,NULL);
}
si.nPos = m_nVscroll_;
m_scroll_bar_.SetScrollInfo(&si, TRUE);
CBCGPDialog::OnVScroll(nSBCode, nPos, pScrollBar);
}
BOOL CDlgXXX::OnMouseWheel(UINT nFlags, short zDelta, CPoint pt)
{
//向下滚
if (zDelta == -120)
{
m_nVscroll_ += 10;
OnVScroll(SB_PAGEDOWN, m_nVscroll_, &m_scroll_bar_);
}
else if (zDelta == 120)
{
m_nVscroll_ -= 10;
OnVScroll(SB_PAGEUP, m_nVscroll_, &m_scroll_bar_);
}
return CBCGPDialog::OnMouseWheel(nFlags, zDelta, pt);
}

浙公网安备 33010602011771号