//----------------------------------------------------------------------
// DoCommandStatWnd - Process WM_COMMAND message for window.
//
LRESULT DoCommandStatWnd (HWND hWnd, UINT wMsg, WPARAM wParam,
LPARAM lParam) {
TCHAR szOut[128];
int i;
for (i = 0; i < dim(nlStatic); i++) {
if (HIWORD (wParam) == nlStatic[i].wNotification) {
lstrcpy (szOut, nlStatic[i].pszLabel);
break;
}
}
if (i == dim(nlStatic))
wsprintf (szOut, TEXT ("notification: %x"), HIWORD (wParam));
SendMessage (GetParent (hWnd), MYMSG_ADDLINE, wParam,
(LPARAM)szOut);
return 0;
}
ScrollWnd.cpp
//======================================================================
// ScrollWnd - Scroll bar control window code
//
// Written for the book Programming Windows CE
// Copyright (C) 2001 Douglas Boling
//======================================================================
#include <windows.h> // For all that Windows stuff
#include "Ctlview.h" // Program-specific stuff
extern HINSTANCE hInst;
//----------------------------------------------------------------------
// Global data
//
// Message dispatch table for ScrollWndWindowProc
const struct decodeUINT ScrollWndMessages[] = {
WM_CREATE, DoCreateScrollWnd,
WM_HSCROLL, DoVScrollScrollWnd,
WM_VSCROLL, DoVScrollScrollWnd,
};
// Structure defining the controls in the window
CTLWNDSTRUCT Scrolls [] = {
{TEXT ("Scrollbar"), IDC_LRSCROLL, TEXT (""),
10, 10, 150, 23, SBS_HORZ},
{TEXT ("Scrollbar"), IDC_UDSCROLL, TEXT (""),
180, 10, 23, 120, SBS_VERT},
};
// Structure labeling the scroll bar control scroll codes for WM_VSCROLL
NOTELABELS nlVScroll[] = {{TEXT ("SB_LINEUP "), 0},
{TEXT ("SB_LINEDOWN "), 1},
{TEXT ("SB_PAGEUP "), 2},
{TEXT ("SB_PAGEDOWN "), 3},
{TEXT ("SB_THUMBPOSITION"), 4},
{TEXT ("SB_THUMBTRACK "), 5},
{TEXT ("SB_TOP "), 6},
{TEXT ("SB_BOTTOM "), 7},
{TEXT ("SB_ENDSCROLL "), 8},
};
// Structure labeling the scroll bar control scroll codes for WM_HSCROLL
NOTELABELS nlHScroll[] = {{TEXT ("SB_LINELEFT "), 0},
{TEXT ("SB_LINERIGHT "), 1},
{TEXT ("SB_PAGELEFT "), 2},
{TEXT ("SB_PAGERIGHT "), 3},
{TEXT ("SB_THUMBPOSITION"), 4},
{TEXT ("SB_THUMBTRACK "), 5},
{TEXT ("SB_LEFT "), 6},
{TEXT ("SB_RIGHT "), 7},
{TEXT ("SB_ENDSCROLL "), 8},
};
//----------------------------------------------------------------------
// InitScrollWnd - ScrollWnd window initialization
//
int InitScrollWnd (HINSTANCE hInstance) {
WNDCLASS wc;
// Register application ScrollWnd window class.
wc.style = 0; // Window style
wc.lpfnWndProc = ScrollWndProc; // Callback function
wc.cbClsExtra = 0; // Extra class data
wc.cbWndExtra = 0; // Extra window data
wc.hInstance = hInstance; // Owner handle
wc.hIcon = NULL, // Application icon
wc.hCursor = LoadCursor (NULL, IDC_ARROW);// Default cursor
wc.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH);
wc.lpszMenuName = NULL; // Menu name
wc.lpszClassName = SCROLLWND; // Window class name
if (RegisterClass (&wc) == 0) return 1;
return 0;
}
//======================================================================
// Message handling procedures for ScrollWindow
//----------------------------------------------------------------------
// ScrollWndProc - Callback function for application window
//
LRESULT CALLBACK ScrollWndProc (HWND hWnd, UINT wMsg, WPARAM wParam,
LPARAM lParam) {
int i;
//
// Search message list to see if we need to handle this
// message. If in list, call procedure.
//
for (i = 0; i < dim(ScrollWndMessages); i++) {
if (wMsg == ScrollWndMessages[i].Code)
return (*ScrollWndMessages[i].Fxn)(hWnd, wMsg, wParam, lParam);
}
return DefWindowProc (hWnd, wMsg, wParam, lParam);
}
//----------------------------------------------------------------------
// DoCreateScrollWnd - Process WM_CREATE message for window.
//
LRESULT DoCreateScrollWnd (HWND hWnd, UINT wMsg, WPARAM wParam,
LPARAM lParam) {
int i;
for (i = 0; i < dim(Scrolls); i++) {
CreateWindow (Scrolls[i].szClass, Scrolls[i].szTitle,
Scrolls[i].lStyle | WS_VISIBLE | WS_CHILD,
Scrolls[i].x, Scrolls[i].y, Scrolls[i].cx,
Scrolls[i].cy,
hWnd, (HMENU) Scrolls[i].nID, hInst, NULL);
}
return 0;
}
//----------------------------------------------------------------------
// DoVScrollScrollWnd - Process WM_VSCROLL message for window.
//
LRESULT DoVScrollScrollWnd (HWND hWnd, UINT wMsg, WPARAM wParam,
LPARAM lParam) {
TCHAR szOut[128];
SCROLLINFO si;
int i, sPos;
// Update the report window.
if (GetDlgItem (hWnd, 101) == (HWND)lParam) {
for (i = 0; i < dim(nlVScroll); i++) {
if (LOWORD (wParam) == nlVScroll[i].wNotification) {
lstrcpy (szOut, nlVScroll[i].pszLabel);
break;
}
}
if (i == dim(nlVScroll))
wsprintf (szOut, TEXT ("notification: %x"), HIWORD (wParam));
} else {
for (i = 0; i < dim(nlHScroll); i++) {
if (LOWORD (wParam) == nlHScroll[i].wNotification) {
lstrcpy (szOut, nlHScroll[i].pszLabel);
break;
}
}
if (i == dim(nlHScroll))
wsprintf (szOut, TEXT ("notification: %x"), HIWORD (wParam));
}
SendMessage (GetParent (hWnd), MYMSG_ADDLINE, -1, (LPARAM)szOut);
// Get scroll bar position.
si.cbSize = sizeof (si);
si.fMask = SIF_POS;
GetScrollInfo ((HWND)lParam, SB_CTL, &si);
sPos = si.nPos;
// Act on the scroll code.
switch (LOWORD (wParam)) {
case SB_LINEUP: // Also SB_LINELEFT
sPos -= 2;
break;
case SB_LINEDOWN: // Also SB_LINERIGHT
sPos += 2;
break;
case SB_PAGEUP: // Also SB_PAGELEFT
sPos -= 10;
break;
case SB_PAGEDOWN: // Also SB_PAGERIGHT
sPos += 10;
break;
case SB_THUMBPOSITION:
sPos = HIWORD (wParam);
break;
}
// Check range.
if (sPos < 0)
sPos = 0;
if (sPos > 100)
sPos = 100;
// Update scroll bar position.
si.cbSize = sizeof (si);
si.nPos = sPos;
si.fMask = SIF_POS;
SetScrollInfo ((HWND)lParam, SB_CTL, &si, TRUE);
return 0;
}
// DoCommandStatWnd - Process WM_COMMAND message for window.
//
LRESULT DoCommandStatWnd (HWND hWnd, UINT wMsg, WPARAM wParam,
LPARAM lParam) {
TCHAR szOut[128];
int i;
for (i = 0; i < dim(nlStatic); i++) {
if (HIWORD (wParam) == nlStatic[i].wNotification) {
lstrcpy (szOut, nlStatic[i].pszLabel);
break;
}
}
if (i == dim(nlStatic))
wsprintf (szOut, TEXT ("notification: %x"), HIWORD (wParam));
SendMessage (GetParent (hWnd), MYMSG_ADDLINE, wParam,
(LPARAM)szOut);
return 0;
}
ScrollWnd.cpp
//======================================================================
// ScrollWnd - Scroll bar control window code
//
// Written for the book Programming Windows CE
// Copyright (C) 2001 Douglas Boling
//======================================================================
#include <windows.h> // For all that Windows stuff
#include "Ctlview.h" // Program-specific stuff
extern HINSTANCE hInst;
//----------------------------------------------------------------------
// Global data
//
// Message dispatch table for ScrollWndWindowProc
const struct decodeUINT ScrollWndMessages[] = {
WM_CREATE, DoCreateScrollWnd,
WM_HSCROLL, DoVScrollScrollWnd,
WM_VSCROLL, DoVScrollScrollWnd,
};
// Structure defining the controls in the window
CTLWNDSTRUCT Scrolls [] = {
{TEXT ("Scrollbar"), IDC_LRSCROLL, TEXT (""),
10, 10, 150, 23, SBS_HORZ},
{TEXT ("Scrollbar"), IDC_UDSCROLL, TEXT (""),
180, 10, 23, 120, SBS_VERT},
};
// Structure labeling the scroll bar control scroll codes for WM_VSCROLL
NOTELABELS nlVScroll[] = {{TEXT ("SB_LINEUP "), 0},
{TEXT ("SB_LINEDOWN "), 1},
{TEXT ("SB_PAGEUP "), 2},
{TEXT ("SB_PAGEDOWN "), 3},
{TEXT ("SB_THUMBPOSITION"), 4},
{TEXT ("SB_THUMBTRACK "), 5},
{TEXT ("SB_TOP "), 6},
{TEXT ("SB_BOTTOM "), 7},
{TEXT ("SB_ENDSCROLL "), 8},
};
// Structure labeling the scroll bar control scroll codes for WM_HSCROLL
NOTELABELS nlHScroll[] = {{TEXT ("SB_LINELEFT "), 0},
{TEXT ("SB_LINERIGHT "), 1},
{TEXT ("SB_PAGELEFT "), 2},
{TEXT ("SB_PAGERIGHT "), 3},
{TEXT ("SB_THUMBPOSITION"), 4},
{TEXT ("SB_THUMBTRACK "), 5},
{TEXT ("SB_LEFT "), 6},
{TEXT ("SB_RIGHT "), 7},
{TEXT ("SB_ENDSCROLL "), 8},
};
//----------------------------------------------------------------------
// InitScrollWnd - ScrollWnd window initialization
//
int InitScrollWnd (HINSTANCE hInstance) {
WNDCLASS wc;
// Register application ScrollWnd window class.
wc.style = 0; // Window style
wc.lpfnWndProc = ScrollWndProc; // Callback function
wc.cbClsExtra = 0; // Extra class data
wc.cbWndExtra = 0; // Extra window data
wc.hInstance = hInstance; // Owner handle
wc.hIcon = NULL, // Application icon
wc.hCursor = LoadCursor (NULL, IDC_ARROW);// Default cursor
wc.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH);
wc.lpszMenuName = NULL; // Menu name
wc.lpszClassName = SCROLLWND; // Window class name
if (RegisterClass (&wc) == 0) return 1;
return 0;
}
//======================================================================
// Message handling procedures for ScrollWindow
//----------------------------------------------------------------------
// ScrollWndProc - Callback function for application window
//
LRESULT CALLBACK ScrollWndProc (HWND hWnd, UINT wMsg, WPARAM wParam,
LPARAM lParam) {
int i;
//
// Search message list to see if we need to handle this
// message. If in list, call procedure.
//
for (i = 0; i < dim(ScrollWndMessages); i++) {
if (wMsg == ScrollWndMessages[i].Code)
return (*ScrollWndMessages[i].Fxn)(hWnd, wMsg, wParam, lParam);
}
return DefWindowProc (hWnd, wMsg, wParam, lParam);
}
//----------------------------------------------------------------------
// DoCreateScrollWnd - Process WM_CREATE message for window.
//
LRESULT DoCreateScrollWnd (HWND hWnd, UINT wMsg, WPARAM wParam,
LPARAM lParam) {
int i;
for (i = 0; i < dim(Scrolls); i++) {
CreateWindow (Scrolls[i].szClass, Scrolls[i].szTitle,
Scrolls[i].lStyle | WS_VISIBLE | WS_CHILD,
Scrolls[i].x, Scrolls[i].y, Scrolls[i].cx,
Scrolls[i].cy,
hWnd, (HMENU) Scrolls[i].nID, hInst, NULL);
}
return 0;
}
//----------------------------------------------------------------------
// DoVScrollScrollWnd - Process WM_VSCROLL message for window.
//
LRESULT DoVScrollScrollWnd (HWND hWnd, UINT wMsg, WPARAM wParam,
LPARAM lParam) {
TCHAR szOut[128];
SCROLLINFO si;
int i, sPos;
// Update the report window.
if (GetDlgItem (hWnd, 101) == (HWND)lParam) {
for (i = 0; i < dim(nlVScroll); i++) {
if (LOWORD (wParam) == nlVScroll[i].wNotification) {
lstrcpy (szOut, nlVScroll[i].pszLabel);
break;
}
}
if (i == dim(nlVScroll))
wsprintf (szOut, TEXT ("notification: %x"), HIWORD (wParam));
} else {
for (i = 0; i < dim(nlHScroll); i++) {
if (LOWORD (wParam) == nlHScroll[i].wNotification) {
lstrcpy (szOut, nlHScroll[i].pszLabel);
break;
}
}
if (i == dim(nlHScroll))
wsprintf (szOut, TEXT ("notification: %x"), HIWORD (wParam));
}
SendMessage (GetParent (hWnd), MYMSG_ADDLINE, -1, (LPARAM)szOut);
// Get scroll bar position.
si.cbSize = sizeof (si);
si.fMask = SIF_POS;
GetScrollInfo ((HWND)lParam, SB_CTL, &si);
sPos = si.nPos;
// Act on the scroll code.
switch (LOWORD (wParam)) {
case SB_LINEUP: // Also SB_LINELEFT
sPos -= 2;
break;
case SB_LINEDOWN: // Also SB_LINERIGHT
sPos += 2;
break;
case SB_PAGEUP: // Also SB_PAGELEFT
sPos -= 10;
break;
case SB_PAGEDOWN: // Also SB_PAGERIGHT
sPos += 10;
break;
case SB_THUMBPOSITION:
sPos = HIWORD (wParam);
break;
}
// Check range.
if (sPos < 0)
sPos = 0;
if (sPos > 100)
sPos = 100;
// Update scroll bar position.
si.cbSize = sizeof (si);
si.nPos = sPos;
si.fMask = SIF_POS;
SetScrollInfo ((HWND)lParam, SB_CTL, &si, TRUE);
return 0;
}