/// <summary>
        /// Defines the common dialog box hook procedure that is overridden to add specific functionality to a common dialog box.
        /// </summary>
        /// <returns>
        /// A zero value if the default dialog box procedure processes the message; a nonzero value if the default dialog box procedure ignores the message.
        /// </returns>
        /// <param name="hWnd">The handle to the dialog box window. </param><param name="msg">The message being received. </param><param name="wparam">Additional information about the message. </param><param name="lparam">Additional information about the message. </param>
        protected override IntPtr HookProc(IntPtr hWnd, int msg, IntPtr wParam, IntPtr lparam)
        {
            switch (unchecked ((uint)msg))
            {
            case InteropUtil.WM_INITDIALOG:
            {
                InitDialog(hWnd);
                break;
            }

            case InteropUtil.WM_NOTIFY:
            {
                var notifyData =
                    (InteropUtil.OFNOTIFY)Marshal.PtrToStructure(lparam, typeof(InteropUtil.OFNOTIFY));
                int results = ProcessNotifyMessage(hWnd, notifyData);
                if (results != 0)
                {
                    InteropUtil.SetWindowLongW(hWnd, InteropUtil.DWL_MSGRESULT, results);
                    return((IntPtr)results);
                }
                break;
            }

            case InteropUtil.WM_SIZE:
            {
                ResizeCustomControl(hWnd);
                break;
            }

            case (InteropUtil.BN_CLICKED << 16) | InteropUtil.IDOK:
            {
                break;
            }

            case InteropUtil.WM_COMMAND:
            {
                unchecked
                {
                    IntPtr hParent = InteropUtil.AssumeNonZero(InteropUtil.GetParent(hWnd));
                    uint   code    = HIGH((uint)wParam);
                    uint   id      = LOW((uint)wParam);
                    if (code == InteropUtil.BN_CLICKED)
                    {
                        switch (id)
                        {
                        case InteropUtil.ID_CUSTOM_CANCEL:
                        {
                            //The user clicked our custom cancel button. Close the dialog.
                            InteropUtil.SendMessage(hParent, InteropUtil.WM_CLOSE, 0, 0);
                            break;
                        }

                        case InteropUtil.ID_SELECT:
                        {
                            if (ProcessSelection(hParent, true))
                            {
                                InteropUtil.SendMessage(hParent, InteropUtil.WM_CLOSE, 0, 0);
                                break;
                            }
                            //The user has not selected an existing folder.
                            //So we translate a click of our "Select" button into the OK button and forward the request to the
                            //open file dialog.
                            InteropUtil.SendMessage
                                (hParent,
                                InteropUtil.WM_COMMAND,
                                (InteropUtil.BN_CLICKED << 16) | InteropUtil.IDOK,
                                unchecked ((uint)InteropUtil.GetDlgItem(hParent, InteropUtil.IDOK))
                                );


                            break;
                        }
                        }
                    }
                }
                break;
            }
            }
            return(base.HookProc(hWnd, msg, wParam, lparam));
        }