Thread: Wm-hscroll

  1. #1
    Registered User
    Join Date
    Feb 2005
    Posts
    22

    Wm-hscroll

    I want to move a trackbar by sending messages to the dialog...
    I'm not sure exactly how I'm supposed to use it.
    I know from used spy++ that when I move the bar the it gets the msgs WM_HSCROLL npos:0-1000
    SB_THUMBTRACK
    SB_ENDSCROLL
    WM_CTLCOLORSTATIC

    Any ideas?

  2. #2
    VA National Guard The Brain's Avatar
    Join Date
    May 2004
    Location
    Manassas, VA USA
    Posts
    903

    Lightbulb #include<windows.h>

    scrollbar (window) styles:
    Code:
    WS_VSCROLL
    WS_HSCROLL
    by default, the range of a scroll bar is 0 (top or left) through 100 (bottom or right), but it's easy to change the range to something that is more convenient for the program:
    Code:
    SetScrollRange(hwnd, iBar, iMin, iMax, bRedraw);
    you can use SetScrollPos( ) to set a new thumb position withing a scroll bar range:
    Code:
    SetScrollPos(hwnd, iBar, iPos, bRedraw);

    General Strategy for Scrollbar Implementation

    Two general methods for repainting a window after scrollbar movement. The first way, is to repaint the window only once.. after the user has completed movement of the scrollbar thumb. This method basically sucks, because the user has to guess the correct location of where they wish to scroll.

    The second method (and most popular) is the repaint the window as the user is moving the scrollbar. This involves real-time processing of WM_VSCROLL and WM_HSCROLL messages. The wParam is divided into a low word and high word. The low word of wParam is a number that indicates what the mouse is doing to the scroll bar:
    Code:
    SB_LINEUP
    SB_LINELEFT
    SB_LINEDOWN
    SB_LINERIGHT
    SB_PAGEUP
    SB_PAGELEFT
    SB_PAGEDOWN
    SB_PAGERIGHT
    SB_THUMBPOSITION
    SB_THUMBTRACK
    SB_TOP
    SB_LEFT
    SB_BOTTOM
    SB_RIGHT
    SB_ENDSCROLL

    Here are some additional thoughts to consider:

    Window's responsibility for scrollbar maintenance
    • Provide a reverse-video "flash" when the user clicks the scroll bar
    • Move the thumb as the user drags the thumb within the scroll bar
    • Send scroll bar message to the window procedure of the window containing the scroll bar


    Responsibilities of your program:
    • Initialize the range and position of the scroll bar
    • Process the scroll bar messages to the window procedure
    • Update the position of the scroll bar thumb
    • Change the contents of the client area in response to a change in the scroll bar.


    Here is some example code that you can examine that may add some inside on scrollbar implementation. Here is the header file, and here is the .c driver program. (yes it is a .c file, but it's all winapi) Basically, the program will display all the "system metrics" of your computer.. but more importantly, it introduces scrollbar concept.
    Last edited by The Brain; 04-21-2005 at 03:47 AM.
    • "Problem Solving C++, The Object of Programming" -Walter Savitch
    • "Data Structures and Other Objects using C++" -Walter Savitch
    • "Assembly Language for Intel-Based Computers" -Kip Irvine
    • "Programming Windows, 5th edition" -Charles Petzold
    • "Visual C++ MFC Programming by Example" -John E. Swanke
    • "Network Programming Windows" -Jones/Ohlund
    • "Sams Teach Yourself Game Programming in 24 Hours" -Michael Morrison
    • "Mathmatics for 3D Game Programming & Computer Graphics" -Eric Lengyel

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. which WM_ to find out when mouse gets out?
    By underthesun in forum Windows Programming
    Replies: 2
    Last Post: 02-02-2005, 11:31 PM
  2. Painfully true but funny...
    By shaik786 in forum A Brief History of Cprogramming.com
    Replies: 8
    Last Post: 04-01-2003, 03:39 PM