April 30th, 2007

The default verb is not necessarily "open"

If you hunt around the Internet you’ll find lots of people† who hard-code the string "open" as the second parameter to the ShellExecute function, indicating that they want to open the document specified as the third parameter. While that’s a nice thing to want to do, it might not be the right thing. When the user double-clicks a document, the shell executes the default verb, which is not necessarily “open”. For example, for audio files, the default verb is often “play”, and for pictures, it’s often “view”. If you want to launch the document as if the user had double-clicked it, then you need to pass NULL as the lpOperation. Commenter brad asked how the default verb is determined. This is explained in MSDN in the section titled, not surprisingly, Verbs and File Associations:

The primary verb is specified by the default value of the shell key, or the open key if the shell key has no default value. … The primary verb is also referred to as the default verb.

Nitpicker’s corner

†The phrase “lots of people” means “lots of people”. It doesn’t mean “lots of people not including Microsoft.”

Topics
Code

Author

Raymond has been involved in the evolution of Windows for more than 30 years. In 2003, he began a Web site known as The Old New Thing which has grown in popularity far beyond his wildest imagination, a development which still gives him the heebie-jeebies. The Web site spawned a book, coincidentally also titled The Old New Thing (Addison Wesley 2007). He occasionally appears on the Windows Dev Docs Twitter account to tell stories which convey no useful information.

0 comments

Discussion are closed.