Windows API實現檔案的查詢

2021-08-26 07:21:38 字數 590 閱讀 9171

在實際應用,經常要用到檔案的查詢,在前面,我們給大家介紹了如何用cfilefind類實現檔案的遍歷以及如何用列表控制項顯示。這裡,我們主要介紹一下如何使用windows api來實現檔案的查詢。

1. findfirstfile(),它有兩個引數,第乙個是要查詢的檔名,第二個是儲存查詢到的資訊,型別為win32_find_dat,返回乙個控制代碼。

2. findnextfile(),繼續查詢。

3. findclose(),關閉查詢。

程式的實現:

win32_find_data fd;

m_listfile.resetcontent();//m_listfile 用來儲存查詢結果

handle hd=::findfirstfile((lpctstr)m_strfile,&fd);//開始查詢

if(hd==invalid_handle_value)

m_listfile.addstring(fd.cfilename);

while(findnextfile(hd,&fd)) //繼續查詢

;findclose(hd);//關閉查詢

}

用WindowsAPI實現檔案複製功能

注釋也在裡面 檔名為 copyfile.c 執行出來的exe為 copyfile.exe include include define buf size 256 int main int argc,lptstr argv 如果通過上面判斷語句的話說明引數輸入符合形式 則進行下乙個判斷 1 判斷檔案1...

windows api之檔案的建立

在windows api中可以使用createfile來建立資料夾,其中createfilew是unicode編碼下的巨集函式,createfilew是長位元組下的巨集函式,以下程式設計環境使用unicode編碼,所以使用的是createfilew。我們先來看一下巨集函式的原型 winbaseapi...

Windows API實現視窗居中

如下 居中視窗 int scrwidth,scrheight rect rect scrwidth getsystemmetrics sm cxscreen scrheight getsystemmetrics sm cyscreen getwindowrect hwnd,rect setwindo...