?? tbicons.c
字號:
//======================================================================
// TBIcons - Taskbar icon demonstration for Windows CE
//
// Written for the book Programming Windows CE
// Copyright (C) 1998 Douglas Boling
//======================================================================
#include <windows.h> // For all that Windows stuff
#include "TBIcons.h" // Program-specific stuff
//----------------------------------------------------------------------
// Global data
//
const TCHAR szAppName[] = TEXT ("TBIcons");
HINSTANCE hInst; // Program instance handle
INT nIconID = 0; // ID values for taskbar icons
BOOL fPalm = FALSE;
// Message dispatch table for MainWindowProc
const struct decodeUINT MainMessages[] = {
WM_INITDIALOG, DoInitDlgMain,
WM_COMMAND, DoCommandMain,
MYMSG_TASKBARNOTIFY, DoTaskBarNotifyMain,
};
// Command Message dispatch for MainWindowProc
const struct decodeCMD MainCommandItems[] = {
IDOK, DoMainCommandExit,
IDCANCEL, DoMainCommandExit,
IDD_ADDICON, DoMainCommandAddIcon,
IDD_DELICON, DoMainCommandDelIcon,
};
//======================================================================
// Program entry point
//
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPWSTR lpCmdLine, int nCmdShow) {
hInst = hInstance;
// Display dialog box as main window.
DialogBoxParam (hInstance, szAppName, NULL, MainDlgProc, 0);
return 0;
}
//======================================================================
// Message handling procedures for main window
//----------------------------------------------------------------------
// MainDlgProc - Callback function for application window
//
BOOL CALLBACK MainDlgProc (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 FALSE;
}
//----------------------------------------------------------------------
// DoInitDlgMain - Process WM_INITDIALOG message for window.
//
BOOL DoInitDlgMain (HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam){
TCHAR szType[256];
SystemParametersInfo (SPI_GETPLATFORMTYPE, dim(szType), szType, 0);
if (lstrcmp (szType, TEXT ("Palm PC")) == 0) {
fPalm = TRUE;
PostMessage (hWnd, WM_COMMAND,
MAKELONG (IDD_ADDICON, BN_CLICKED), 0);
}
return 0;
}
//----------------------------------------------------------------------
// DoCommandMain - Process WM_COMMAND message for window.
//
BOOL DoCommandMain (HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam){
WORD idItem, wNotifyCode;
HWND hwndCtl;
INT i;
// Parse the parameters.
idItem = (WORD) LOWORD (wParam);
wNotifyCode = (WORD) HIWORD (wParam);
hwndCtl = (HWND) lParam;
// Call routine to handle control message.
for (i = 0; i < dim(MainCommandItems); i++) {
if (idItem == MainCommandItems[i].Code) {
(*MainCommandItems[i].Fxn)(hWnd, idItem, hwndCtl,
wNotifyCode);
return TRUE;
}
}
return FALSE;
}
//----------------------------------------------------------------------
// DoTaskBarNotifyMain - Process MYMSG_TASKBARNOTIFY message for window.
//
BOOL DoTaskBarNotifyMain (HWND hWnd, UINT wMsg, WPARAM wParam,
LPARAM lParam) {
TCHAR szText[128];
SetForegroundWindow (hWnd);
wsprintf (szText,
TEXT ("icon %d "), wParam);
switch (lParam) {
case WM_MOUSEMOVE:
lstrcat (szText, TEXT ("WM_MOUSEMOVE"));
break;
case WM_LBUTTONDOWN:
lstrcat (szText, TEXT ("WM_LBUTTONDOWN"));
break;
case WM_LBUTTONUP:
lstrcat (szText, TEXT ("WM_LBUTTONUP"));
break;
case WM_LBUTTONDBLCLK:
lstrcat (szText, TEXT ("WM_LBUTTONDBLCLK"));
break;
}
Add2List (hWnd, szText);
return 0;
}
//======================================================================
// Command handler routines
//----------------------------------------------------------------------
// DoMainCommandExit - Process Program Exit command.
//
LPARAM DoMainCommandExit (HWND hWnd, WORD idItem, HWND hwndCtl,
WORD wNotifyCode) {
NOTIFYICONDATA nid;
// Delete any remaining taskbar icons.
memset (&nid, 0, sizeof nid);
nid.cbSize = sizeof (NOTIFYICONDATA);
nid.hWnd = hWnd;
while (nIconID) {
nid.uID = nIconID--;
Shell_NotifyIcon (NIM_DELETE, &nid);
}
EndDialog (hWnd, 0);
return 0;
}
//----------------------------------------------------------------------
// DoMainCommandAddIcon - Process Add Icon button.
//
LPARAM DoMainCommandAddIcon (HWND hWnd, WORD idItem, HWND hwndCtl,
WORD wNotifyCode) {
NOTIFYICONDATA nid;
nIconID++;
nid.cbSize = sizeof (NOTIFYICONDATA);
nid.hWnd = hWnd;
nid.uID = nIconID;
nid.uFlags = NIF_ICON | NIF_MESSAGE; // NIF_TIP not supported
nid.uCallbackMessage = MYMSG_TASKBARNOTIFY;
nid.hIcon = LoadImage (hInst, MAKEINTRESOURCE (ID_ICON),
IMAGE_ICON, 16,16,0);
nid.szTip[0] = '\0';
Shell_NotifyIcon (NIM_ADD, &nid);
return 0;
}
//----------------------------------------------------------------------
// DoMainCommandDelIcon - Process Del Icon button.
//
LPARAM DoMainCommandDelIcon (HWND hWnd, WORD idItem, HWND hwndCtl,
WORD wNotifyCode) {
NOTIFYICONDATA nid;
// Leave one icon on for Palm-size PC, so user can get back to the
// window. Otherwise, don't delete an icon if none currently exists.
if ((fPalm && (nIconID == 1)) || (nIconID == 0))
return 0;
memset (&nid, 0, sizeof nid);
nid.cbSize = sizeof (NOTIFYICONDATA);
nid.hWnd = hWnd;
nid.uID = nIconID--;
Shell_NotifyIcon (NIM_DELETE, &nid);
return 0;
}
//----------------------------------------------------------------------
// Add2List - Add string to the report list box.
//
void Add2List (HWND hWnd, LPTSTR lpszFormat, ...) {
int i, nBuf;
TCHAR szBuffer[512];
va_list args;
va_start(args, lpszFormat);
nBuf = _vstprintf(szBuffer, lpszFormat, args);
i = SendDlgItemMessage (hWnd, IDD_OUTPUT, LB_ADDSTRING, 0,
(LPARAM)(LPCTSTR)szBuffer);
if (i != LB_ERR)
SendDlgItemMessage (hWnd, IDD_OUTPUT, LB_SETTOPINDEX, i,
(LPARAM)(LPCTSTR)szBuffer);
va_end(args);
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -