📄 statwnd.cpp
字号:
//======================================================================
// StatWnd - Static control window code
//
// Written for the book Programming Windows CE
// Copyright (C) 2007 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 StatWndWindowProc
const struct decodeUINT StatWndMessages[] = {
WM_CREATE, DoCreateStatWnd,
WM_COMMAND, DoCommandStatWnd,
};
// Structure defining the controls in the window
CTLWNDSTRUCT Stats [] = {
{TEXT ("static"), IDC_LEFTTEXT, TEXT ("Left text"),
10, 10, 120, 23, SS_LEFT | SS_NOTIFY},
{TEXT ("static"), IDC_RIGHTTEXT, TEXT ("Right text"),
10, 35, 120, 23, SS_RIGHT},
{TEXT ("static"), IDC_CENTERTEXT, TEXT ("Center text"),
10, 60, 120, 23, SS_CENTER | WS_BORDER},
};
// Structure labeling the static control WM_COMMAND notifications
NOTELABELS nlStatic[] = {{TEXT ("STN_CLICKED"), 0},
{TEXT ("STN_ENABLE "), 2},
{TEXT ("STN_DISABLE"), 3},
};
//----------------------------------------------------------------------
// InitStatWnd - StatWnd window initialization
//
int InitStatWnd (HINSTANCE hInstance) {
WNDCLASS wc;
// Register application StatWnd window class.
wc.style = 0; // Window style
wc.lpfnWndProc = StatWndProc; // 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 = STATWND; // Window class name
if (RegisterClass (&wc) == 0) return 1;
return 0;
}
//======================================================================
// Message handling procedures for StatWindow
//----------------------------------------------------------------------
// StatWndProc - Callback function for application window
//
LRESULT CALLBACK StatWndProc (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(StatWndMessages); i++) {
if (wMsg == StatWndMessages[i].Code)
return (*StatWndMessages[i].Fxn)(hWnd, wMsg, wParam, lParam);
}
return DefWindowProc (hWnd, wMsg, wParam, lParam);
}
//----------------------------------------------------------------------
// DoCreateStatWnd - Process WM_CREATE message for window.
//
LRESULT DoCreateStatWnd (HWND hWnd, UINT wMsg, WPARAM wParam,
LPARAM lParam) {
int i;
for (i = 0; i < dim(Stats); i++) {
CreateWindow (Stats[i].szClass, Stats[i].szTitle,
Stats[i].lStyle | WS_VISIBLE | WS_CHILD,
Stats[i].x, Stats[i].y, Stats[i].cx, Stats[i].cy,
hWnd, (HMENU) Stats[i].nID, hInst, NULL);
}
return 0;
}
//----------------------------------------------------------------------
// DoCommandStatWnd - Process WM_COMMAND message for window.
//
LRESULT DoCommandStatWnd (HWND hWnd, UINT wMsg, WPARAM wParam,
LPARAM lParam) {
PrintCmdMessage (hWnd, wParam, lParam, nlStatic, dim (nlStatic));
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -