예제 #1
0
        }// DialogProcHook

        //-------------------------------------------------
        // PropSheetDialogProc
        //
        // This function will handle all messages coming sent
        // to the property page
        //-------------------------------------------------
        internal bool PropPageDialogProc(IntPtr hwndDlg, uint msg, IntPtr wParam, IntPtr lParam)
        {
            m_pphWnd = hwndDlg;

            // See if we've been subclassed...
            if (m_dlgHook != null)
            {
                // If our hook handled the message, then we don't need to do
                // anything anymore. :)
                if (m_dlgHook(hwndDlg, msg, wParam, lParam))
                {
                    return(true);
                }
            }
            switch (msg)
            {
            case WM.NOTIFY:

                // lParam really is a pointer to a NMHDR structure....
                NMHDR nm = new NMHDR();
                nm = (NMHDR)Marshal.PtrToStructure(lParam, nm.GetType());

                switch (nm.code)
                {
                case PSN.SETACTIVE:
                    SetWindowLong(hwndDlg, 0, WizSetActive(hwndDlg));
                    return(true);

                case PSN.WIZBACK:
                    SetWindowLong(hwndDlg, 0, WizBack(hwndDlg));
                    return(true);

                case PSN.WIZNEXT:

                    StartWaitCursor();
                    SetWindowLong(hwndDlg, 0, WizNext(hwndDlg));
                    EndWaitCursor();

                    return(true);

                case PSN.WIZFINISH:
                    SetWindowLong(hwndDlg, 0, WizFinish(hwndDlg));
                    return(true);
                }
                break;

            default:
                // We didn't handle this message
                return(false);
            }
            return(false);
        }// PropPageDialogProc
예제 #2
0
        }// DialogProcHook

        //-------------------------------------------------
        // PropSheetDialogProc
        //
        // This function will handle all messages coming sent
        // to the property page
        //-------------------------------------------------
        internal bool PropPageDialogProc(IntPtr hwndDlg, uint msg, IntPtr wParam, IntPtr lParam)
        {
            try
            {
                // See if we've been subclassed...
                if (m_dlgHook != null)
                {
                    // If our hook handled the message, then we don't need to do
                    // anything anymore. :)
                    if (m_dlgHook(hwndDlg, msg, wParam, lParam))
                    {
                        return(true);
                    }
                }
                switch (msg)
                {
                case WM.INITDIALOG:
                    BeginInsertPropSheetPageControls(hwndDlg);
                    return(true);

                case WM.DESTROY:

                    // We're not going to make changes to this
                    m_fChanges = false;

                    // tell MMC that we're done with the property sheet
                    if (m_iCookie != -1)
                    {
                        CNodeManager.GetNode(m_iCookie).FreePropertySheetNotifyHandle();
                        return(true);
                    }
                    // If we don't belong to a specific node, then we can't handle
                    // this message
                    return(false);

                case WM.PAINT:
                    // WinForms has problems repainting managed controls on an unmanaged
                    // form. We'll intercept every paint message and force all the
                    // managed controls to repaint themselves. This will create a little
                    // flicker, but it's better (for now) than having controls not show
                    // up at all.
                    if (m_uc != null)
                    {
                        m_uc.Refresh();
                    }
                    return(false);

                case WM.NOTIFY:

                    // lParam really is a pointer to a NMHDR structure....
                    NMHDR nm = new NMHDR();
                    nm = (NMHDR)Marshal.PtrToStructure(lParam, nm.GetType());

                    // We're about to lose focus of this property page. Make sure the data
                    // is valid before we allow that
                    //
                    // We only want to do validation though if they've made changes
                    if (nm.code == PSN.KILLACTIVE && m_fChanges)
                    {
                        if (!ValidateData())
                        {
                            // The data on the page had errors
                            SetWindowLong(hwndDlg, 0, 1);
                        }
                        return(true);
                    }

                    // If we're being told to apply changes made in the property pages....
                    else if (nm.code == PSN.APPLY)
                    {
                        // We'll only run through the Validate/Apply if the user made changes
                        if (m_fChanges)
                        {
                            // First, call a validate on the current page
                            if (!ValidateData() || !ApplyData())
                            {
                                // There were errors on this page...
                                // Set the appropriate return code here.
                                SetWindowLong(hwndDlg, 0, (int)PSNRET.INVALID_NOCHANGEPAGE);
                            }
                            else
                            {
                                m_fChanges = false;
                            }

                            return(true);
                        }
                    }
                    else if (nm.code == PSN.QUERYCANCEL)
                    {
                        // Ok, so this may look odd. Why do we send an WM_INITDIALOG right
                        // after we get a QUERYCANCEL?
                        //
                        // Well, our dialogs expect WM.INITDIALOG to be sent to them each time
                        // they are shown. Well, unfortunately, that doesn't seem to be the case
                        // now. It is sent once, when it is first shown. Now, we'll make
                        // sure it gets send again.
                        PostMessage(hwndDlg, WM.INITDIALOG, 0, 0);
                    }
                    break;

                default:
                    // We'll let the default windows message handler handle the rest of
                    // the messages
                    return(false);
                }
            }
            catch (Exception)
            {
                // We encountered an exception... let's just swallow the error and
                // hope everything will be ok.
                //
                // If we let this exception continue, it will kill the thread that's pumping
                // messages for the property page. This will cause MMC to hang. Not what we want.
            }
            return(false);
        }// PropPageDialogProc