Click here to Skip to main content
15,885,216 members
Articles / Programming Languages / C++

Using the Windows RunFile Dialog - The Documented and Undocumented Way

Rate me:
Please Sign up or sign in to vote.
4.64/5 (13 votes)
8 Aug 20023 min read 119.2K   1.8K   18  
An article describing how to use system RunFile dialog, both documented and undocumented way
#ifndef __RUNDLG_H__
#define __RUNDLG_H__
#pragma once

////////////////////////////////////////////////////////////////////////////////
//
//	Copyright(c) Armen Hakobyan 2002
//	mailto:armenh@web.am
//	http://www.codeproject.com/script/profile/whos_who.asp?vt=arts&id=25653
//
////////////////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////////////////
// START // RunFile dialog undocumented WINAPI function
////////////////////////////////////////////////////////////////////////////////

#ifndef IN
	#define IN
	#define OUT
	#define OPTIONAL
#endif

#ifndef FASTCALL
#define FASTCALL	__fastcall
#endif

// RunFileDlg flags
#define RFF_NOBROWSE		0x0001	// Removes the browse button
#define RFF_NODEFAULT		0x0002	// No default item selected
#define RFF_CALCDIRECTORY	0x0004	// Calculates the working directory from the file name
#define RFF_NOLABEL			0x0008	// Removes the edit box label
#define RFF_NOSEPARATEMEM	0x0020  // Removes the Separate Memory Space check box, NT only

// RunFileFlg notification message
#define RFN_VALIDATE		(-510)

// RunFileFlg notification structure
typedef struct tagNMRUNFILEDLGW {
	NMHDR		hdr;
	LPCWSTR		lpszFile;
	LPCWSTR		lpszDirectory; 
	int			nShow;
} NMRUNFILEDLGW, *LPNMRUNFILEDLGW, *PNMRUNFILEDLGW;

typedef struct tagNMRUNFILEDLGA {
	NMHDR		hdr;
	LPCSTR		lpszFile;
	LPCSTR		lpszDirectory; 
	int			nShow;
} NMRUNFILEDLGA, *LPNMRUNFILEDLGA, *PNMRUNFILEDLGA;

#ifdef UNICODE
	typedef NMRUNFILEDLGW	NMRUNFILEDLG;
	typedef PNMRUNFILEDLGW	PNMRUNFILEDLG;
	typedef LPNMRUNFILEDLGW	LPNMRUNFILEDLG;
#else
	typedef NMRUNFILEDLGA	NMRUNFILEDLG;
	typedef PNMRUNFILEDLGA	PNMRUNFILEDLG;
	typedef LPNMRUNFILEDLGA	LPNMRUNFILEDLG;
#endif // UNICODE

// RunFileDlg notification return values
#define RF_OK		0x0000	// Allow the application to run
#define RF_CANCEL	0x0001	// Cancel the operation and close the dialog
#define RF_RETRY	0x0002	// Cancel the operation, but leave the dialog open

// The ordinal value of the function is 61 and the
// function declaration looks like this:

BOOL
FASTCALL
RunFileW (
	IN HWND		hWndOwner,
	IN HICON	hIcon,
	IN LPCWSTR	lpszDirectory,
	IN LPCWSTR	lpszTitle,
	IN LPCWSTR	lpszDescription,
	IN DWORD	dwFlags
	);

BOOL
FASTCALL
RunFileA (
	IN HWND		hWndOwner,
	IN HICON	hIcon,
	IN LPCSTR	lpszDirectory,
	IN LPCSTR	lpszTitle,
	IN LPCSTR	lpszDescription,
	IN DWORD	dwFlags
	);

#ifdef UNICODE
	#define RunFile RunFileW
#else
	#define RunFile	RunFileA
#endif

// RunFile function some parameter lengths
#define RF_MAX_DIRECTORY	MAX_PATH
#define RF_MAX_TITLE		64
#define RF_MAX_DESCRIPTION	128

////////////////////////////////////////////////////////////////////////////////
// END // RunFile dialog undocumented WINAPI function
////////////////////////////////////////////////////////////////////////////////

// Inlines:
__forceinline BOOL SafeRunFileDlg( IN HWND hWndOwner, OPTIONAL HICON hIcon = NULL, 
	OPTIONAL LPCTSTR lpszTitle = NULL, OPTIONAL LPCTSTR lpszDescription = NULL,
	OPTIONAL DWORD dwFlags = RFF_CALCDIRECTORY, OPTIONAL LPCTSTR lpszDirectory = NULL )
{
	return ::RunFile( hWndOwner, hIcon, (LPCTSTR)lpszDirectory, 
		(LPCTSTR)lpszTitle, (LPCTSTR)lpszDescription, dwFlags );
}

#endif // __RUNDLG_H__

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.


Written By
Software Developer (Senior) SafeNet Inc
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions