How Common Dialog BoxSubclassing Works
Subclassing a common dialog box is not as easy as subclassing a window. A few extra steps are involved. The four main steps are:
Create a child dialog template resource.
Package this resource in a dynamic link library (DLL), optional
Create a hook procedure that will intercept messages for the common dialog box.
Use the API function in the comdlg32.dll file to create the modified common dialog.
I will be using the term dialog procedure instead of “window procedure” to describe the message processing function for the common dialog box. These two types of procedures, for all practical purposes, are the same. One small difference is that the dialog procedure sends all unprocessed messages to the DefDlgProc function, whereas the window procedure sends all unprocessed messages to the DefWindowProc function.
Using the COMDLG32.DLL
Before going any further with subclassing common dialogs, we will see how to use the comdlg32.dll APIs. The common dialog that we use for subclassing must be created with the comdlg32.dll API instead of with the ActiveX Common Dialog control (comdlg32.ocx). The consequence of using the DLL instead of the ActiveX control (OCX) is mainly added complexity: all the details that the OCX hid from us are now up to us to handle. The good thing is that there is no longer a performance penalty for having to load the comdlg32.ocx, and this file will not have to be shipped along with your final application.
The common dialog box relies ...
Get Subclassing and Hooking with Visual Basic now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.