C MFC 通過檔案對話方塊讀寫INI 檔案

2021-08-17 09:52:29 字數 3285 閱讀 1497

bool isopen = true;     //是否開啟(否則為儲存)  

cstring defaultdir = l"c:\\"; //預設開啟的檔案路徑

cstring filename = l""; //預設開啟的檔名

cstring filter = l"檔案 (*.ini; *.cfg)|*.ini;*.cfg||"; //檔案過慮的型別

cfiledialog openfiledlg(isopen, defaultdir, filename, ofn_hidereadonly|ofn_readonly, filter, null);

openfiledlg.getofn().lpstrinitialdir = l"e:\\filetest\\test.ini";

int_ptr result = openfiledlg.domodal();

cstring filepath = defaultdir + _t("\\test.ini");

if(result == idok) else

//讀取採集引數配置檔案

int itmp;

itmp = getprivateprofileint(_t("acqparam"),_t("acqclk") , 0, filepath);

m_acqclksrc.setcursel(itmp);

cstring stmp;

getprivateprofilestring(_t("acqparam"),_t("exclkfre"),_t(""),stmp.getbuffer(256),256,filepath);

m_extrfre = _wtof(stmp); //轉double 賦值給介面

getprivateprofilestring(_t("acqparam"),_t("chunit"),_t(""),m_unit.getbuffer(256),256,filepath);

updatedata(false); //重新整理介面

bool isopen = false;        //是否開啟(否則為儲存)  

cstring defaultdir = l"c:\\"; //預設開啟的檔案路徑

cstring filename = l"test.ini"; //預設開啟的檔名

cstring filter = l"檔案 (*.ini; *.cfg)|*.ini;*.cfg||"; //檔案過慮的型別

cfiledialog openfiledlg(isopen, defaultdir, filename, ofn_hidereadonly|ofn_overwriteprompt, filter, null);

openfiledlg.getofn().lpstrinitialdir = l"c:\\test.ini";

int_ptr result = openfiledlg.domodal();

cstring filepath = defaultdir + _t("\\") + filename;

if(result == idok) else

tchar buf[256];

cstring stmp;

wsprintf(buf, _t("%d"), m_acqclksrc.getcursel());

writeprivateprofilestring(_t("acqparam"), _t("acqclk"), buf, filepath);

stmp.format(_t("%f"),m_extrfre);

wsprintf(buf, _t("%s"), stmp.getbuffer(stmp.getlength()));

writeprivateprofilestring(_t("acqparam"), _t("exclkfre"), buf, filepath);

wsprintf(buf, _t("%d"), m_acqfre.getcursel());

writeprivateprofilestring(_t("acqparam"), _t("acqfre"), buf, filepath);

stmp.format(_t("%f"),m_len);

wsprintf(buf, _t("%s"), stmp.getbuffer(stmp.getlength()));

writeprivateprofilestring(_t("acqparam"), _t("acqlen"), buf, filepath);

stmp.format(_t("%f"),m_dly);

wsprintf(buf, _t("%s"), stmp.getbuffer(stmp.getlength()));

writeprivateprofilestring(_t("acqparam"), _t("dlglen"), buf, filepath);

wsprintf(buf, _t("%d"), m_rg.getcursel());

writeprivateprofilestring(_t("acqparam"), _t("acqrg"), buf, filepath);

wsprintf(buf, _t("%d"), m_cpl);

writeprivateprofilestring(_t("acqparam"), _t("cpl"), buf, filepath);

wsprintf(buf, _t("%d"), m_filter.getcursel());

writeprivateprofilestring(_t("acqparam"), _t("filterfre"), buf, filepath);

stmp.format(_t("%f"),m_k);

wsprintf(buf, _t("%s"), stmp.getbuffer(stmp.getlength()));

writeprivateprofilestring(_t("acqparam"), _t("kvalue"), buf, filepath);

writeprivateprofilestring(_t("acqparam"), _t("offset"), buf, filepath);

wsprintf(buf, _t("%s"), m_unitflag);

writeprivateprofilestring(_t("acqparam"), _t("chunitflag"), buf, filepath);

afxmessagebox(_t("匯出引數成功!"));

模態對話方塊 非模態對話方塊 標準對話方塊 檔案對話方塊

模態對話方塊 qdialog 非模態對話方塊 qdialog 標準對話方塊 關於對話方塊 問題對話方塊等 qmessagebox 檔案對話方塊 qfiledialog 標準對話方塊還有 qcolordialog 選擇顏色 qfiledialog 選擇檔案或者目錄 qfontdialog 選擇字型 q...

對話方塊 訊息對話方塊

我們在使用windows系統的過程中經常會見到訊息對話方塊,提示我們有異常發生或提出詢問等。因為在軟體開發中經常用到訊息對話方塊,所以mfc提供了兩個函式可以直接生成指定風格的訊息對話方塊,而不需要我們在每次使用的時候都要去建立對話方塊資源和生成對話方塊類等。這兩個函式就是cwnd類的成員函式mes...

MFC 實現開啟檔案對話方塊 儲存檔案對話方塊

cfiledialog cfiledialog bool bopenfiledialog,lpctstr lpszdefext null,lpctstr lpszfilename null,dword dwflags ofn hidereadonly ofn overwriteprompt,lpct...