MFC CFileDialog 相對路徑

2021-06-05 23:23:26 字數 1566 閱讀 3604

1)在mfc中想按照自己設定的路徑來開啟filedialog,其實cfiledialog有自己的變數 m_ofn,該變數為openfilename的結構體,使用者可自己定義一些內容

例如 開啟窗體的名字:

dlg.m_ofn.lpstrtitle = _t("遙測載入");

按照自己設定的路徑開啟dlg:

dlg.m_ofn.lpstrinitialdir = _t("c:\\documents and settings\\administrator\\桌面\\2012.4.16\\drawprogram1\\ycpicture");

在這裡想說的是,使用相對路徑

dlg.m_ofn.lpstrinitialdir = _t("res\\ycpicture");

總體**如下:

cfiledialog dlg(true,null,null,ofn_hidereadonly | ofn_overwriteprompt,_t("檔案(*.bmp;*.jpg;*.gif)|*.bmp;*.jpg;*.gif| 位**件                    (*.bmp)|*.bmp"),null);

= _t("c:\\documents and settings\\administrator\\桌面\\2012.4.16\\drawprogram1\\ycpicture");

/*cstring abc = getsyspath();     獲得系統的絕對路徑

dlg.m_ofn.lpstrinitialdir = getsyspath();*/

dlg.m_ofn.lpstrinitialdir = _t("res\\ycpicture");

dlg.m_ofn.lpstrtitle = _t("遙測載入");

if (dlg.domodal() == idok)

以上**中的相對路徑是有問題的,後來拿到另一台機子上測試,發現不正常,後來修改,根據以下獲得的絕對路徑來完成的:

**如下:

也就是獲得當前的路徑後,根據自己的需要做些修改。

cstring cyxpropertydialog::getsyspath(cstring filename)

str += filename;*/

//szfolder = _t("c:\\documents and settings\\administrator\\桌面\\drawprogram1\\debug");

return szfolder;

}

在呼叫該函式的部分:

cstring strtemp = getsyspath(_t("ycpicture"));

dlg.m_ofn.lpstrinitialdir = strtemp;

dlg.m_ofn.lpstrtitle = _t("遙測載入");

2)獲得系統的絕對路徑:

這個是摘自網路:

cstring dlg::getsyspath(void)

MFC CFileDialog 檔案過濾條件

今天寫乙個選擇檔案的對話方塊,使用cfiledialog tchar lpfilter t img files img img all files cfiledialog dlg true,null,null,ofn hidereadonly ofn overwriteprompt,lpfilter...

GetCurrentDirectory相關問題

dword getcurrentdirectory dword nbufferlength,size of directory buffer lptstr lpbuffer directory buffer 函式功能 獲取當前程序的當前目錄。注意當前目錄這東西有點怪異,本來確實是可執行檔案的所在目錄...

Map JSONObject String相互轉換

map轉jsonobject com.alibaba fastjson 1.2.59 jsonobject info jsonobject.parseobject json.tojsonstring map jsonobject轉map jsonobject json new jsonobject ...