dips.c
来自「一本已经绝版的好书」· C语言 代码 · 共 147 行
C
147 行
/************************************************************
Module name: DIPS.c
Notices: Copyright (c) 1996 Jeffrey Richter
************************************************************/
#include "..\CmnHdr.H" /* See Appendix C. */
#include <Windows.H>
#include <WindowsX.H>
#include <tchar.h>
#include "Resource.h"
#include "..\DIPSLib\DIPSLib.h"
/////////////////////////////////////////////////////////////
BOOL Dlg_OnInitDialog (HWND hwnd, HWND hwndFocus,
LPARAM lParam) {
// Associate an icon with the dialog box.
chSETDLGICONS(hwnd, IDI_DIPS, IDI_DIPS);
return(TRUE);
}
/////////////////////////////////////////////////////////////
void Dlg_OnCommand (HWND hwnd, int id,
HWND hwndCtl, UINT codeNotify) {
switch (id) {
case IDC_SAVE:
case IDC_RESTORE:
case IDCANCEL:
EndDialog(hwnd, id);
break;
}
}
/////////////////////////////////////////////////////////////
BOOL CALLBACK Dlg_Proc (HWND hwnd, UINT uMsg,
WPARAM wParam, LPARAM lParam) {
switch (uMsg) {
chHANDLE_DLGMSG(hwnd, WM_INITDIALOG, Dlg_OnInitDialog);
chHANDLE_DLGMSG(hwnd, WM_COMMAND, Dlg_OnCommand);
}
return(FALSE);
}
/////////////////////////////////////////////////////////////
int WINAPI _tWinMain (HINSTANCE hinstExe,
HINSTANCE hinstPrev, LPTSTR pszCmdLine, int nCmdShow) {
HWND hwndDIPS;
HWND hwndLV;
MSG msg;
TCHAR cWhatToDo;
chWARNIFUNICODEUNDERWIN95();
// Convert command-line character to uppercase.
CharUpperBuff(pszCmdLine, 1);
cWhatToDo = pszCmdLine[0];
if ((cWhatToDo != __TEXT('S')) &&
(cWhatToDo != __TEXT('R'))) {
// An invalid command-line argument; prompt the user.
cWhatToDo = 0;
}
if (cWhatToDo == 0) {
// No command-line argument was used to tell us what to
// do; show usage dialog box and prompt the user.
switch (DialogBox(hinstExe, MAKEINTRESOURCE(IDD_DIPS),
NULL, Dlg_Proc)) {
case IDC_SAVE:
cWhatToDo = __TEXT('S');
break;
case IDC_RESTORE:
cWhatToDo = __TEXT('R');
break;
}
}
if (cWhatToDo == 0) {
// The user doesn't want to do anything.
return(0);
}
// The Desktop ListView window is the
// grandchild of the ProgMan window.
hwndLV = GetFirstChild(
GetFirstChild(FindWindow(__TEXT("ProgMan"), NULL)));
chASSERT(IsWindow(hwndLV));
// Set hook that injects our DLL into the Explorer's
// address space. After setting the hook, the DIPS hidden
// modeless dialog box is created. We send messages to
// this window to tell it what we want it to do.
chVERIFY(SetDIPSHook(
GetWindowThreadProcessId(hwndLV, NULL)));
// Wait for the DIPS server window to be created.
GetMessage(&msg, NULL, 0, 0);
// Find the handle of the hidden dialog box window.
hwndDIPS = FindWindow(NULL, __TEXT("Richter DIPS"));
// Make sure that the window was created.
chASSERT(IsWindow(hwndDIPS));
// Tell the DIPS window which ListView window to manipulate
// and whether the items should be saved or restored.
SendMessage(hwndDIPS, WM_APP, (WPARAM) hwndLV,
(cWhatToDo == __TEXT('S')));
// Tell the DIPS window to destroy itself. Use SendMessage
// instead of PostMessage so that we know the window is
// destroyed before the hook is removed.
SendMessage(hwndDIPS, WM_CLOSE, 0, 0);
// Make sure that the window was destroyed.
chASSERT(!IsWindow(hwndDIPS));
// Unhook the DLL, removing the DIPS dialog box procedure
// from the Explorer's address space.
SetDIPSHook(0);
return(0);
}
//////////////////////// End of File ////////////////////////
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?