Main Page | Alphabetical List | Class List | File List | Class Members

scrollable_wnd

1.0

Content

Introduction

scrollable_wnd is a mix-in class for the great Win32GUI Lib by John Torjo. Steven Weiss has the full copyright but you can use and modify the code as long as the copyright comment persists.

scrollable_wnd takes care of all scroll-relating actions including mouse whell navigation appearing on a window. You only have to set a few parameters that manipulate the scrolling behaviour.

Download scrollable_wnd class from here.

Synopsis

namespace win32 { namespace gui {

     struct scrollable_wnd : wnd_extend<window_base, scrollable_wnd>
     {
          // c'tor
          scrollable_wnd();

          // operations
          void  total_size(unsigned cx, unsigned cy);
          SIZE  total_size() const;
          void  line_scrolling_size(int cx, int cy);
          SIZE  line_scrolling_size() const; 
          void  page_factor(float xFactor, float yFactor);
          float page_factor_x() const;
          float page_factor_y() const;
          void  wheel_factor(float yFactor);
          float wheel_factor() const;
          void  scroll_pos(unsigned x, unsigned y);
          POINT scroll_pos() const;
     };

} }


Deriving from scrollable_wnd

To make your window a scrollable_wnd you have to extend the scrollable_wnd-class as usual:
#include <win32gui/scrollable_wnd.hpp>

struct your_window : wnd_extend<dialog, your_window>, wnd_extend<scrollable_wnd, your_window>
{
     ...
};


Using scrollable_wnd

To set the total size of the client area, use the function total_size(). If the window is resized and the visible part of the client area is smaller than the total, the scrollbars are shown. scrollable_wnd automatically adjust's the scrollbar's thumb.
scrollable_wnd.jpg

A scrollable_wnd which has the total size 400 x 300



You can get the current scrolling position by calling scroll_pos(). You can also scroll to a position with this function.

There are different scrolling actions: line scrolling, page scrolling and mousewheel scrolling. You can set the amount to scroll by calling line_scrolling_size(), page_factor() and wheel_factor(). Note that only line_scrolling_size() takes total values - the other values are multiplied with the line scrolling value.

Example:
line_scrolling_size(10, 10);        // scrolls 10 pixel in each direction when line scrolling is invoked
page_factor(3, 4);                  // scrolls 30 pixel horizontally and 40 pixel vertically when page scrolling is invoked


How to draw in a scrollable_wnd

When you want to draw something in your client area (WM_PAINT / WM_ERASEBKGND) you have to take the scrolling into account. You have to get the current scrolling position and draw only the part that is visible.

About the author

steven_weiss.jpg
Currently (December 2004) I am an apprentice to Deutsche Telekom for IT specialist. I have done several projects for my company in C++, Java, SQL and PHP but my real love is C++ ;-). After finishing my apprenticeship in January I will work as a programmer in a small biotech-company.

If you find bugs, have any suggestions and/or criticism you can contact me at steven11@gmx.de

Generated on Mon Dec 27 17:34:37 2004 for scrollable_wnd by  doxygen 1.3.9.1