User Tools

Site Tools


using_20a_20pager_20control

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
using_20a_20pager_20control [2018/03/31 13:19] – external edit 127.0.0.1using_20a_20pager_20control [2024/01/05 00:21] (current) – external edit 127.0.0.1
Line 2: Line 2:
  
 //by Richard Russell, July 2010//\\ \\  A [[http://msdn.microsoft.com/en-us/library/bb760855.aspx|pager control]] is useful if you have a child window which is too big to be displayed in its entirety. The pager control allows you to scroll into view the part of the child control in which you are interested.\\ \\  A typical use of a pager control is to allow you to scroll through a toolbar which is too wide to fit across your main window. Another use, and the one I will take as an example, is to allow you to scroll through a dialogue box which would otherwise be too big.\\ \\  In order to use a pager control the first step is to perform some initialisation, as follows:\\  //by Richard Russell, July 2010//\\ \\  A [[http://msdn.microsoft.com/en-us/library/bb760855.aspx|pager control]] is useful if you have a child window which is too big to be displayed in its entirety. The pager control allows you to scroll into view the part of the child control in which you are interested.\\ \\  A typical use of a pager control is to allow you to scroll through a toolbar which is too wide to fit across your main window. Another use, and the one I will take as an example, is to allow you to scroll through a dialogue box which would otherwise be too big.\\ \\  In order to use a pager control the first step is to perform some initialisation, as follows:\\ 
 +<code bb4w>
         INSTALL @lib$+"WINLIB2"         INSTALL @lib$+"WINLIB2"
         INSTALL @lib$+"WINLIB5A"         INSTALL @lib$+"WINLIB5A"
Line 28: Line 29:
         iccx.dwICC% = ICC_PAGESCROLLER_CLASS         iccx.dwICC% = ICC_PAGESCROLLER_CLASS
         SYS "InitCommonControlsEx", iccx{}         SYS "InitCommonControlsEx", iccx{}
 +</code>
 Note that **WINLIB2** is installed for the purpose of creating the dialogue box; it is not required for the pager control itself. The **ON CLOSE** and **ON ERROR** statements ensure that the dialogue box is closed when the program is terminated. The **PROCcleanup** routine is listed below.\\ \\  The next step is to create the pager control:\\  Note that **WINLIB2** is installed for the purpose of creating the dialogue box; it is not required for the pager control itself. The **ON CLOSE** and **ON ERROR** statements ensure that the dialogue box is closed when the program is terminated. The **PROCcleanup** routine is listed below.\\ \\  The next step is to create the pager control:\\ 
 +<code bb4w>
         x% = 100         x% = 100
         y% = 100         y% = 100
