?? listwnd.c
字號:
//======================================================================
// ListWnd - List box control window code
//
// Written for the book Programming Windows CE
// Copyright (C) 1998 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 ListWndWindowProc
const struct decodeUINT ListWndMessages[] = {
WM_CREATE, DoCreateListWnd,
WM_COMMAND, DoCommandListWnd,
};
// Structure defining the controls in the window
CTLWNDSTRUCT Lists[] = {
{TEXT ("combobox"), IDC_COMBOBOX, TEXT (""), 10, 10, 170, 100,
WS_VSCROLL},
{TEXT ("Listbox"), IDC_SNGLELIST, TEXT (""), 10, 35, 100, 120,
WS_VSCROLL | LBS_NOTIFY},
{TEXT ("Listbox"), IDC_MULTILIST, TEXT (""), 115, 35, 100, 120,
WS_VSCROLL | LBS_EXTENDEDSEL | LBS_NOTIFY}
};
// Structure labeling the list box control WM_COMMAND notifications
NOTELABELS nlList[] = {{TEXT ("LBN_ERRSPACE "), (-2)},
{TEXT ("LBN_SELCHANGE"), 1},
{TEXT ("LBN_DBLCLK "), 2},
{TEXT ("LBN_SELCANCEL"), 3},
{TEXT ("LBN_SETFOCUS "), 4},
{TEXT ("LBN_KILLFOCUS"), 5},
};
// Structure labeling the combo box control WM_COMMAND notifications
NOTELABELS nlCombo[] = {{TEXT ("CBN_ERRSPACE "), (-1)},
{TEXT ("CBN_SELCHANGE "), 1},
{TEXT ("CBN_DBLCLK "), 2},
{TEXT ("CBN_SETFOCUS "), 3},
{TEXT ("CBN_KILLFOCUS "), 4},
{TEXT ("CBN_EDITCHANGE "), 5},
{TEXT ("CBN_EDITUPDATE "), 6},
{TEXT ("CBN_DROPDOWN "), 7},
{TEXT ("CBN_CLOSEUP "), 8},
{TEXT ("CBN_SELENDOK "), 9},
{TEXT ("CBN_SELENDCANCEL"), 10},
};
//----------------------------------------------------------------------
// InitListWnd - ListWnd window initialization
//
int InitListWnd (HINSTANCE hInstance) {
WNDCLASS wc;
// Register application ListWnd window class.
wc.style = 0; // Window style
wc.lpfnWndProc = ListWndProc; // 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 = NULL; // Default cursor
wc.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH);
wc.lpszMenuName = NULL; // Menu name
wc.lpszClassName = LISTWND; // Window class name
if (RegisterClass (&wc) == 0) return 1;
return 0;
}
//======================================================================
// Message handling procedures for ListWindow
//----------------------------------------------------------------------
// ListWndProc - Callback function for application window
//
LRESULT CALLBACK ListWndProc (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(ListWndMessages); i++) {
if (wMsg == ListWndMessages[i].Code)
return (*ListWndMessages[i].Fxn)(hWnd, wMsg, wParam, lParam);
}
return DefWindowProc (hWnd, wMsg, wParam, lParam);
}
//----------------------------------------------------------------------
// DoCreateListWnd - Process WM_CREATE message for window.
//
LRESULT DoCreateListWnd (HWND hWnd, UINT wMsg, WPARAM wParam,
LPARAM lParam) {
INT i;
TCHAR szOut[64];
for (i = 0; i < dim(Lists); i++) {
CreateWindow (Lists[i].szClass, Lists[i].szTitle,
Lists[i].lStyle | WS_VISIBLE | WS_CHILD | WS_BORDER,
Lists[i].x, Lists[i].y, Lists[i].cx, Lists[i].cy,
hWnd, (HMENU) Lists[i].nID, hInst, NULL);
}
for (i = 0; i < 20; i++) {
wsprintf (szOut, TEXT ("Item %d"), i);
SendDlgItemMessage (hWnd, IDC_SNGLELIST, LB_ADDSTRING, 0,
(LPARAM)szOut);
SendDlgItemMessage (hWnd, IDC_MULTILIST, LB_ADDSTRING, 0,
(LPARAM)szOut);
SendDlgItemMessage (hWnd, IDC_COMBOBOX, CB_ADDSTRING, 0,
(LPARAM)szOut);
}
// Set initial selection.
SendDlgItemMessage (hWnd, IDC_COMBOBOX, CB_SETCURSEL, 0, 0);
return 0;
}
//----------------------------------------------------------------------
// DoCommandListWnd - Process WM_COMMAND message for window.
//
LRESULT DoCommandListWnd (HWND hWnd, UINT wMsg, WPARAM wParam,
LPARAM lParam) {
TCHAR szOut[128];
INT i;
if (LOWORD (wParam) == IDC_COMBOBOX) {
for (i = 0; i < dim(nlCombo); i++) {
if (HIWORD (wParam) == nlCombo[i].wNotification) {
lstrcpy (szOut, nlCombo[i].pszLabel);
break;
}
}
if (i == dim(nlList))
wsprintf (szOut, TEXT ("notification: %x"), HIWORD (wParam));
} else {
for (i = 0; i < dim(nlList); i++) {
if (HIWORD (wParam) == nlList[i].wNotification) {
lstrcpy (szOut, nlList[i].pszLabel);
break;
}
}
if (i == dim(nlList))
wsprintf (szOut, TEXT ("notification: %x"), HIWORD (wParam));
}
SendMessage (GetParent (hWnd), MYMSG_ADDLINE, wParam,
(LPARAM)szOut);
return 0;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -