コード例 #1
0
        // TODO: what does this do?!
        // TODO: whatever it does, it should be returning an idl, not a path.
        public static string TrackGroupContextMenu(string groupName, Point pnt, IntPtr pDropDownHandle)
        {
            string name = string.Empty;
            Group  g    = GroupsManager.GetGroup(groupName);

            if (g == null)
            {
                return(name);
            }
            ContextMenu menu = new ContextMenu();

            if (!QTUtility.IsXP)
            {
                foreach (string str2 in g.Paths)
                {
                    string text;
                    if (str2.StartsWith(@"\\"))
                    {
                        text = str2;
                    }
                    else
                    {
                        text = ShellMethods.GetDisplayName(str2);
                    }
                    MenuItem item = new MenuItem(text);
                    item.Name = str2;
                    menu.MenuItems.Add(item);
                }
            }
            else
            {
                foreach (string path in g.Paths)
                {
                    string displayName;
                    if (path.StartsWith(@"\\"))
                    {
                        displayName = path;
                    }
                    else
                    {
                        displayName = ShellMethods.GetDisplayName(path);
                    }
                    MenuItemEx ex = new MenuItemEx(displayName);
                    ex.Name  = path;
                    ex.Image = QTUtility.ImageListGlobal.Images[QTUtility.GetImageKey(path, null)];
                    menu.MenuItems.Add(ex);
                }
            }
            List <IntPtr> list = new List <IntPtr>();

            if (!QTUtility.IsXP)
            {
                for (int k = 0; k < g.Paths.Count; k++)
                {
                    string imageKey = QTUtility.GetImageKey(g.Paths[k], null);
                    IntPtr hbitmap  = ((Bitmap)QTUtility.ImageListGlobal.Images[imageKey]).GetHbitmap(Color.Black);
                    if (hbitmap != IntPtr.Zero)
                    {
                        list.Add(hbitmap);
                        PInvoke.SetMenuItemBitmaps(menu.Handle, k, 0x400, hbitmap, IntPtr.Zero);
                    }
                }
            }
            uint maxValue = uint.MaxValue;

            if (menu.MenuItems.Count > 0)
            {
                maxValue = PInvoke.TrackPopupMenu(menu.Handle, 0x180, pnt.X, pnt.Y, 0, pDropDownHandle, IntPtr.Zero);
                if (maxValue != 0)
                {
                    for (int m = 0; m < menu.MenuItems.Count; m++)
                    {
                        if (maxValue == PInvoke.GetMenuItemID(menu.Handle, m))
                        {
                            name = menu.MenuItems[m].Name;
                            break;
                        }
                    }
                }
            }
            menu.Dispose();
            if (!QTUtility.IsXP)
            {
                foreach (IntPtr ptr2 in list)
                {
                    PInvoke.DeleteObject(ptr2);
                }
            }
            if (maxValue != 0)
            {
                return(name);
            }
            return(null);
        }
コード例 #2
0
ファイル: MenuUtility.cs プロジェクト: uvbs/test-code-backup
        public static string TrackGroupContextMenu(string groupName, Point pnt, IntPtr pDropDownHandle)
        {
            string str;
            string name = string.Empty;

            if (!QTUtility.GroupPathsDic.TryGetValue(groupName, out str))
            {
                return(name);
            }
            string[]    strArray = str.Split(QTUtility.SEPARATOR_CHAR);
            ContextMenu menu     = new ContextMenu();

            if (QTUtility.IsVista)
            {
                for (int i = 0; i < strArray.Length; i++)
                {
                    string text = string.Empty;
                    if (strArray[i].StartsWith(@"\\"))
                    {
                        text = strArray[i];
                    }
                    else
                    {
                        text = ShellMethods.GetDisplayName(strArray[i]);
                    }
                    MenuItem item = new MenuItem(text);
                    item.Name = strArray[i];
                    menu.MenuItems.Add(item);
                }
            }
            else
            {
                for (int j = 0; j < strArray.Length; j++)
                {
                    string displayName = string.Empty;
                    if (strArray[j].StartsWith(@"\\"))
                    {
                        displayName = strArray[j];
                    }
                    else
                    {
                        displayName = ShellMethods.GetDisplayName(strArray[j]);
                    }
                    MenuItemEx ex = new MenuItemEx(displayName);
                    ex.Name  = strArray[j];
                    ex.Image = QTUtility.ImageListGlobal.Images[QTUtility.GetImageKey(strArray[j], null)];
                    menu.MenuItems.Add(ex);
                }
            }
            List <IntPtr> list = new List <IntPtr>();

            if (QTUtility.IsVista)
            {
                for (int k = 0; k < strArray.Length; k++)
                {
                    string imageKey = QTUtility.GetImageKey(strArray[k], null);
                    IntPtr hbitmap  = ((Bitmap)QTUtility.ImageListGlobal.Images[imageKey]).GetHbitmap(System.Drawing.Color.Black);
                    if (hbitmap != IntPtr.Zero)
                    {
                        list.Add(hbitmap);
                        PInvoke.SetMenuItemBitmaps(menu.Handle, k, 0x400, hbitmap, IntPtr.Zero);
                    }
                }
            }
            uint maxValue = uint.MaxValue;

            if (menu.MenuItems.Count > 0)
            {
                maxValue = PInvoke.TrackPopupMenu(menu.Handle, 0x180, pnt.X, pnt.Y, 0, pDropDownHandle, IntPtr.Zero);
                if (maxValue != 0)
                {
                    for (int m = 0; m < menu.MenuItems.Count; m++)
                    {
                        if (maxValue == PInvoke.GetMenuItemID(menu.Handle, m))
                        {
                            name = menu.MenuItems[m].Name;
                            break;
                        }
                    }
                }
            }
            menu.Dispose();
            if (QTUtility.IsVista)
            {
                foreach (IntPtr ptr2 in list)
                {
                    PInvoke.DeleteObject(ptr2);
                }
            }
            if (maxValue != 0)
            {
                return(name);
            }
            return(null);
        }
コード例 #3
0
 public static string TrackGroupContextMenu(string groupName, Point pnt, IntPtr pDropDownHandle) {
     string str;
     string name = string.Empty;
     if(!QTUtility.GroupPathsDic.TryGetValue(groupName, out str)) {
         return name;
     }
     string[] strArray = str.Split(QTUtility.SEPARATOR_CHAR);
     ContextMenu menu = new ContextMenu();
     if(!QTUtility.IsXP) {
         foreach(string str2 in strArray) {
             string text;
             if(str2.StartsWith(@"\\")) {
                 text = str2;
             }
             else {
                 text = ShellMethods.GetDisplayName(str2);
             }
             MenuItem item = new MenuItem(text);
             item.Name = str2;
             menu.MenuItems.Add(item);
         }
     }
     else {
         foreach(string path in strArray) {
             string displayName;
             if(path.StartsWith(@"\\")) {
                 displayName = path;
             }
             else {
                 displayName = ShellMethods.GetDisplayName(path);
             }
             MenuItemEx ex = new MenuItemEx(displayName);
             ex.Name = path;
             ex.Image = QTUtility.ImageListGlobal.Images[QTUtility.GetImageKey(path, null)];
             menu.MenuItems.Add(ex);
         }
     }
     List<IntPtr> list = new List<IntPtr>();
     if(!QTUtility.IsXP) {
         for(int k = 0; k < strArray.Length; k++) {
             string imageKey = QTUtility.GetImageKey(strArray[k], null);
             IntPtr hbitmap = ((Bitmap)QTUtility.ImageListGlobal.Images[imageKey]).GetHbitmap(Color.Black);
             if(hbitmap != IntPtr.Zero) {
                 list.Add(hbitmap);
                 PInvoke.SetMenuItemBitmaps(menu.Handle, k, 0x400, hbitmap, IntPtr.Zero);
             }
         }
     }
     uint maxValue = uint.MaxValue;
     if(menu.MenuItems.Count > 0) {
         maxValue = PInvoke.TrackPopupMenu(menu.Handle, 0x180, pnt.X, pnt.Y, 0, pDropDownHandle, IntPtr.Zero);
         if(maxValue != 0) {
             for(int m = 0; m < menu.MenuItems.Count; m++) {
                 if(maxValue == PInvoke.GetMenuItemID(menu.Handle, m)) {
                     name = menu.MenuItems[m].Name;
                     break;
                 }
             }
         }
     }
     menu.Dispose();
     if(!QTUtility.IsXP) {
         foreach(IntPtr ptr2 in list) {
             PInvoke.DeleteObject(ptr2);
         }
     }
     if(maxValue != 0) {
         return name;
     }
     return null;
 }