|
我在wince下做了个对话框程序 ,使用evc4,增加了垂直滚动条,并增加了OnVScroll,OnSize 事件,
结果滑动滚动条,没有任何效果,在vc++6.0 用同样的方法,就没有问题;
下面是代码,高手看看有什么问题!
代码如下:
先在OnInitDialog 中改变窗口大小配合机器的分辨率:
GetWindowRect(m_rect);
m_nScrollPos = 0;
int iLeft = 0;
int iTop = 0;
int iWidth = m_rect.Width();
int iHeight= m_rect.Height();
//320 * 240
int creenW = GetSystemMetrics( SM_CXSCREEN );
int creenH = GetSystemMetrics( SM_CYSCREEN );
//creenW = 240;
//creenH = 240;
if( iWidth > creenW) iWidth = creenW;
else iLeft = (creenW - iWidth) / 2 ;
if( iHeight > creenH ) iHeight = creenH;
else iTop = (creenH - iHeight) / 2 ;
SetWindowPos(NULL, 0,0, creenW,creenH-25,SWP_SHOWWINDOW);
//SetWindowPos(NULL, 0,0, creenW,creenH,SWP_SHOWWINDOW);
GetWindowRect(m_rect);
return TRUE;
在是 OnVsorll 的代码:
void POSLOG::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
{
// TODO: Add your message handler code here and/or call default
int nDelta;
int nMaxPos = m_rect.Height() - m_nCurHeight;
switch (nSBCode)
{
case SB_LINEDOWN:
if (m_nScrollPos >= nMaxPos)
return;
nDelta = min(nMaxPos/100,nMaxPos-m_nScrollPos);
break;
case SB_LINEUP:
if (m_nScrollPos <= 0)
return;
nDelta = -min(nMaxPos/100,m_nScrollPos);
break;
case SB_PAGEDOWN:
if (m_nScrollPos >= nMaxPos)
return;
nDelta = min(nMaxPos/10,nMaxPos-m_nScrollPos);
break;
case SB_THUMBPOSITION:
nDelta = (int)nPos - m_nScrollPos;
break;
case SB_PAGEUP:
if (m_nScrollPos <= 0)
return;
nDelta = -min(nMaxPos/10,m_nScrollPos);
break;
default:
return;
}
m_nScrollPos += nDelta;
SetScrollPos(SB_VERT,m_nScrollPos,TRUE);
ScrollWindow(0,-nDelta ,NULL ,NULL);
UpdateWindow();
CDialog::OnVScroll(nSBCode, nPos, pScrollBar);
}
下面,OnSize 代码:
void POSLOG::OnSize(UINT nType, int cx, int cy)
{
CDialog::OnSize(nType, cx, cy);
// TODO: Add your message handler code here
// TODO: Add your message handler code here.
m_nCurHeight = cy;
int nScrollMax;
if (cy < m_rect.Height())
{
nScrollMax = m_rect.Height() - cy;
}
else
nScrollMax = 0;
SCROLLINFO si;
si.cbSize = sizeof(SCROLLINFO);
si.fMask = SIF_ALL; // SIF_ALL = SIF_PAGE | SIF_RANGE | SIF_POS;
si.nMin = 0;
si.nMax = nScrollMax;
si.nPage = si.nMax/10;
si.nPos = 0;
SetScrollInfo(SB_VERT, &si, TRUE);
}
|
|