示例#1
0
        public static BOOL EnumThreadWindows(uint dwThreadId, EnumThreadWindowsCallback lpfn, IHandle lParam)
        {
            BOOL result = EnumThreadWindows(dwThreadId, lpfn, lParam.Handle);

            GC.KeepAlive(lParam);
            return(result);
        }
示例#2
0
        //PID找主窗口
        private void TrySetMainWindowHandle(int processId)
        {
            MainWindowHandle = IntPtr.Zero;
            ProcessId        = processId;
            EnumThreadWindowsCallback callback = new EnumThreadWindowsCallback(EnumWindowsCallback);

            EnumWindows(callback, IntPtr.Zero);
            GC.KeepAlive(callback);
        }
示例#3
0
            internal IntPtr FindMainWindow(int processId)
            {
                Handle = (IntPtr)0;
                ID     = processId;
                EnumThreadWindowsCallback enumThreadWindowsCallback = new EnumThreadWindowsCallback(EnumWindowsCallback);

                EnumWindows(enumThreadWindowsCallback, IntPtr.Zero);
                GC.KeepAlive(enumThreadWindowsCallback);
                return(Handle);
            }
示例#4
0
        public static IntPtr NucleusGetMainWindowHandle(this Process p)
        {
            bestHandle          = (IntPtr)0;
            processIdOfInterest = p.Id;

            var callback = new EnumThreadWindowsCallback(EnumWindowsCallback);

            EnumWindows(callback, IntPtr.Zero);

            GC.KeepAlive((object)callback);

            return(bestHandle);
        }
示例#5
0
 public IntPtr GetMainWindowHandle(int processId)
 {
     if (!this.haveMainWindow)
     {
         this.mainWindowHandle = IntPtr.Zero;
         this.processId        = processId;
         EnumThreadWindowsCallback callback = new EnumThreadWindowsCallback(this.EnumWindowsCallback);
         EnumWindows(callback, IntPtr.Zero);
         GC.KeepAlive(callback);
         this.haveMainWindow = true;
     }
     return(this.mainWindowHandle);
 }
    private void GetMainWindowHandle(int processId)
    {
        if (_mainWindowHandle != IntPtr.Zero)
        {
            return;
        }

        _processId = processId;
        EnumThreadWindowsCallback callback = EnumWindowsCallback;

        EnumWindows(callback, IntPtr.Zero);
        GC.KeepAlive(callback);
    }
示例#7
0
文件: IME.cs 项目: huqiang0204/HGUI
        public static IntPtr GetMainWindowHandle(int procId)
        {
            if (!haveMainWindow)
            {
                mainWindowHandle = IntPtr.Zero;
                processId        = procId;
                EnumThreadWindowsCallback callback = new EnumThreadWindowsCallback(EnumWindowsCallback);
                EnumWindows(callback, IntPtr.Zero);
                GC.KeepAlive(callback);

                haveMainWindow = true;
            }
            return(mainWindowHandle);
        }
        public static BOOL EnumThreadWindows(uint dwThreadId, EnumThreadWindowsCallback lpfn)
        {
            // We pass a static delegate to the native function and supply the callback as
            // reference data, so that the CLR doesn't need to generate a native code block for
            // each callback delegate instance (for storing the closure pointer).
            var gcHandle = GCHandle.Alloc(lpfn);

            try
            {
                return(EnumThreadWindows(dwThreadId, s_enumThreadWindowsNativeCallback, GCHandle.ToIntPtr(gcHandle)));
            }
            finally
            {
                gcHandle.Free();
            }
        }
示例#9
0
文件: Excel.cs 项目: yeaicc/ExcelDna
 private static extern bool EnumThreadWindows(uint dwThreadId, EnumThreadWindowsCallback callback, /*ref*/ IntPtr param);
示例#10
0
 public static extern bool EnumWindows(EnumThreadWindowsCallback lpEnumFunc, IntPtr lParam);
示例#11
0
 public static extern bool EnumWindows(EnumThreadWindowsCallback callback, IntPtr extraData);
