工作過程中經常遇到有些函式想不起來,然後去查,很多函式已經查過但還是會忘,這裡把這些函式整理起來,方便以後使用。
//彈出警告框
acedalert()
;
getdlgitem
(idc_cs_gridctrl)
->
enablewindow
(false)
;//控制項禁用
getdlgitem
(idc_cs_gridctrl)
->
enablewindow
(true)
;//控制項使用
getdlgitem
(idc_cs_gridctrl)
->
showwindow
(false)
;//控制項隱藏
getdlgitem
(idc_cs_gridctrl)
->
showwindow
(true)
;//控制項顯示
//關於windows路徑的api
//宣告路徑變數用 tchar szpath[max_path] 來宣告
tchar szpath[max_path]=_t
("d:\\資料\\整理的筆記");
tchar szpath2[max_path]=_t
("資料\\筆記");
tchar szpath3[max_path]=_t
("");
lptstr pszpath =
null;::
pathremovebackslashw
(szpath)
;//去除路徑最後的反斜槓「\\」
::pathaddbackslashw
(szpath)
;//在路徑最後加上反斜槓「\\」
::pathremoveblanksw
(szpath)
;//去除路徑前後的空格
pszpath =
::pathfindextensionw
(szpath)
;//查詢路徑的副檔名
bret =
::pathmatchspecw
(szpath,_t(
"*.dwg"))
;//判斷路徑是否匹配制定的副檔名
::pathaddextensionw
(szpath,_t(
".dwg"))
;//在檔案路徑後面加上副檔名
::pathremoveextensionw
(szpath)
;//去除檔案路徑副檔名
::pathrenameextensionw
(szpath,_t(
".pdf"))
;//更改檔案路徑副檔名
pszpath =
::pathfindfilenamew
(szpath)
;//獲取路徑的檔名
::pathstrippathw
(szpath)
;//去掉路徑中的目錄部分,得到檔名
::pathremovefilespecw
(szpath)
;//去除檔名,得到目錄
::pathstriptorootw
(szpath)
;//得到根目錄
::(szpath,szpath2)
;//將乙個路徑追加到另乙個路徑後面
::pathcombinew
(szpath3,szpath,szpath2)
;//合併兩個路徑
bret =
::pathrelativepathtow
(szpath3,szpath,file_attribute_normal,szpath2,file_attribute_directory)
;//建立乙個路徑到另乙個路徑的相對路徑 file_attribute_directory:代表是乙個資料夾,否則視為檔案
bret =
::pathyetanothermakeuniquename
(szpath3,szpath,
null
,null);
//基於已存在的檔案,自動建立乙個唯一的檔名。比較有用,比如存在「新建檔案」,此函式會建立檔名「新建檔案(2)」
::
shgetspecialfolderpathw
(nullptr;
hmodule hmodule =
::afxgetinstancehandle()
;//獲取當前應用程式的例項控制代碼
hmodule =
::afxgetresourcehandle()
;//獲取當前應用程式的資源模組控制代碼
::afxsetresourcehandle
(hmodule)
;//設定程式目前要使用的資源模組控制代碼
hmodule =
::getmodulehandlew(_t
("mybasedll.dll"))
;//獲取乙個應用程式或動態鏈結庫的模組控制代碼。只有在當前程序的場景中,這個控制代碼才會有效。
::getmodulefilenamew
(hmodule, szpath3, max_path)
;//通過控制代碼獲得完整路徑
wchar_t buffer[max_path]
; dword code =
getenvironmentvariable
(l"jdc_protal"
, buffer, max_path)
;//得到環境變數的值
::
getcurrentdirectoryw
(max_path,szpath3)
;//得到當前程序的工作路徑
::setcurrentdirectoryw(_t
("e:\\test\\"))
;//設定當前程序的工作路徑
bool bret =
::pathisdirectory
(szdirpath)
;//判斷路徑是不是資料夾(也可以判斷該路徑是否存在)
bool rec =
::pathfileexists
(path)
;//判斷檔案或資料夾是否存在
::removedirectory
(szdirpath)
;//刪除空資料夾(只能刪除空資料夾)
::deletefile
(szfilepath)
;//刪除檔案(只能刪除檔案)
::movefile
(szexistingfilename,sznewfilename)
;//移動現有檔案或目錄,包括其子目錄。(可以對資料夾和檔案進行重新命名)
::copyfile
(szexistingfilename,sznewfilename,
false);
//複製檔案(只能複製檔案) true:如果目標存在,不拷貝並返回false; false:直接覆蓋
bret =
::createdirectory
(strdirpath,
null);
//建立資料夾 (第二個引數為安全屬性,一般為null)
MFC常用函式(總)for Myse
boolcopyfile lpctstr lpexistingfilename,pointer to name of an existing file lpctstr lpnewfilename,pointer to filename to copy to bool bfailifexists fl...
MFC常用小工具函式
1 判斷檔案是否存在 bool isfileexist cstring sfilename return true 2 判斷目錄是否存在 bool clib global ispathexist const cstring spathname findclose hfind return rvalu...
MFC中常用類,巨集,函式介紹
常用類 crect 用來表示矩形的類,擁有四個成員變數 top left bottom right。分別表是左上角和右下角的座標。可以通過以下的方法構造 crect int l,int t,int r,int b 指明四個座標 crect const rect srcrect 由rect結構構造 c...