Posts Tagged ‘CFileDialog’

Customizing open and save as dialogs

Read this article on how to customize file open and save as dialogs ->

A keyword for search will be stc32. Well what is stc32? It’s a special static control’s id which acts as a placeholder for placing file open and save as dialog’s main pane. This allows us to position our own custom controls after or before main UI of open file dialog.

There is a sample in MSDN called OfnKing, which is quite good for starting off!

Displaying “Properties window” for any file!

October 14, 2007 1 comment

Right click on any file in windows and select properties, you will see a tabbed properties window pop up. Ever wondered how to do this programmatically on any file that you choose…

Here is a demo…

#include <afxwin .h>
#include <afxdlgs .h> // CFileDialog      

int main()
    // initialize MFC and print an error on failure
    if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0))
        // TODO: change error code to suit your needs
        std::cerr < < _T("Fatal Error: MFC initialization failed") << std::endl;
        return 1;

    // Our code starts here //      

    CFileDialog cfDlg( TRUE );<a title="Properties window demo" href="">

    // Get file name
    CString csFileName = cfDlg.GetPathName();
    if (!csFileName.IsEmpty())
        SHELLEXECUTEINFO shExecInfo = { 0 };
        shExecInfo.cbSize = sizeof(shExecInfo);
        shExecInfo.lpFile = csFileName;
        shExecInfo.lpVerb = _T("properties"); // Context menu item
        shExecInfo.fMask  = SEE_MASK_INVOKEIDLIST; // This is the key, see MSDN       

        // Show properties

        // Wait, else console application will exit
        Sleep( 5000 );
    }// End if
}// End main

The key to this is this flag SEE_MASK_INVOKEIDLIST which means lpVerb is valid and it has a command which is valid. This command will be one of the items we see when we right click on a file, this can be “explore”, “edit”, “print” ;), “open”, “properties”, “find”. I’ve given “properties” hence we see the properties window. Try “print”.

Screenshot for properties…

Properties window demo

%d bloggers like this: