home *** CD-ROM | disk | FTP | other *** search
- /****************************************************************************
- * MODULE : scroll.c
- * AUTHOR : Steven B. Katz
- * DATE : 30-NOV-1990
- *
- * DESCRIPTION : This program is sample code to demonstrate how to create
- * a scrollable dialog box.
- *
- * If you have any questions, I can be reached on Compuserve through
- * Bill Gutches, 76477,3044
- *
- ****************************************************************************/
- #include "windows.h"
- #include "scroll.h"
- #include "scrdef.h"
-
- /*
- These values are used for calculating the scroll position of the dialog
- box. These values were calculated by trial and error and will be different
- for each dialog box. There is probably a way to calculate them, however for
- this example I just hard coded them. If this was to be a resizeable
- scrollable dialog box, these values would have to be calulated dynamically.
- */
- #define SCROLLMAX 130
- #define SCROLLINC 10
-
- HANDLE hInst;
-
- int PASCAL WinMain(hInstance, hPrevInstance, lpCmdLine, nCmdShow)
- HANDLE hInstance;
- HANDLE hPrevInstance;
- LPSTR lpCmdLine;
- int nCmdShow;
- {
- MSG msg;
-
- if (!hPrevInstance)
- if (!InitApplication(hInstance))
- return (FALSE);
-
- if (!InitInstance(hInstance, nCmdShow))
- return (FALSE);
-
- while (GetMessage(&msg, NULL, NULL, NULL)) {
- TranslateMessage(&msg);
- DispatchMessage(&msg);
- }
- return (msg.wParam);
- }
-
-
-
- BOOL InitApplication(hInstance)
- HANDLE hInstance; /* current instance */
- {
- WNDCLASS wc;
-
- wc.style = NULL;
- wc.lpfnWndProc = MainWndProc;
-
- wc.cbClsExtra = 0;
- wc.cbWndExtra = 0;
- wc.hInstance = hInstance;
- wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
- wc.hCursor = LoadCursor(NULL, IDC_ARROW);
- wc.hbrBackground = GetStockObject(WHITE_BRUSH);
- wc.lpszMenuName = "ScrollMenu";
- wc.lpszClassName = "ScrollWClass";
-
- return (RegisterClass(&wc));
-
- }
-
-
-
- BOOL InitInstance(hInstance, nCmdShow)
- HANDLE hInstance;
- int nCmdShow;
- {
- HWND hWnd;
-
- hInst = hInstance;
-
- hWnd = CreateWindow(
- "ScrollWClass",
- "Scroll Application",
- WS_OVERLAPPEDWINDOW,
- 0,
- 0,
- CW_USEDEFAULT,
- CW_USEDEFAULT,
- NULL,
- NULL,
- hInstance,
- NULL
- );
-
- if (!hWnd)
- return (FALSE);
-
- ShowWindow(hWnd, nCmdShow);
- UpdateWindow(hWnd);
- return (TRUE);
-
- }
-
-
- long FAR PASCAL MainWndProc(hWnd, message, wParam, lParam)
- HWND hWnd;
- unsigned message;
- WORD wParam;
- LONG lParam;
- {
- FARPROC lpProcAbout;
-
- switch (message) {
- case WM_COMMAND:
- switch (wParam) {
- case IDM_SCROLL:
- lpProcAbout = MakeProcInstance(ScrollProc, hInst);
- DialogBox(hInst,"Scroll", hWnd, lpProcAbout);
- FreeProcInstance(lpProcAbout);
- break;
-
- default:
- return (DefWindowProc(hWnd, message, wParam, lParam));
- }
- break;
-
- case WM_DESTROY: /* message: window being destroyed */
- PostQuitMessage(0);
- break;
-
- default: /* Passes it on if unproccessed */
- return (DefWindowProc(hWnd, message, wParam, lParam));
- }
- return (NULL);
- }
-
-
-
- BOOL FAR PASCAL ScrollProc(hDlg, message, wParam, lParam)
- HWND hDlg;
- unsigned message;
- WORD wParam;
- LONG lParam;
- {
- static int iScrollPos;
-
- switch (message) {
- case WM_INITDIALOG:
- iScrollPos = 0;
- SetScrollRange(hDlg,SB_VERT, 0, SCROLLMAX, FALSE);
- SetScrollPos(hDlg,SB_VERT,-iScrollPos,TRUE);
- return (TRUE);
-
- case WM_VSCROLL:
- switch (wParam) {
- case SB_PAGEUP:
- case SB_LINEUP:
- if (iScrollPos == 0)
- break;
- ScrollWindow(hDlg, 0, SCROLLINC, NULL,NULL);
- iScrollPos += SCROLLINC;
- SetScrollPos(hDlg,SB_VERT,-iScrollPos,TRUE);
- UpdateWindow(hDlg);
- break;
-
- case SB_PAGEDOWN:
- case SB_LINEDOWN:
- if (iScrollPos <= -SCROLLMAX)
- break;
- ScrollWindow(hDlg, 0, -SCROLLINC, NULL,NULL);
- iScrollPos -= SCROLLINC;
- SetScrollPos(hDlg,SB_VERT,-iScrollPos,TRUE);
- UpdateWindow(hDlg);
- break;
- }
- break;
-
- case WM_COMMAND:
- switch (wParam) {
- case IDOK:
- EndDialog(hDlg, TRUE);
- return (TRUE);
- break;
-
- case IDCANCEL:
- EndDialog(hDlg, FALSE);
- return (FALSE);
- }
- break;
- }
- return (FALSE);
- }