Use the System's File Properties Dialog
Invoke the Windows standard property dialog for any given file.
by Karl E. Peterson

December 2002 Issue  Download the original Classic VB code from this column.

Technology Toolbox: VB6, VB5

Q: Use the System's File Properties Dialog
My application offers a display of filenames as part of its user interface. I'd like to give users the ability to bring up the system File Properties dialog as one of the options when they right-click on a filename. How can I do that?

A:
This task involves only a single quick call to the ShellExecuteEx API (see Listing 1). Unlike ShellExecute, ShellExecuteEx enables you to call any context menu item related to a given shell object—"properties," in this case.

Set up the call by creating a SHELLEXECUTEINFO structure and filling its first element (cbSize) with the structure's overall size so the system knows that you know what you're doing. Create the flag mask by combining the constant values for SEE_MASK_INVOKEIDLIST (which allows the use of shortcut menu extension verbs, rather than only Registry verbs), SEE_MASK_FLAG_NO_UI (which prevents the system from popping message boxes on errors), and SEE_MASK_DOENVSUBST (which expands environment variables in the passed filespec).

It's good form to stuff the structure's hWnd element with the handle of a window in your app. This window serves as the parent of any error-related message boxes the system pops up, although you've instructed the system already not to do this. The lpVerb element is the key to bringing up the desired dialog—assign "properties" to this element. Finally, assign the desired filename to the lpFile element, and make the call to ShellExecuteEx.

You can gauge your call's success by examining the SHELLEXECUTEINFO structure's hInstApp element for a value greater than 32. Values less than 32 indicate an error occurred, and you can interpret the exact cause from the specific value. —K.E.P.


About the Author
Karl E. Peterson is a GIS analyst with a regional transportation planning agency and serves as a member of the VSM Editorial Advisory Board. Online, he's a Microsoft MVP and a section leader on several DevX forums. Find more of Karl's VB samples at www.mvps.org/vb.