?? textdemo.c
字號:
//======================================================================
// TextDemo - Text output demo
//
// Written for the book Programming Windows CE
// Copyright (C) 1998 Douglas Boling
//
//======================================================================
#include <windows.h> // For all that Windows stuff
#include <commctrl.h> // Command bar includes
#include "TextDemo.h" // Program-specific stuff
//----------------------------------------------------------------------
// Global data
//
const TCHAR szAppName[] = TEXT ("TextDemo");
HINSTANCE hInst; // Program instance handle
// Message dispatch table for MainWindowProc
const struct decodeUINT MainMessages[] = {
WM_CREATE, DoCreateMain,
WM_PAINT, DoPaintMain,
WM_DESTROY, DoDestroyMain,
};
//======================================================================
//
// Program Entry Point
//
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPWSTR lpCmdLine, int nCmdShow) {
MSG msg;
int rc = 0;
// Initialize application
rc = InitApp (hInstance);
if (rc) return rc;
// Initialize this instance
if ((rc = InitInstance (hInstance, lpCmdLine, nCmdShow)) != 0)
return rc;
// Application message loop
while (GetMessage (&msg, NULL, 0, 0)) {
TranslateMessage (&msg);
DispatchMessage (&msg);
}
// Instance cleanup
return TermInstance (hInstance, msg.wParam);
}
//----------------------------------------------------------------------
// InitApp - Application initialization
//
int InitApp (HINSTANCE hInstance) {
WNDCLASS wc;
// Register application main window class.
wc.style = 0; // Window style
wc.lpfnWndProc = MainWndProc; // 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 = szAppName; // Window class name
if (RegisterClass (&wc) == 0) return 1;
return 0;
}
//----------------------------------------------------------------------
// InitInstance - Instance initialization
//
int InitInstance (HINSTANCE hInstance, LPWSTR lpCmdLine, int nCmdShow){
HWND hWnd;
// Save program instance handle in global variable.
hInst = hInstance;
// Create main window.
hWnd = CreateWindow (szAppName, // Window class
TEXT("TextDemo"), // Window title
WS_VISIBLE, // Style flags
CW_USEDEFAULT, // x position
CW_USEDEFAULT, // y position
CW_USEDEFAULT, // Initial width
CW_USEDEFAULT, // Initial height
NULL, // Parent
NULL, // Menu, must be null
hInstance, // Application instance
NULL); // Pointer to create
// parameters
// Return fail code if window not created.
if ((!hWnd) || (!IsWindow (hWnd))) return 0x10;
// Standard show and update calls
ShowWindow (hWnd, nCmdShow);
UpdateWindow (hWnd);
return 0;
}
//----------------------------------------------------------------------
// TermInstance - Program cleanup
//
int TermInstance (HINSTANCE hInstance, int nDefRC) {
return nDefRC;
}
//======================================================================
// Message handling procedures for MainWindow
//
//----------------------------------------------------------------------
// MainWndProc - Callback function for application window
//
LRESULT CALLBACK MainWndProc(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(MainMessages); i++) {
if (wMsg == MainMessages[i].Code)
return (*MainMessages[i].Fxn)(hWnd, wMsg, wParam, lParam);
}
return DefWindowProc (hWnd, wMsg, wParam, lParam);
}
//----------------------------------------------------------------------
// DoCreateMain - Process WM_CREATE message for window.
//
LRESULT DoCreateMain (HWND hWnd, UINT wMsg, WPARAM wParam,
LPARAM lParam) {
HWND hwndCB;
// Create a command bar.
hwndCB = CommandBar_Create (hInst, hWnd, IDC_CMDBAR);
// Add exit button to command bar.
CommandBar_AddAdornments (hwndCB, 0, 0);
return 0;
}
//----------------------------------------------------------------------
// DoPaintMain - Process WM_PAINT message for window.
//
LRESULT DoPaintMain (HWND hWnd, UINT wMsg, WPARAM wParam,
LPARAM lParam) {
PAINTSTRUCT ps;
RECT rect, rectCli;
HBRUSH hbrOld;
HDC hdc;
INT i, cy;
DWORD dwColorTable[] = {0x00000000, 0x00808080,
0x00cccccc, 0x00ffffff};
// Adjust the size of the client rect to take into account
// the command bar height.
GetClientRect (hWnd, &rectCli);
rectCli.top += CommandBar_Height (GetDlgItem (hWnd, IDC_CMDBAR));
hdc = BeginPaint (hWnd, &ps);
// Get the height and length of the string
DrawText (hdc, TEXT ("Hello Windows CE"), -1, &rect,
DT_CALCRECT | DT_CENTER | DT_SINGLELINE);
cy = rect.bottom - rect.top + 5;
// Draw black rectangle on right half of window
hbrOld = SelectObject (hdc, GetStockObject (BLACK_BRUSH));
Rectangle (hdc, rectCli.left + (rectCli.right - rectCli.left) / 2,
rectCli.top, rectCli.right, rectCli.bottom);
SelectObject (hdc, hbrOld);
rectCli.bottom = rectCli.top + cy;
SetBkMode (hdc, TRANSPARENT);
for (i = 0; i < 4; i++) {
SetTextColor (hdc, dwColorTable[i]);
SetBkColor (hdc, dwColorTable[3-i]);
DrawText (hdc, TEXT ("Hello Windows CE"), -1, &rectCli,
DT_CENTER | DT_SINGLELINE);
rectCli.top += cy;
rectCli.bottom += cy;
}
SetBkMode (hdc, OPAQUE);
for (i = 0; i < 4; i++) {
SetTextColor (hdc, dwColorTable[i]);
SetBkColor (hdc, dwColorTable[3-i]);
DrawText (hdc, TEXT ("Hello Windows CE"), -1, &rectCli,
DT_CENTER | DT_SINGLELINE);
rectCli.top += cy;
rectCli.bottom += cy;
}
EndPaint (hWnd, &ps);
return 0;
}
//----------------------------------------------------------------------
// DoDestroyMain - Process WM_DESTROY message for window.
//
LRESULT DoDestroyMain (HWND hWnd, UINT wMsg, WPARAM wParam,
LPARAM lParam) {
PostQuitMessage (0);
return 0;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -