当前位置: 首页>>代码示例>>C#>>正文


C# IContextMenu.QueryContextMenu方法代码示例

本文整理汇总了C#中IContextMenu.QueryContextMenu方法的典型用法代码示例。如果您正苦于以下问题:C# IContextMenu.QueryContextMenu方法的具体用法?C# IContextMenu.QueryContextMenu怎么用?C# IContextMenu.QueryContextMenu使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IContextMenu的用法示例。


在下文中一共展示了IContextMenu.QueryContextMenu方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: iContextMenu

        //     public void iContextMenu(string sParent, string sSelected, System.Drawing.Point location, object f1, bool bSpecialFolderFlag)
        public void iContextMenu(string sParent, string sSelected, bool bSpecialFolderFlag)
        {
            IntPtr shellFolderPtr;
            SHGetDesktopFolder(out shellFolderPtr);
            iShellFolder.IShellFolder shellFolder =
                (iShellFolder.IShellFolder)Marshal.GetTypedObjectForIUnknown(shellFolderPtr, typeof(iShellFolder.IShellFolder));

            uint pchEaten = 0;
            int nResult = 0;
            IntPtr pPIDL = IntPtr.Zero;
            iShellFolder.SFGAO pdwAttributes = iShellFolder.SFGAO.FILESYSTEM;

            if (bSpecialFolderFlag) //for root drives - get "My Computer"
            {
                nResult = ShellExtensions.SHGetSpecialFolderLocation(this.Handle,
                    ShellExtensions.CSIDL.CSIDL_DRIVES,
                    out pPIDL);
            }
            else
            {
                nResult = shellFolder.ParseDisplayName(this.Handle,
                    IntPtr.Zero,
                    sParent,
                    ref pchEaten,
                    out pPIDL,
                    ref pdwAttributes);
            }
            if(nResult == 0)
            {
                // Get the IShellFolder for folder
                IntPtr pUnknownParentFolder = IntPtr.Zero;

                if (shellFolder.BindToObject(pPIDL,
                    IntPtr.Zero,
                    ref iShellFolder.Guid_IShellFolder.IID_IShellFolder,
                    out pUnknownParentFolder) == S_OK)
                {
                    // Free the PIDL first
                    Marshal.FreeCoTaskMem(pPIDL);
                    pPIDL = IntPtr.Zero;
                    IntPtr[] aPidl = new IntPtr[1];
                    shellFolder = (iShellFolder.IShellFolder)Marshal.GetTypedObjectForIUnknown(pUnknownParentFolder,
                        typeof(iShellFolder.IShellFolder));

                    nResult = shellFolder.ParseDisplayName(this.Handle,
                        IntPtr.Zero,
                        sSelected,
                        ref pchEaten,
                        out pPIDL,
                        ref pdwAttributes);

                    aPidl[0] = pPIDL;

                    IntPtr iContextMenuPtr = IntPtr.Zero,
                       iContextMenuPtr2 = IntPtr.Zero,
                       iContextMenuPtr3 = IntPtr.Zero;;

                    shellFolder.GetUIObjectOf(this.Handle,
                        1,
                        aPidl,
                        ref IID_IContextMenu,
                        0,
                        out iContextMenuPtr);

                    //*********************

                    _oContextMenu = (IContextMenu)Marshal.GetTypedObjectForIUnknown(iContextMenuPtr, typeof(IContextMenu));

                    IntPtr pUnknownContextMenu2 = IntPtr.Zero;
                    if (S_OK == Marshal.QueryInterface(iContextMenuPtr, ref IID_IContextMenu2, out pUnknownContextMenu2))
                    {
                        _oContextMenu2 = (IContextMenu2)Marshal.GetTypedObjectForIUnknown(pUnknownContextMenu2, typeof(IContextMenu2));
                    }
                    IntPtr pUnknownContextMenu3 = IntPtr.Zero;
                    if (S_OK == Marshal.QueryInterface(iContextMenuPtr, ref IID_IContextMenu3, out pUnknownContextMenu3))
                    {
                        _oContextMenu3 = (IContextMenu3)Marshal.GetTypedObjectForIUnknown(pUnknownContextMenu3, typeof(IContextMenu3));
                    }

                    IntPtr pMenu = IntPtr.Zero;
                    pMenu = CreatePopupMenu();

                    nResult = _oContextMenu.QueryContextMenu(
                        pMenu,
                        0,
                        CMD_FIRST,
                        CMD_LAST,
                        CMF.EXPLORE |
                        CMF.NORMAL |
                        ((Control.ModifierKeys & System.Windows.Forms.Keys.Shift) != 0 ? CMF.EXTENDEDVERBS : 0));

                     Marshal.QueryInterface(iContextMenuPtr, ref IID_IContextMenu2, out iContextMenuPtr2);
                    Marshal.QueryInterface(iContextMenuPtr, ref IID_IContextMenu3, out iContextMenuPtr3);

                    _oContextMenu2 = (IContextMenu2)Marshal.GetTypedObjectForIUnknown(iContextMenuPtr2, typeof(IContextMenu2));
                    _oContextMenu3 = (IContextMenu3)Marshal.GetTypedObjectForIUnknown(iContextMenuPtr3, typeof(IContextMenu3));

                   uint nSelected = TrackPopupMenuEx(
                    pMenu,
//.........这里部分代码省略.........
开发者ID:priceLiu,项目名称:ServerController,代码行数:101,代码来源:IShellContextMenu.cs


注:本文中的IContextMenu.QueryContextMenu方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。