简体   繁体   中英

Win32 OpenFileDialog Does Not Filter *.DOCX Shortcuts

I could do this on several different computers with Windows 7 SP1.

This can be duplicated in Notepad (or any other app that uses OpenFileDialog )

  1. Create a shortcut to a DOCX
  2. Launch notepad
  3. File, Open
  4. Filter on *.txt
  5. Browse to location of *.docx shortcut

*.docx is the only shortcut extension I can find that does not filter. So far my only workaround is for my application to check the file extension after the user selects a file.

Is there some way to make OpenFileDialog filter out *.docx.lnk files as the user might expect it to?

Why are only Office file extensions affected?

Only shortcuts to Office 2007+ documents are affected. (Shortcuts actually have a .lnk extension that is hidden by the shell, ie Windows Explorer)

FindFirstFile does not find these files when the mask "*.txt" is specified, so this is something the shell does.

You could attempt to disable respective shell plugins to determine which plugin is responsible for that behavior (to be safe: disable the plugins, kill and restart explorer through task manager, then restart your process before testing again).

I've checked the most obvious candidates, couldn't find any.


Programming advice: Verify your input. In your case, this is the file content, not the file extension!

I can specify any fiel in the Open dialog, even if you limit the mask.
I can save my text file as "really.important" and still expect to open it in your application.
I can save my word file as "really a word document.txt", open this in your application and at least expect you to not crash-

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM