コード例 #1
0
 public bool Install()
 {
     if (_installed)
     {
         return(false);
     }
     // Process
     if (_process == null)
     {
         _process = new RUser32.HWindowsHook(HookProcess);
     }
     // Scope
     if (_scope == EHookScope.Thread)
     {
         _nextHookPtr = RUser32.SetWindowsHookEx((int)_type, _process, IntPtr.Zero, RKernel32.GetCurrentThreadId());
     }
     if (_scope == EHookScope.Global)
     {
         //IntPtr ptr = Marshal.GetHINSTANCE(Assembly.GetExecutingAssembly().GetModules()[0]);
         string modulename = global::System.Diagnostics.Process.GetCurrentProcess().MainModule.ModuleName;
         IntPtr ptr        = RKernel32.GetModuleHandle(modulename);
         _nextHookPtr = RUser32.SetWindowsHookEx((int)_type, _process, ptr, 0);
     }
     _installed = true;
     return(true);
 }
 public void Release()
 {
     if (_menuHandle != IntPtr.Zero)
     {
         RUser32.DestroyMenu(_menuHandle);
         _menuHandle = IntPtr.Zero;
     }
 }
コード例 #3
0
        //============================================================
        public static string GetWindowText(IntPtr hWnd)
        {
            int           length = RUser32.GetWindowTextLength(hWnd);
            StringBuilder sb     = new StringBuilder(length);

            RUser32.GetWindowText(hWnd, sb, length);
            return(sb.ToString());
        }
        public void Insert(string text, bool enable)
        {
            EMft extraFlag = enable ? 0 : EMft.GRAYED;

            RUser32.InsertMenu(_menuHandle, 0, EMft.BYPOSITION | extraFlag, (int)(RWinShell.CMD_LAST + 1), text);
            RUser32.InsertMenu(_menuHandle, 1, EMft.BYPOSITION | EMft.SEPARATOR, 0, "-");
            RUser32.SetMenuDefaultItem(_menuHandle, 0, true);
        }
 public void Create()
 {
     if (_menuHandle == IntPtr.Zero)
     {
         _menuHandle = RUser32.CreatePopupMenu();
         _face.QueryContextMenu(_menuHandle, 0, RWinShell.CMD_FIRST, RWinShell.CMD_LAST, ECmf.NORMAL | ECmf.EXPLORE);
     }
 }
コード例 #6
0
 public bool Uninstall()
 {
     if (!_installed)
     {
         return(false);
     }
     RUser32.UnhookWindowsHookEx(_nextHookPtr);
     _nextHookPtr = IntPtr.Zero;
     _installed   = false;
     return(true);
 }
コード例 #7
0
        //============================================================
        public static Control GetFocusedControl()
        {
            Control control = null;
            IntPtr  handle  = RUser32.GetFocus();

            if (handle != IntPtr.Zero)
            {
                control = Control.FromHandle(handle);
            }
            return(control);
        }
コード例 #8
0
        // 0: 令待完成的动作继续完成
        // 1: 则取消原本要完成的动作
        protected IntPtr HookProcess(int code, IntPtr wparam, IntPtr lparam)
        {
            if (code >= 0)
            {
                if (Process(code, wparam, lparam))
                {
                    return((IntPtr)1);
                }
            }
            return(RUser32.CallNextHookEx(_nextHookPtr, code, wparam, lparam));

            /*if (Process(code, wparam, lparam)) {
             * return (IntPtr)1;
             * }*/
            //return IntPtr.Zero;
        }
        public void InvokeDefault(int x, int y)
        {
            Create();
            int defaultCommand = RUser32.GetMenuDefaultItem(_menuHandle, false, 0);

            if (defaultCommand != -1)
            {
                SCmInvokeCommandInfoEX invoke = new SCmInvokeCommandInfoEX();
                invoke.cbSize      = Marshal.SizeOf(typeof(SCmInvokeCommandInfoEX));
                invoke.lpVerb      = (IntPtr)(defaultCommand - RWinShell.CMD_FIRST);
                invoke.lpDirectory = string.Empty;
                invoke.fMask       = 0;
                invoke.ptInvoke    = new SPoint();
                invoke.ptInvoke.x  = x;
                invoke.ptInvoke.y  = y;
                invoke.nShow       = 1;
                _face.InvokeCommand(ref invoke);
            }
        }
        public int Popup(IntPtr handle, int x, int y)
        {
            Create();
            uint cmd = RUser32.TrackPopupMenuEx(_menuHandle, ETrackPopupMenu.RETURNCMD, x, y, handle, IntPtr.Zero);

            _menuHandle = IntPtr.Zero;
            if (cmd >= RWinShell.CMD_FIRST)
            {
                SCmInvokeCommandInfoEX invoke = new SCmInvokeCommandInfoEX();
                invoke.cbSize      = Marshal.SizeOf(typeof(SCmInvokeCommandInfoEX));
                invoke.lpVerb      = (IntPtr)(cmd - 1);
                invoke.lpDirectory = string.Empty;
                invoke.fMask       = 0;
                invoke.ptInvoke    = new SPoint();
                invoke.ptInvoke.x  = x;
                invoke.ptInvoke.y  = y;
                invoke.nShow       = 1;
                _face.InvokeCommand(ref invoke);
            }
            return((int)cmd);
        }