模仿 Windows 檔案複製/刪除的飛行動畫對話框。
CModelclass CModel : public CDialog {
public:
CModel(CWnd* pParent = NULL); // 無模式建構函數
BOOL Create(); // 呼叫 CDialog::Create
CWnd* m_pParent; int m_nID;
protected:
virtual void PostNcDestroy() { delete this; CDialog::PostNcDestroy(); }
};
// 標頭檔
CModel* m_pDlg = NULL;
// 開啟
if(!m_pDlg) { m_pDlg = new CModel(this); m_pDlg->Create(); GetDlgItem(IDC_BTN)->EnableWindow(FALSE); }
else m_pDlg->SetActiveWindow();
// 關閉
if(m_pDlg) { m_pDlg->DestroyWindow(); m_pDlg = NULL; }
優於自寫 DLL:成熟穩定、免維護、命令列參數靈活。
CreateBat() 產生批次檔,內含 ARJ 命令 + DIR > flag.tmp 作完成標記RunBat() 用 CreateProcess 執行批次檔OnTimer 輪詢 flag.tmp 存在與否,存在則終止進程、清理FindDriverInfo():列舉所有磁碟機,篩選軟碟機加入下拉清單EmptyDiskSpace():清空磁碟、取得容量與序號(內部呼叫自訂 DeleteTree)SetVolumeLabel():設定磁碟區標籤(最多 11 字元,不分大小寫)Win32/MFC 均無對應 API,但組合 FindFirstFile/RemoveDirectory/DeleteFile 易於實作,比呼叫外部命令更高效、可控。
BOOL DeleteTree(LPCTSTR path) {
CFileFind find; BOOL b = find.FindFile(CString(path)+_T("\\*.*"));
while(b) {
b = find.FindNextFile();
if(find.IsDots()) continue;
if(find.IsDirectory()) DeleteTree(find.GetFilePath());
else DeleteFile(find.GetFilePath());
}
return RemoveDirectory(path);
}