mciSendString(_T("Set CDAudio Door Open Wait"), NULL, 0, NULL);
mciSendString(_T("Set CDAudio Door Closed Wait"), NULL, 0, NULL);
OSVERSIONINFO osvi = { sizeof(OSVERSIONINFO) };
GetVersionEx(&osvi);
if (osvi.dwPlatformId == VER_PLATFORM_WIN32_NT) {
// NT 系列需 SE_SHUTDOWN_NAME 權限
HANDLE hToken; OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES, &hToken);
TOKEN_PRIVILEGES tkp = {1, {{0,0}, SE_PRIVILEGE_ENABLED}};
LookupPrivilegeValue(NULL, SE_SHUTDOWN_NAME, &tkp.Privileges[0].Luid);
AdjustTokenPrivileges(hToken, FALSE, &tkp, 0, NULL, NULL);
}
ExitWindowsEx(EWX_SHUTDOWN | EWX_FORCE, 0); // 或 EWX_REBOOT, EWX_LOGOFF
typedef int (CALLBACK* SHUTDOWNDLG)(int);
HINSTANCE h = LoadLibrary(_T("Shell32.dll"));
if (h) {
SHUTDOWNDLG fn = (SHUTDOWNDLG)GetProcAddress(h, (LPCSTR)60);
if (fn) fn(0);
FreeLibrary(h);
}
LOGFONT lf = {0}; lf.lfCharSet = DEFAULT_CHARSET;
CClientDC dc(this);
EnumFontFamiliesEx(dc, &lf, (FONTENUMPROC)EnumFontProc, (LPARAM)this, 0);
int CALLBACK EnumFontProc(LPENUMLOGFONT lpelf, LPNEWTEXTMETRIC, DWORD, LPARAM lParam) {
((CMyDlg*)lParam)->m_fontList.AddString(lpelf->elfLogFont.lfFaceName);
return 1; // 繼續列舉
}
if (FindWindow(NULL, _T("我的程式標題"))) exit(0); // 早期退出
CPoint pt; GetCursorPos(&pt); // 螢幕座標
ScreenToClient(&pt); // 轉客戶區座標
ON_WM_CONTEXTMENU(),處理函數 OnContextMenu(CWnd*, CPoint) 中 TrackPopupMenu。CWnd* pMain = AfxGetMainWnd();
if (bHide) { pMain->SetMenu(NULL); pMain->DrawMenuBar(); }
else { CMenu menu; menu.LoadMenu(IDR_MAINFRAME); pMain->SetMenu(&menu); pMain->DrawMenuBar(); menu.Detach(); }
HICON hIcon = ExtractIcon(AfxGetInstanceHandle(), _T("Notepad.exe"), 0);
#define _CRTDBG_MAP_ALLOC
#include
#include
// 程式結束前
_CrtDumpMemoryLeaks();
arg1 arg2。Output Directory 設為同一 ../Output,EXE 專案 Working Directory 設為該目錄。