Ejemplo n.º 1
0
        /// <summary>
        /// Add property page for this object
        /// </summary>
        /// <param name="lpfnAddPage"></param>
        /// <param name="lParam"></param>
        /// <returns></returns>
        int IShellPropSheetExt.AddPages(LPFNSVADDPROPSHEETPAGE pfnAddPage, IntPtr lParam)
        {
            try
            {
                // ADD PAGES HERE
                SheetControl  samplePage;
                PROPSHEETPAGE psp;
                IntPtr        hPage;

                // create new inherited property page(s) and pass dobj to it
                samplePage = new DokanNFCSheet();
                psp        = samplePage.GetPSP(250, 230);

                hPage = ShellAPIWrapper.CreatePropertySheetPage(ref psp);
                bool result = pfnAddPage(hPage, lParam);
                if (!result)
                {
                    ShellAPIWrapper.DestroyPropertySheetPage(hPage);
                }

                // We'll add reference manualy only if there is no exceptions
                samplePage.KeepAlive();
            }
            catch (Exception ex)
            {
                System.Windows.Forms.MessageBox.Show(ex.ToString());
            }
            return(0);
        }
Ejemplo n.º 2
0
        public static IntPtr CreatePropertySheetPage(ref PROPSHEETPAGE psp)
        {
            IntPtr hPage = ShellAPIWrapper.CreatePropertySheetPage_(ref psp);

            if (hPage == IntPtr.Zero)
            {
                throw new Exception("CreatePropertySheetPage failed");
            }
            return(hPage);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Handle all messages coming sent to the property page
        /// </summary>
        /// <param name="hwndDlg"></param>
        /// <param name="msg"></param>
        /// <param name="wParam"></param>
        /// <param name="lParam"></param>
        /// <returns></returns>
        public bool PropPageDialogProc(IntPtr hwndDlg, uint msg, IntPtr wParam, IntPtr lParam)
        {
            switch ((WM)msg)
            {
            case WM.INITDIALOG:
                // Set up our parent managed control first
                // Warning: this is NOT supported feature in Windows Forms,
                // The only supported unmanaged container for managed controls is IE
                this.hWin32Dlg = hwndDlg;
                ShellAPIWrapper.SetParent(this.Handle, this.hWin32Dlg);
                break;

            case WM.PAINT:
                // MS sample used to have a Refresh() here. (Then you can return true?).
                // If you don't return false ,you keep on getting paint messages!
                return(false);

            case WM.NOTIFY:
                // Most notifications are sent in the form of a WM_NOTIFY message.
                // To set the return value that some of the notifications require, the
                // dialog box procedure must call SetWindowLong function and return TRUE.
                // Do not kill,add,remove pages/dialogs during most notification handling

                int pResult;
                if (OnNotify(wParam, lParam, out pResult))
                {
                    ShellAPIWrapper.SetWindowLong(hWin32Dlg, (int)DWL.MSGRESULT, pResult);
                }
                // if we dont send, should we still send return true?

                break;

            // case WM.DESTROY: ? If an application processes this message, it should return zero!

            default:
                // We'll let the default windows (dialog procedure) message
                // handler handle the rest of the messages
                return(false);

                // WM.COMMAND,WM.GETDLGCODE,WM.KILLFOCUS,WM.SETFOCUS,WM.CHAR never arrive
            }
            return(true);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Page handler function
        /// </summary>
        /// <param name="wParam"></param>
        /// <param name="lParam"></param>
        /// <param name="pResult"></param>
        /// <returns></returns>
        protected virtual bool OnNotify(IntPtr wParam, IntPtr lParam, out int pResult)
        {
            NMHDR nmhdr = (NMHDR)Marshal.PtrToStructure(lParam, typeof(NMHDR));

            pResult = 0;

            // don't handle messages not from the page/sheet itself?
            if (nmhdr.hwndFrom != hWin32Dlg && nmhdr.hwndFrom != ShellAPIWrapper.GetParent(hWin32Dlg))
            {
                return(false);
            }

            switch ((PSN)nmhdr.code)
            {
            case PSN.SETACTIVE:
                // Notifies a page that it is about to be activated.
                // Returns zero to accept the activation, or -1 to activate the next or
                // the previous page (depending on whether the user clicked Next or Back).
                pResult = 0;
                break;

            case PSN.KILLACTIVE:
                // Notifies a page that it is about to lose activation either because another page
                // is being activated or the user has clicked the OK button.
                // We always return true for this because we validate on control already
                pResult = 0;
                break;

            case PSN.APPLY:
                // Sometimes the Apply button causes a page to make a change to a property sheet,
                // and the change cannot be undone. When this happens, the page must send the
                // PSM_CANCELTOCLOSE message to the property sheet. --> doesn't work

                //	After making such a change, a page can send either the PSM_RESTARTWINDOWS or
                //	PSM_REBOOTSYSTEM message to the property sheet. to restart the system!!

                if (modified)
                {
                    OnApply();
                    modified = false;
                }

                pResult = (int)PSNRET.NOERROR;
                break;

            case PSN.RESET:
                // Notifies a page that the property sheet is about to be destroyed.
                // I think this means cancel, we don't care ... MFC: OnReset();
                break;

            case PSN.QUERYCANCEL:
                break;

            /////////////////////////////////////////////////////////////////////////
            // Wizard messages

            case PSN.WIZNEXT:
                //WINBUG: Win32 will send a PSN_WIZBACK even if the button is disabled.
                break;

            case PSN.WIZBACK:
                //WINBUG: Win32 will send a PSN_WIZBACK even if the button is disabled.
                break;

            case PSN.WIZFINISH:
                break;

            //////////////////////////////////////////////////////////////////////////////////

            case PSN.HELP:
                // -- For help, we can use tool tips instead. cool.
                // SendMessage(WM_COMMAND, ID_HELP);
                break;

            case PSN.QUERYINITIALFOCUS:
                pResult = 0;
                // An application must not call the SetFocus function while
                // handling this notification. Return the handle of the control
                // that should receive focus.
                break;

            case PSN.TRANSLATEACCELERATOR:
                // Accelerator keys messages.
                // We handle this message to handle TAB and SHIFT TAB buttons.
                // Hot keys must be handled here too. Weired: these already work in hyenet!

                // Note: tried overriding ProcessTabKey(),ProcessDialogKey(),WndProc(),_KeyPress(),_KeyDown().
                // Also try passing message to usercontrol() with out much success (for the TAB problem).
                // Also tried changing our base type to Form instead of UserControl, but didn't work.

                PSHNOTIFY pshn = (PSHNOTIFY)Marshal.PtrToStructure(lParam, typeof(PSHNOTIFY));
                MSG       iMsg = (MSG)Marshal.PtrToStructure(pshn.lParam, typeof(MSG));
                pResult = (int)PSNRET.NOERROR;

                // shift key
                if ((int)iMsg.wParam == 16)
                {
                    if (iMsg.message == (uint)WM.KEYDOWN)
                    {
                        shift = true;
                    }
                    else if (iMsg.message == (uint)WM.KEYUP)
                    {
                        shift = false;
                    }
                }

                // tab key
                if ((int)iMsg.wParam == 9 && iMsg.message == (uint)WM.KEYDOWN)
                {
                    ProcessTabKey(!shift);

                    // 1- visual selection (khattaye doresh) of TAB doesn't work on DW server console.
                    // 2- If control at end / start send WM.NEXTDLGCTL to property sheet to WRAP.

                    pResult = (int)PSNRET.MESSAGEHANDLED;
                    // no more processing needed (remove windows tab, with it's wrong order)
                }

                break;

            default:
                return(false);      //Not handled
            }
            return(true);           //Handled
        }