Make the Child Window and parent window both active

Source: Internet
Author: User

Normally, when the parent window is activated, the Child Window will lose the focus. Similarly, when the child window is activated, the parent window will also lose the focus, which is not very nice in some cases, for example, when a child window floats above the parent window as a ToolWindow. Visual Studio also seems to have this problem. When a floating DockingPanel is activated, the focus of the Visual Studio main window will be lost.
The last two images are more clear,
The general effect is as follows:

We are pursuing the following results:

 

Well, there is a simple package here. You can copy the code and use it directly (the Framework version requires 3.5 ):
 

Using System;
Using System. Runtime. InteropServices;
Using System. Windows;
Using System. Windows. Interop;

Namespace YourNamespace
{
Public static class WindowActiveService
{
Internal class WindowActiveHelper
{
[DllImport ("user32", CharSet = CharSet. Auto)]
Private extern static int SendMessage (
IntPtr handle, int msg, int wParam, IntPtr lParam );

[DllImport ("user32.dll")]
Private static extern IntPtr GetForegroundWindow ();

// ReSharper disable InconsistentNaming
Private const int WM_NCACTIVATE = 0x086;
// ReSharper restore InconsistentNaming
Private IntPtr ownerHwnd = IntPtr. Zero;
Private IntPtr childHwnd = IntPtr. Zero;
Private HwndSource ownerHwndSource;
Private HwndSource childHwndSource;
Private HwndSourceHook ownerHook;
Private HwndSourceHook childHook;
Private bool childActive;
Private bool ownerActive;

Private static IntPtr get1_whwnd (Window window Window)
{
Var helper = new WindowInteropHelper (window );
Return helper. Handle;
}

Private IntPtr FilterChildMessage (IntPtr hwnd, int msg, IntPtr wParam, IntPtr

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.