开发者

Help with WinAPI scroll bars

Right now I have a window with horizontal ad vertical scrollbars. I use these parameters to initialize it.

//Set OGL Frame scroll bar
    SCROLLINFO inf;
    inf.cbSize = 开发者_运维知识库sizeof(SCROLLINFO);
    inf.fMask = SIF_PAGE | SIF_POS;
    inf.nPage = 20;
    inf.nPos = 30;

It creates them in the center and I like their size, but when I scroll I multiply by 50 which creates chopiness. How could I add more resolution to the bars and still keep the same thumb size. Is there a way I can calculate the size and position of the bar based on the above parameters?

Thanks


Right, here's my solution even though one is already accepted.

Everytime I have issues with the windows controls I use Controlspy to experiment with them. Controlspy also lists all the different messages that can be sent to the different controls. Find one that is similar to what you are trying to do and check that specific message on MSDN.


Here is my old chunk of code that handles scrolling events. You could use the same "customized" approach.

Note that it's (probably) not the best way of solving this problem, but still a working one.

  case WM_VSCROLL:
    {
      TEXTHANDLER * handler = ((TEXTHANDLER *)GetProp(hWnd, "TEXTHANDLER"));
      BOOL needInvalidation = TRUE;
      SCROLLINFO   si; 

      si.cbSize = sizeof(si);
      si.fMask  = SIF_ALL;
      GetScrollInfo(hWnd, SB_VERT, &si);

      switch (LOWORD(wParam))
      {
      case SB_LINEUP: 
        si.nPos -= 1;
        if (si.nPos < 0)
        {
          si.nPos = 0;
          needInvalidation = FALSE;
        }
        break;

      case SB_LINEDOWN: 
        si.nPos += 1;
        if (si.nPos > si.nMax)
        {
          si.nPos = si.nMax;
          needInvalidation = FALSE;
        }
        break;

      case SB_PAGEUP:
        si.nPos -= handler->renderer->cyCount;
        if (si.nPos < 0)
        {
          si.nPos = 0;
          needInvalidation = FALSE;
        }
        break;

      case SB_PAGEDOWN:
        si.nPos += handler->renderer->cyCount;
        if (si.nPos > si.nMax)
        {
          si.nPos = si.nMax;
          needInvalidation = FALSE;
        }
        break;

      case SB_THUMBTRACK: 
        si.nPos = si.nTrackPos;
        break;
      }

      si.fMask = SIF_POS;
      SetScrollInfo(hWnd, SB_VERT, &si, TRUE);

      // Set new text renderer parameters
      handler->renderer->yPos = si.nPos;

      if (needInvalidation) InvalidateRect(hWnd, NULL, FALSE);
      return 0;
    }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