Ejemplo n.º 1
0
        private void WmNotifyDropDown(ref Message m)
        {
            NativeMethods.NMTOOLBAR nmTB = (NativeMethods.NMTOOLBAR)m.GetLParam(typeof(NativeMethods.NMTOOLBAR));
            ToolBoxButton           tbb  = buttons[nmTB.iItem];
            Menu menu = tbb.DropDownMenu;

            if (menu != null)
            {
                NativeMethods.RECT      rc  = new NativeMethods.RECT();
                NativeMethods.TPMPARAMS tpm = new NativeMethods.TPMPARAMS();
                UnsafeNativeMethods.SendMessage(new HandleRef(this, Handle), NativeMethods.TB_GETRECT, nmTB.iItem, ref rc);

                if ((menu.GetType()).IsAssignableFrom(typeof(ContextMenu)))
                {
                    ((ContextMenu)menu).Show(this, new Point(rc.left, rc.bottom));
                }
                else
                {
                    UnsafeNativeMethods.MapWindowPoints(new HandleRef(nmTB.hdr, nmTB.hdr.hwndFrom), NativeMethods.NullHandleRef, ref rc, 2);
                    tpm.rcExclude_left   = rc.left;
                    tpm.rcExclude_top    = rc.top;
                    tpm.rcExclude_right  = rc.right;
                    tpm.rcExclude_bottom = rc.bottom;
                    UnsafeNativeMethods.TrackPopupMenuEx(new HandleRef(menu, menu.Handle), NativeMethods.TPM_LEFTALIGN | NativeMethods.TPM_LEFTBUTTON | NativeMethods.TPM_VERTICAL, rc.left, rc.bottom, new HandleRef(this, Handle), tpm);
                }
            }
        }
Ejemplo n.º 2
0
        private void TrackPopupMenu(int index)
        {
            while (index >= 0)
            {
                npopupIndex = -1;
                cpopupIndex = index;

                UnsafeNativeMethods.SendMessage(new HandleRef(this, Handle), NativeMethods.TB_PRESSBUTTON, index, 1);
                UnsafeNativeMethods.SendMessage(new HandleRef(this, Handle), NativeMethods.TB_SETHOTITEM, index, IntPtr.Zero);
                MenuBoxItem tbb = items[index];
                tbb.mpressed = true;
                //安装钩子
                NativeMethods.WindowsHookProc hookProc = new NativeMethods.WindowsHookProc(MessageHook);
                messageHookHandle = UnsafeNativeMethods.SetWindowsHookEx(NativeMethods.WH_MSGFILTER, hookProc, NativeMethods.NullHandleRef, UnsafeNativeMethods.GetCurrentThreadId());
                if (messageHookHandle == IntPtr.Zero)
                {
                    throw new Win32Exception("SetWindowsHookEx Failt");
                }

                Menu menu = tbb.DropDownMenu;
                if (menu != null)
                {
                    NativeMethods.RECT      rc  = new NativeMethods.RECT();
                    NativeMethods.TPMPARAMS tpm = new NativeMethods.TPMPARAMS();
                    UnsafeNativeMethods.SendMessage(new HandleRef(this, Handle), NativeMethods.TB_GETRECT, index, ref rc);
                    if ((menu.GetType()).IsAssignableFrom(typeof(ContextMenu)))
                    {
                        ((ContextMenu)menu).Show(this, new Point(rc.left, rc.bottom));
                    }
                }
                base.Update();

                //卸载钩子
                UnsafeNativeMethods.UnhookWindowsHookEx(new HandleRef(null, messageHookHandle));
                messageHookHandle = IntPtr.Zero;
                if (menu != null)
                {
                    UnsafeNativeMethods.SendMessage(new HandleRef(this, this.Handle), NativeMethods.TB_PRESSBUTTON, index, 0);
                }
                index = npopupIndex;
            }
            UnsafeNativeMethods.SendMessage(new HandleRef(this, this.Handle), NativeMethods.TB_SETHOTITEM, -1, IntPtr.Zero);
        }
Ejemplo n.º 3
0
 public static extern bool TrackPopupMenuEx(HandleRef hmenu, int fuFlags, int x, int y, HandleRef hwnd, NativeMethods.TPMPARAMS tpm);