Line 36: Line 39:
         \                         0, PGS_VERT OR WS_BORDER, 0)         \                         0, PGS_VERT OR WS_BORDER, 0)
         IF hPager% = 0 ERROR 100, "Cannot create pager control"         IF hPager% = 0 ERROR 100, "Cannot create pager control"
 +</code>
 The position and size have been set to arbitrary values for the purpose of the demonstration. The **PGS_VERT** style signifies that the pager control allows vertical scrolling; if you want to enable horizontal scrolling specify the **PGS_HORZ** style (you cannot enable both at the same time).\\ \\  The appearance of the pager control and its scroll buttons can be changed by sending various messages; see this [[http://msdn.microsoft.com/en-us/library/bb760857.aspx|MSDN page]] for details.\\ \\  Now we create the child window that we wish to scroll. In this case, purely for the purposes of the example, it is a dialogue box containing a grid of 160 pushbuttons:\\  The position and size have been set to arbitrary values for the purpose of the demonstration. The **PGS_VERT** style signifies that the pager control allows vertical scrolling; if you want to enable horizontal scrolling specify the **PGS_HORZ** style (you cannot enable both at the same time).\\ \\  The appearance of the pager control and its scroll buttons can be changed by sending various messages; see this [[http://msdn.microsoft.com/en-us/library/bb760857.aspx|MSDN page]] for details.\\ \\  Now we create the child window that we wish to scroll. In this case, purely for the purposes of the example, it is a dialogue box containing a grid of 160 pushbuttons:\\ 
 +<code bb4w>
         Dialog% = FN_newdialog("Pager test", 0, 0, 120, 1000, 8, 10000)         Dialog% = FN_newdialog("Pager test", 0, 0, 120, 1000, 8, 10000)
         id% = 100         id% = 100
Line 45: Line 50:
           NEXT x%           NEXT x%
         NEXT y%         NEXT y%
 +</code>
 Before we display the dialogue box we need to perform a little magic on its template:\\  Before we display the dialogue box we need to perform a little magic on its template:\\ 
 +<code bb4w>
         Dialog%!16 = (Dialog%!16 AND NOT (WS_POPUP OR WS_DLGFRAME)) OR \         Dialog%!16 = (Dialog%!16 AND NOT (WS_POPUP OR WS_DLGFRAME)) OR \
         \            WS_CHILD OR CCS_NORESIZE         \            WS_CHILD OR CCS_NORESIZE
         !(Dialog%!4+8) = hPager% : REM Set parent         !(Dialog%!4+8) = hPager% : REM Set parent
         PROC_showdialog(Dialog%)         PROC_showdialog(Dialog%)
 +</code>
 The first line modifies the dialogue box's style; in particular the title bar is removed and it is made a child window. The second line sets the dialogue box's parent to be the pager control we created earlier.\\ \\  We have to tell the pager control the dimensions of the child window it contains, so it can calculate when to display the scroll buttons. This is done as follows:\\  The first line modifies the dialogue box's style; in particular the title bar is removed and it is made a child window. The second line sets the dialogue box's parent to be the pager control we created earlier.\\ \\  We have to tell the pager control the dimensions of the child window it contains, so it can calculate when to display the scroll buttons. This is done as follows:\\ 
 +<code bb4w>
         DIM rc{l%,t%,r%,b%}         DIM rc{l%,t%,r%,b%}
         SYS "GetWindowRect", !Dialog%, rc{}         SYS "GetWindowRect", !Dialog%, rc{}
         PROCsetnotify(rc.r%-rc.l%, rc.b%-rc.t%)         PROCsetnotify(rc.r%-rc.l%, rc.b%-rc.t%)
 +</code>
 The **PROCsetnotify** routine is listed below.\\ \\  There is just one more step, which is to 'assign' the dialogue box to the pager control:\\  The **PROCsetnotify** routine is listed below.\\ \\  There is just one more step, which is to 'assign' the dialogue box to the pager control:\\ 
 +<code bb4w>
         SYS "SendMessage", hPager%, PGM_SETCHILD, 0, !Dialog%         SYS "SendMessage", hPager%, PGM_SETCHILD, 0, !Dialog%
 +</code>
 Now the pager control, containing the scrollable dialogue box, should be displayed. The rest of the program is simulated by this simple loop:\\  Now the pager control, containing the scrollable dialogue box, should be displayed. The rest of the program is simulated by this simple loop:\\ 
 +<code bb4w>
         REPEAT         REPEAT
           WAIT 0           WAIT 0
         UNTIL FALSE         UNTIL FALSE
         END         END
 +</code>
 In practice you will want to do something rather more useful!\\ \\  Here are the listings of the **PROCsetnotify** and **PROCcleanup** routines:\\  In practice you will want to do something rather more useful!\\ \\  Here are the listings of the **PROCsetnotify** and **PROCcleanup** routines:\\ 
 +<code bb4w>
         DEF PROCsetnotify(iWidth%, iHeight%)         DEF PROCsetnotify(iWidth%, iHeight%)
         LOCAL L%, P%, oldwndproc, newwndproc, exit, notify         LOCAL L%, P%, oldwndproc, newwndproc, exit, notify
Line 91: Line 106:
         hPager% += 0 : IF hPager% PROC_closewindow(hPager%)         hPager% += 0 : IF hPager% PROC_closewindow(hPager%)
         ENDPROC         ENDPROC
 +</code>
 Needless to say, you should incorporate in the **PROCcleanup** routine any cleanup operations needed by the rest of your program. Needless to say, you should incorporate in the **PROCcleanup** routine any cleanup operations needed by the rest of your program.
using_20a_20pager_20control.1522502388.txt.gz · Last modified: 2024/01/05 00:16 (external edit)