Home

The Open a File With Dialog Box

     

Introduction

The C language, the C++ language, Object Pascal, the VCL, and the Win32 library, all provide different ways to open a file. In a typical computer, most file types are registered with known applications so the user can appropriately open a file. Some times the user may be in the presence of a file that no application is automatically configured to open. In some cases, the user can use the Open With dialog box to select an application to open the file.

To display the Open With dialog box, you can call the SHOpenWithDialog() function. Its syntax is:

HRESULT SHOpenWithDialog(
  __in_opt  HWND hwndParent,
  __in      const OPENASINFO *poainfo);

Here is an example:

//---------------------------------------------------------------------------

#include 
#include 

#pragma hdrstop

#include "Exercise.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
	: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::btnDriveClick(TObject *Sender)
{
    OPENASINFO oai;
    oai.pcszFile = L"C:\\Exercise\\Example.png";
    oai.pcszClass = NULL;
    oai.oaifInFlags = OAIF_ALLOW_REGISTRATION;
    SHOpenWithDialog(Handle, &oai);
}
//---------------------------------------------------------------------------

This would produce:

Open With

 
 
     
 

Home Copyright © 2010-2011 FunctionX, Inc.