public static BOOL EnumThreadWindows(uint dwThreadId, EnumThreadWindowsCallback lpfn, IHandle lParam) { BOOL result = EnumThreadWindows(dwThreadId, lpfn, lParam.Handle); GC.KeepAlive(lParam); return(result); }
//PID找主窗口 private void TrySetMainWindowHandle(int processId) { MainWindowHandle = IntPtr.Zero; ProcessId = processId; EnumThreadWindowsCallback callback = new EnumThreadWindowsCallback(EnumWindowsCallback); EnumWindows(callback, IntPtr.Zero); GC.KeepAlive(callback); }
internal IntPtr FindMainWindow(int processId) { Handle = (IntPtr)0; ID = processId; EnumThreadWindowsCallback enumThreadWindowsCallback = new EnumThreadWindowsCallback(EnumWindowsCallback); EnumWindows(enumThreadWindowsCallback, IntPtr.Zero); GC.KeepAlive(enumThreadWindowsCallback); return(Handle); }
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); }
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); }
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(); } }
private static extern bool EnumThreadWindows(uint dwThreadId, EnumThreadWindowsCallback callback, /*ref*/ IntPtr param);
public static extern bool EnumWindows(EnumThreadWindowsCallback lpEnumFunc, IntPtr lParam);
public static extern bool EnumWindows(EnumThreadWindowsCallback callback, IntPtr extraData);
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); } }
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); } }
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; }
public static extern bool EnumChildWindows(HandleRef hWndParent, EnumThreadWindowsCallback callback, IntPtr extraData);
public static extern bool EnumChildWindows(IntPtr hWndParent, EnumThreadWindowsCallback callback, IntPtr lParam);
private static extern bool EnumThreadWindows(int threadId, EnumThreadWindowsCallback callback, IntPtr lParam);
public static extern bool EnumThreadWindows( uint dwThreadId, EnumThreadWindowsCallback lpfn, IntPtr lParam);