📄 autorun.cpp
字号:
// Autorun.cpp : Defines the entry point for the application.
//
#include "stdafx.h"
// <BOOK_ADDON Chapter 11.5.5.1> *****************
#include <tchar.h>
const WCHAR tstrINSTALL[] = L"install";
const WCHAR tstrROOT[] = L"\\*";
const WCHAR tstrCAB[] = L"PCDM.MIPS_PSPC3.CAB";
const WCHAR tstrUNINST[] = L"\\Windows\\unload.exe";
const WCHAR tstrUNINST_APP[] = L"Addison Wesley Pocket-CD-Manager V1.0";
// a top-level dir with these attributes is a flash card
const DWORD dwATTRIB_CF = FILE_ATTRIBUTE_DIRECTORY | FILE_ATTRIBUTE_TEMPORARY;
void OnCardInsert()
{
HANDLE hFind = NULL;
BOOL fLoop = FALSE;
WCHAR szwFile[MAX_PATH];
WIN32_FIND_DATA fd;
SHELLEXECUTEINFO si;
// search all top-level dirs
ZeroMemory(&fd, sizeof(fd));
hFind = FindFirstFile(tstrROOT, &fd);
if (INVALID_HANDLE_VALUE == hFind)
return;
szwFile[0] = 0;
do
{
// check the dir attributes
if (dwATTRIB_CF == (dwATTRIB_CF & fd.dwFileAttributes))
{
// we have found the first CF Card
lstrcpy(szwFile, fd.cFileName);
break;
}
fLoop = FindNextFile(hFind, &fd);
} while (fLoop);
FindClose(hFind);
// exit if we did not find a CF Card
if (!szwFile[0]) return;
// create the full filename of the CAB file
lstrcat(szwFile, L"\\");
lstrcat(szwFile, tstrCAB);
// run the CAB
ZeroMemory(&si, sizeof(si));
si.cbSize = sizeof(si);
si.lpFile = szwFile;
ShellExecuteEx(&si);
return;
}
void OnCardEject()
{
SHELLEXECUTEINFO si;
// run the uninstall program to uninstall our app
ZeroMemory(&si, sizeof(si));
si.cbSize = sizeof(si);
si.lpFile = tstrUNINST;
si.lpParameters = tstrUNINST_APP;
ShellExecuteEx(&si);
}
// </BOOK_ADDON Chapter 11.5.5.1> *****************
int WINAPI WinMain( HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)
{
// <BOOK_ADDON Chapter 11.5.5.1> *****************
if (0 == lstrcmpi(lpCmdLine, tstrINSTALL))
OnCardInsert();
else
OnCardEject();
// </BOOK_ADDON Chapter 11.5.5.1> *****************
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -