Customized open file dialog
File open dialog is a part of windows subsystem and comes with commdlg32.dll package. In normal senarios we pass the file path buffer and it returns the path which is selected by the user. However there are additional facilities can be given with this dialog. Additional GUI controls can be added using a resource template. A hook procedure can be added to handle the events from these custom controls.
Customization of file open dialog is helpful for applications like Photo editors, audio editors etc. Here are some common usage of custom dialogs.
- An audio application can add a play sound file for preview before opening
- Photo or graphics editor applications can add a thumnail preview of the file
- User can display metadata information like author, revision etc
Here is the demo and we have mainly these steps to make a custom open file dialog.
- Add a dialg bar child resource in the project
- Add necessary button, text, ActiveX or other GUI controls
- Give ID for each controls
- Add OFN_ENABLETEMPLATE and OFN_ENABLEHOOK for OPENFILENAME.Flags
- Add lpTemplateName = MAKEINTRESOURCE(<DIALOGBAR resource ID>)
- Add hook procedure and implement all the notify events needed
- Update the lpfnHook = hook procedure address
Here is the C++ source file followed by the resource script.
///////////////////////////////////////////////////////////////////////////// // // Dialog // IDD_DIALOGBAR DIALOGEX 0, 0, 269, 26 STYLE WS_CHILD FONT 8, "MS Sans Serif" BEGIN LTEXT "Customized File open",IDC_STATIC_HINT,7,7,222,12,0, WS_EX_STATICEDGE PUSHBUTTON "Play",IDC_PLAYPREVIEW,231,7,31,12 END
About our authors: Team EQA
MFC hides WinMain in its framework and includes source file on WinMain(). This explains how framework calls global CWinApp::Initinstance() from entry WinMain.
This is constructed during global C++ objects are constructed and is already available when Windows calls the WinMain function, which is supplied by the ...
Define a custom Window class structure, Register the class name, CreateWindow, Show windows and write message get and dispatch loop statements. Define the Window CallBack procedure and write the handlers.
DispatchMessage() is a API which indirectly triggers the Window CallBack procedure. Message structure members from this function are passed to the CallBack procedure. CallBack procedure should implement event handlers depending on the need of the application.
LPARAM and WPARAM are the two parameters in Window CallBack procedure. They signifies parameters of various events. They are used in handing individual events.
We need to write WinMain and need to follow all these in a Win32 application. However we need not to write much if we are writing an application with MFC ...
Questions index C Questions C++ Questions Win32 MFC COM/DCOM DLL Questions
Compilers & Editors
Download Visual Studio Download XCode Download Visual Studio Code Android studio install sdk Eclipse installer Best C compilers IDEs
Development system setup
Windows media creation tool MSDN subscription Ubuntu virtualbox
New updated posts
Why learn C? Draw on printer Free alt softwares