VS 調試運行:棋子正常顯示
直接雙擊 EXE:棋子缺失,界面異常
工作目錄不同導致相對路徑資源加載失敗:
xcopy /Y "$(ProjectDir)Resources\*.*" "$(OutDir)Resources\"
CString strPath = AfxGetApp()->m_pszHelpFilePath;
strPath = strPath.Left(strPath.ReverseFind('\\') + 1) + _T("Resources\\chess.bmp");
CBitmap bmp;
bmp.LoadBitmap(IDB_CHESS); // 從 EXE 內部加載,無路徑依賴
在 EXE 目錄創建 debug.log 記錄當前工作目錄:
CString cwd;
GetCurrentDirectory(MAX_PATH, cwd.GetBuffer(MAX_PATH));
cwd.ReleaseBuffer();
TRACE(_T("Current Dir: %s\n"), cwd);