CFileDialog类在WTL库中的atldlgs.h文件中
网上搜索"CFileDialog"大部分是MFC库的使用实例。
试了几个实例发现都没办法过虑扩展名;
后来跟踪源码发现,填充了一个OPENFILENAME结构体,接着调用的是GetOpenFileName系统API来显示窗口;
查下MSDN关于GetOpenFileName的说明,
Windows XP: In the case of a shortcut, if no filter is set, GetOpenFileName and GetSaveFileName retrieve the name of the .lnk file, not its target. This behavior is the same as setting the OFN_NODEREFERENCELINKS flag in the Flags member. To retrieve a shortcut's target without filtering, use the string "All Files\0*.*\0\0".
最后一句给我了提示,MFC库的Filter是用|来分隔,而系统却是\0来分隔,修正运行,就是我想要的。
但当中,还发现一个问题
“image files (*.png; *.jpg; *.bmp)\0*.png;*.jpeg;*.jpg;*.bmp \0All Files (*.*)\0*.*\0\0”
注意*.bmp后面有个空格,这个时候在打开窗口里是没法看到bmp格式的图片的,所以注意