Пример #1
0
        public void AddTransparencyMenu()
        {
            Trace.WriteLine("Add Transparency on Window: " + this.ToString());
            //HwndSource source = HwndSource.FromHwnd(Handle);
            //if (source != null)
            //{
            //    Trace.WriteLine("Add HwndSource Hook on Window: " + this.ToString());
            //    source.AddHook(WndProc);
            //}



            // This gets a handle to the system menu for a window. Once we have that handle, we can add our
            // own menu items.
            IntPtr windowMenuHandle = User32.GetSystemMenu(Handle, false);
            int    index            = User32.GetMenuItemCount(windowMenuHandle);

            _transparencyMenuHandle = User32.CreateMenu();
            User32.InsertMenu(_transparencyMenuHandle, -1, (int)User32.Menu.MF_BYPOSITION, TransparencyPercentId + 100, "100%");
            User32.InsertMenu(_transparencyMenuHandle, -1, (int)User32.Menu.MF_BYPOSITION, TransparencyPercentId + 95, "95%");
            User32.InsertMenu(_transparencyMenuHandle, -1, (int)User32.Menu.MF_BYPOSITION, TransparencyPercentId + 90, "90%");
            User32.InsertMenu(_transparencyMenuHandle, -1, (int)User32.Menu.MF_BYPOSITION, TransparencyPercentId + 85, "85%");
            User32.InsertMenu(_transparencyMenuHandle, -1, (int)User32.Menu.MF_BYPOSITION, TransparencyPercentId + 80, "80%");
            User32.InsertMenu(_transparencyMenuHandle, -1, (int)User32.Menu.MF_BYPOSITION, TransparencyPercentId + 75, "75%");
            User32.InsertMenu(_transparencyMenuHandle, -1, (int)User32.Menu.MF_BYPOSITION, TransparencyPercentId + 70, "70%");
            User32.InsertMenu(_transparencyMenuHandle, -1, (int)(User32.Menu.MF_BYPOSITION | User32.Menu.MF_SEPARATOR), 0, "");
            User32.InsertMenu(_transparencyMenuHandle, -1, (int)User32.Menu.MF_BYPOSITION, DefaultTransparencyMenuId, "Default Transparency");

            User32.InsertMenu(windowMenuHandle, index - 2, (int)(User32.Menu.MF_BYPOSITION | User32.Menu.MF_POPUP), _transparencyMenuHandle, "Transparency");
            User32.InsertMenu(_transparencyMenuHandle, -2, (int)(User32.Menu.MF_BYPOSITION | User32.Menu.MF_SEPARATOR), 0, "");
        }
Пример #2
0
        public void CreateHandle()
        {
            if (hMenu != IntPtr.Zero)
            {
                User32.DestroyMenu(hMenu);
            }

            hMenu = User32.CreateMenu();
        }
Пример #3
0
        public NativeMenu(bool createHandle = true, bool isPopup = true)
        {
            if (createHandle)
            {
                if (isPopup)
                {
                    hMenu = User32.CreatePopupMenu();
                }
                else
                {
                    hMenu = User32.CreateMenu();
                }
            }

            mCol = new NativeMenuItemCollection(hMenu);
        }