示例#12
0
文件: Form.cs 项目: mind0n/hive
        internal override void RecreateHandleCore() {
            //Debug.Assert( CanRecreateHandle(), "Recreating handle when form is not ready yet." );
            NativeMethods.WINDOWPLACEMENT wp = new NativeMethods.WINDOWPLACEMENT();
            FormStartPosition oldStartPosition = FormStartPosition.Manual;

            if (!IsMdiChild && (WindowState == FormWindowState.Minimized || WindowState == FormWindowState.Maximized)) {
                wp.length = Marshal.SizeOf(typeof(NativeMethods.WINDOWPLACEMENT));
                UnsafeNativeMethods.GetWindowPlacement(new HandleRef(this, Handle), ref wp);
            }

            if (StartPosition != FormStartPosition.Manual) {
                oldStartPosition = StartPosition;
                // Set the startup postion to manual, to stop the form from
                // changing position each time RecreateHandle() is called.
                StartPosition = FormStartPosition.Manual;
            }

            EnumThreadWindowsCallback etwcb = null;
            SafeNativeMethods.EnumThreadWindowsCallback callback = null;
            if (IsHandleCreated) {
                // First put all the owned windows into a list
                etwcb = new EnumThreadWindowsCallback();
                if (etwcb != null) {
                    callback = new SafeNativeMethods.EnumThreadWindowsCallback(etwcb.Callback);
                    UnsafeNativeMethods.EnumThreadWindows(SafeNativeMethods.GetCurrentThreadId(),
                                                          new NativeMethods.EnumThreadWindowsCallback(callback),
                                                          new HandleRef(this, this.Handle));
                    // Reset the owner of the windows in the list
                    etwcb.ResetOwners();
                }
            }

            base.RecreateHandleCore();


            if (etwcb != null) {
                // Set the owner of the windows in the list back to the new Form's handle
                etwcb.SetOwners(new HandleRef(this, this.Handle));
            }
            
            if (oldStartPosition != FormStartPosition.Manual) {
                StartPosition = oldStartPosition;
            }

            if (wp.length > 0) {
                UnsafeNativeMethods.SetWindowPlacement(new HandleRef(this, Handle), ref wp);
            }

            if (callback != null) {
                GC.KeepAlive(callback);
            }
        }
示例#13
0
文件: Program.cs 项目: yinwun/SATools
 private static extern bool EnumWindows(EnumThreadWindowsCallback callback, IntPtr extraData); [DllImport("user32.dll", ExactSpelling = true)]
 internal override void RecreateHandleCore()
 {
     System.Windows.Forms.NativeMethods.WINDOWPLACEMENT placement = new System.Windows.Forms.NativeMethods.WINDOWPLACEMENT();
     FormStartPosition manual = FormStartPosition.Manual;
     if (!this.IsMdiChild && ((this.WindowState == FormWindowState.Minimized) || (this.WindowState == FormWindowState.Maximized)))
     {
         placement.length = Marshal.SizeOf(typeof(System.Windows.Forms.NativeMethods.WINDOWPLACEMENT));
         System.Windows.Forms.UnsafeNativeMethods.GetWindowPlacement(new HandleRef(this, base.Handle), ref placement);
     }
     if (this.StartPosition != FormStartPosition.Manual)
     {
         manual = this.StartPosition;
         this.StartPosition = FormStartPosition.Manual;
     }
     EnumThreadWindowsCallback callback = null;
     System.Windows.Forms.SafeNativeMethods.EnumThreadWindowsCallback callback2 = null;
     if (base.IsHandleCreated)
     {
         callback = new EnumThreadWindowsCallback();
         if (callback != null)
         {
             callback2 = new System.Windows.Forms.SafeNativeMethods.EnumThreadWindowsCallback(callback.Callback);
             System.Windows.Forms.UnsafeNativeMethods.EnumThreadWindows(System.Windows.Forms.SafeNativeMethods.GetCurrentThreadId(), new System.Windows.Forms.NativeMethods.EnumThreadWindowsCallback(callback2.Invoke), new HandleRef(this, base.Handle));
             callback.ResetOwners();
         }
     }
     base.RecreateHandleCore();
     if (callback != null)
     {
         callback.SetOwners(new HandleRef(this, base.Handle));
     }
     if (manual != FormStartPosition.Manual)
     {
         this.StartPosition = manual;
     }
     if (placement.length > 0)
     {
         System.Windows.Forms.UnsafeNativeMethods.SetWindowPlacement(new HandleRef(this, base.Handle), ref placement);
     }
     if (callback2 != null)
     {
         GC.KeepAlive(callback2);
     }
 }
示例#15
0
 public IntPtr GetMainWindowHandle(int processId)
 {
     if (!this.haveMainWindow)
     {
         this.mainWindowHandle = IntPtr.Zero;
         this.processId = processId;
         EnumThreadWindowsCallback callback = new EnumThreadWindowsCallback(this.EnumWindowsCallback); EnumWindows(callback, IntPtr.Zero);
         GC.KeepAlive(callback);
         this.haveMainWindow = true;
     }
     return this.mainWindowHandle;
 }
示例#16
0
 public static extern bool EnumChildWindows(HandleRef hWndParent, EnumThreadWindowsCallback callback, IntPtr extraData);
示例#17
0
 public static extern bool EnumChildWindows(IntPtr hWndParent, EnumThreadWindowsCallback callback, IntPtr lParam);
示例#18
0
 private static extern bool EnumThreadWindows(int threadId, EnumThreadWindowsCallback callback, IntPtr lParam);
示例#19
0
 public static extern bool EnumThreadWindows(
     uint dwThreadId,
     EnumThreadWindowsCallback lpfn,
     IntPtr lParam);
示例#20
0
 public static extern bool EnumWindows(EnumThreadWindowsCallback callback, IntPtr extraData);
示例#21
0
文件: Excel.cs 项目: red2901/ExcelDna
 private static extern bool EnumThreadWindows(uint dwThreadId, EnumThreadWindowsCallback callback, /*ref*/ IntPtr param);