C语言如何调用系统的文件浏览功能?

C语言如何调用系统的文件浏览功能?,第1张

加上头文件#include <commdlg.h>

其格式如下毕启

OPENFILENAME ofn

char path[MAX_PATH]

static TCHAR szFilter[] = TEXT ("Text Files (*.TXT)\0*.txt\0") \

TEXT ("ASCII Files (*.ASC)\0*.asc\0"知毕) \

TEXT ("All Files (*.*)\0*.*\0\0")

ofn.lStructSize = sizeof (OPENFILENAME)

ofn.hwndOwner = hwnd

ofn.hInstance = NULL

ofn.lpstrFilter = szFilter

ofn.lpstrCustomFilter = NULL

ofn.nMaxCustFilter = 0

ofn.nFilterIndex = 0

ofn.nMaxFile = MAX_PATH

ofn.nMaxFileTitle = MAX_PATH

ofn.lpstrInitialDir = NULL

ofn.lpstrTitle = NULL

ofn.Flags = 0 // Set in Open and Close functions

ofn.nFileOffset = 0

ofn.nFileExtension = 0

ofn.lpstrDefExt = TEXT ("txt")

ofn.lCustData = 0L

ofn.lpfnHook = NULL

ofn.lpTemplateName = NULL

ofn.hwndOwner = hwnd

ofn.lpstrFile = path

ofn.lpstrFileTitle = NULL

ofn.Flags = OFN_HIDEREADONLY | OFN_CREATEPROMPT

GetOpenFileName (&ofn) //打开文件对话框

GetSaveFileName(&ofn)//保存文件对话搭数芹框

只枝斗有用WinAPI的,需要头文件颂渣windows.h和commdlg.h:

#include <windows.h>猛樱磨

#include <commdlg.h>

int main(void)

{

OPENFILENAME ofn

ZeroMemory(&ofn,sizeof(ofn))

ofn.lStructSize = sizeof(ofn)

ofn.lpstrFile[0] = '\0'

ofn.lpstrFilter = TEXT("ALL\0*.*\0")

ofn.nFilterIndex = 1

ofn.lpstrFileTitle = NULL

ofn.nMaxFileTitle = 0

ofn.lpstrInitialDir = NULL

ofn.hwndOwner = NULL

ofn.Flags = OFN_EXPLORER |OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST

GetOpenFileName(&ofn)

return 0

}

Linux中浏览裂姿当前目录下所肆镇绝有以".c"为后缀名的文件,可以使用ls命令,旅或直接执行如下命令:

ls *.c

要获取更多信息可以使用ls命令的-l参数

ls -l *.c


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/tougao/8216372.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-14
下一篇 2023-04-14

发表评论

登录后才能评论

评论列表(0条)

保存