作者:陈缘
联系:[email protected]
博客:http://blog.csdn.net/luandao2000
主页:http://www.spbase.com
做PPC开发的同志会发现 开发Dialog程序时,遇到比较大Dialog,一个屏幕放不下。自然设置 Vertical Scrollbar,设置了也没错。滚动条出来了,但是就是拉不动。百思不得其解。也有老外同志好心办坏事:
How do I scroll the contents of a dialog
http://www.pocketpcdn.com/articles/print_scroll_dialog.html
用property page.去实现。乱78遭一堆。
我想来想去,没理由不能滚动啊。滚动条都出来了,总得发对应的消息吧,自己动手验证,果然WM_VSCROLL,WM_HSCROLL 等消息一个没拉 都有。再验证一下ScrollWindowEx能滚动Dialog不?能啊。
得!自己动手搞定滚动不就得了
代码如下:
1 先响应 MESSAGE_HANDLER(WM_VSCROLL, OnVScroll);
2 自己实现 OnVScroll
LRESULT CJeyoDialog::OnVScroll(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
int nScrollCode = (int)LOWORD(wParam);
int nNowPos = (short int)HIWORD(wParam);
HWND hwndScrollBar = (HWND)lParam;
CRect rc;
GetWindowRect(&rc);
SCROLLINFO si = {sizeof(SCROLLINFO),
SIF_PAGE|SIF_POS|SIF_RANGE|SIF_TRACKPOS, 0, 0, 0, 0,
0};
::GetScrollInfo (m_hWnd, SB_VERT, &si);
int MIN_VSCROLL_VALUE = 0;
int MAX_VSCROLL_VALUE = si.nMax;
int iInterval = 0;
int nPos = si.nPos;
switch (nScrollCode)
{
case SB_LINEUP:
nPos -= 20;
break;
case SB_PAGEUP:
nPos -= 60;
break;
case SB_LINEDOWN:
nPos += 20;
break;
case SB_PAGEDOWN:
nPos += 60;
break;
case SB_TOP:
nPos = MIN_VSCROLL_VALUE;
break;
case SB_BOTTOM:
nPos = MAX_VSCROLL_VALUE;
break;
case SB_THUMBTRACK:
case SB_THUMBPOSITION:
nPos = si.nTrackPos;
break;
}
if(nPos < MIN_VSCROLL_VALUE)
nPos = MIN_VSCROLL_VALUE;
else if(nPos >MAX_VSCROLL_VALUE)
nPos = MAX_VSCROLL_VALUE;
iInterval = nPos - si.nPos;
if(0 != iInterval)
{
si.fMask = SIF_POS;
si.nPos = nPos;
::SetScrollInfo (m_hWnd, SB_VERT, &si, TRUE);
ScrollWindowEx(0, -iInterval, NULL, NULL,
NULL, NULL, SW_SCROLLCHILDREN);
}
Invalidate();
return 0;
}
尽信书 不如无书 仅供参考而已