用GETScrollPos和GetScrollInfo得不到nPOS和nTachPos的值!

hx 2002-03-11 01:50:57
我设置了SIF_ALL
反正是要求的都设置了。。。
返回都是0
我的nMax的值是200000
...全文
363 15 打赏 收藏 转发到动态 举报
写回复
用AI写文章
15 条回复
切换为时间正序
请发表友善的回复…
发表回复
hx 2002-03-19
  • 打赏
  • 举报
回复
这个和,那个是没有关系的。。。算了,散分。。
hx 2002-03-18
  • 打赏
  • 举报
回复
不好意思,去了福建,今天刚回来。
老熊宝宝 2002-03-15
  • 打赏
  • 举报
回复
太长了,不好贴,你可以在MSDN里查Scroll Bar Controls in Win32。
里面有两个例子代码。楼上是其中一个的一部分。
老熊宝宝 2002-03-15
  • 打赏
  • 举报
回复
楼上的东西和Wugifer() ( )讲的是一个意思。
在MSDN找到一个和SB_CTL相关的代码,你可以看看:
LONG APIENTRY MainWndProc(
HWND hWnd, /* window handle */
UINT message, /* type of message */
UINT wParam, /* additional information */
LONG lParam) /* additional information */
{

HDC hdc;
PAINTSTRUCT ps;
static HWND hWndHorzScroll, hWndVertScroll;
static UINT uHorzPage, uVertPage, uHorzLine, uVertLine;
WORD wScrollNotify;
UINT uMess;
static RECT RclHorz, RclVert;
POINT Pt;

switch (message)
{

case WM_CREATE:
{
RECT rcl;

GetClientRect(hWnd, &rcl);

// create a scrollbar to put in the window
hWndHorzScroll = CreateWindow(
"Scrollbar",
"",
WS_CHILD | WS_VISIBLE | SBS_HORZ | SBS_TOPALIGN,
SM_CXVSCROLL,0,rcl.right - SM_CXVSCROLL,0,
hWnd,
(HMENU)10,
hInst,
NULL);

SetScrollRange( hWndHorzScroll, SB_CTL, 0, MAX_RANGE, FALSE);
GetClientRect( hWndHorzScroll, &RclHorz);

hWndVertScroll = CreateWindow(
"Scrollbar",
"",
WS_CHILD | WS_VISIBLE | SBS_VERT | SBS_LEFTALIGN,
0,0,0,rcl.bottom,
hWnd,
(HMENU)20,
hInst,
NULL);

SetScrollRange( hWndVertScroll, SB_CTL, 0, MAX_RANGE, FALSE);
GetClientRect( hWndVertScroll, &RclVert);

SetScrollPos(hWndHorzScroll, SB_CTL, 0, TRUE);
SetScrollPos(hWndVertScroll, SB_CTL, 0, TRUE);

uVertPos = uHorzPos = 0;
uVertMax = uHorzMax = MAX_RANGE;
fVertSet = fHorzSet = TRUE;
uHorzPage = uHorzMax / 5;
uVertPage = uVertMax / 5;
uHorzLine = uHorzMax / 10;
uVertLine = uVertMax / 10;
}
break;

case WM_PAINT:
{
char buffer[128];
RECT rcl;

hdc = BeginPaint(hWnd, &ps);
GetClientRect(hWnd, &rcl);

sprintf(buffer, "Horizontal Thumb position = %d", uHorzPos);
TextOut(hdc, rcl.left + 20, rcl.bottom - 90, buffer, strlen(buffer));
sprintf(buffer, "Maximum Horizontal position = %d", uHorzMax);
TextOut(hdc, rcl.left + 20, rcl.bottom - 70, buffer, strlen(buffer));

sprintf(buffer, "Vertical Thumb position = %d", uVertPos);
TextOut(hdc, rcl.left + 20, rcl.bottom - 50, buffer, strlen(buffer));
sprintf(buffer, "Maximum Vertical position = %d", uVertMax);
TextOut(hdc, rcl.left + 20, rcl.bottom - 30, buffer, strlen(buffer));

EndPaint(hWnd, &ps);
}
break;

case WM_HSCROLL:
{
UINT xNewPos; /* new position */

switch (LOWORD(wParam))
{
/* User clicked the shaft left of the scroll box. */
case SB_PAGEUP:
xNewPos = uHorzPos - uHorzPage;
break;

/* User clicked the shaft right of the scroll box. */
case SB_PAGEDOWN:
xNewPos = uHorzPos + uHorzPage;
break;

/* User clicked the left arrow. */
case SB_LINEUP:
xNewPos = uHorzPos - uHorzLine;
break;

/* User clicked the right arrow. */
case SB_LINEDOWN:
xNewPos = uHorzPos + uHorzLine;
break;

case SB_TOP:
xNewPos = uHorzMax;
break;

case SB_BOTTOM:
xNewPos = 0;
break;

/* User dragged the scroll box. */
case SB_THUMBPOSITION:
case SB_THUMBTRACK:
/* if range is greater than 16 bits, then convert */
if (uHorzMax > 65535)
{
double d1;

//get the current cursor position
GetCursorPos(&Pt);
// map it to the scroll window
ScreenToClient(hWndHorzScroll, &Pt);
// multiply by the maximum horizontal position
// and store in a double to keep from overflowing
d1 = (double)Pt.x * (double)uHorzMax;
// divide by the right side of the scroll window
xNewPos = (UINT)(d1 / (double)RclHorz.right);
}
/* else just take the 16-bit value passed in HIWORD(wParam) */
else
xNewPos = HIWORD(wParam);
break;

default:
xNewPos = uHorzPos;
}

/* New position must be between 0 and the screen width. */
xNewPos = max(0, xNewPos);
xNewPos = min(uHorzMax, xNewPos);

/* Reset the current scroll position. */
uHorzPos = xNewPos;

/* Reset the scroll bar. */
if ((LOWORD(wParam) != SB_THUMBTRACK) && (LOWORD(wParam) != SB_THUMBPOSITION))
SetScrollPos(hWndHorzScroll, SB_CTL, uHorzPos, TRUE);

InvalidateRect(hWnd, NULL, TRUE);
}
break;
老熊宝宝 2002-03-15
  • 打赏
  • 举报
回复
即然用了SB_CTL,就得用SB Control的句柄,而不是窗口句柄。
下面的东西是MSDN里的:

All scroll bar functions return an error in the following cases:

The second parameter is SB_CTL, but the first parameter is not a valid handle to a scroll bar control.


The second parameter is SB_HORZ, SB_VERT, or SB_BOTH, but the first parameter points to a window that does not have a scroll bar child window
AloneWolf 2002-03-15
  • 打赏
  • 举报
回复
SCROLLINFO si;
si.cbSize = sizeof(si);
si.fMask = SIF_ALL;
VERIFY(GetScrollInfo(SB_VERT, &si));
Wugifer 2002-03-15
  • 打赏
  • 举报
回复
使用 SB_HORZ 或 SB_VERT 时,hWnd 是窗口的句柄,
使用 SB_CTL 时,hWnd 是滚动条的句柄
老熊宝宝 2002-03-15
  • 打赏
  • 举报
回复
我帮你来试试吧!
hx 2002-03-14
  • 打赏
  • 举报
回复
给个机会,让我结帖啊。。
hx 2002-03-13
  • 打赏
  • 举报
回复
各位,问题还没有解决啊。。!
帮帮我啦。。。。
要不给个代码,看看也成啊
panda_w 2002-03-11
  • 打赏
  • 举报
回复
你要保证窗口句柄是正确的
MSDN的代码,我试过了,可以的
SCROLLINFO si;
case WM_HSCROLL:
switch(LOWORD(wparam)) {
case SB_THUMBTRACK:
// Initialize SCROLLINFO structure

ZeroMemory(&si, sizeof(SCROLLINFO));
si.cbSize = sizeof(SCROLLINFO);
si.fMask = SIF_TRACKPOS;

// Call GetScrollInfo to get current tracking
// position in si.nTrackPos

if (!GetScrollInfo(hwnd, SB_HORZ, &si) )
return 1; // GetScrollInfo failed
break;
zyl910 2002-03-11
  • 打赏
  • 举报
回复
不懂!
建议到msdn.microsoft.com搜索
hx 2002-03-11
  • 打赏
  • 举报
回复
GetScrollInfo(hwnd, SB_CTL, &si)=1

但得不到nTachPos的值啊

hx 2002-03-11
  • 打赏
  • 举报
回复
我是用SB_CTL
hx 2002-03-11
  • 打赏
  • 举报
回复
我用SETSCROLLINFO也是该句柄。。可以

16,551

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Creator Browser
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