Bonjour,
Je souhaite sélectionner la fenetre située en dessous de mon application WinForms pour lui envoyer des entrées clavier.
Pour cela j'utilise le code suivant :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 enum GetWindow_Cmd : uint { GW_HWNDFIRST = 0, GW_HWNDLAST = 1, GW_HWNDNEXT = 2, GW_HWNDPREV = 3, GW_OWNER = 4, GW_CHILD = 5, GW_ENABLEDPOPUP = 6 } [DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)] public static extern IntPtr GetForegroundWindow(); [return: MarshalAs(UnmanagedType.Bool)] [DllImport("user32", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)] public static extern bool SetForegroundWindow(IntPtr hwnd); [DllImport("user32.dll", SetLastError = true)] static extern IntPtr GetWindow(IntPtr hWnd, GetWindow_Cmd uCmd);Ce code fait bien apparaitre la fentre du dessous, mais je n'ai pas le focus sur cette fenetre.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3 IntPtr ptrSrcWindow = GetForegroundWindow(); IntPtr ptrDstWindow = GetWindow(ptrSrcWindow, GetWindow_Cmd.GW_HWNDNEXT); SetForegroundWindow(ptrDstWindow);
J'ai également essayé avec les fonction GetActiveWindow et SetActiveWindow mais cela ne donne rien.
Comment faire pour sélectionner la fenêtre du dessous et avoir le focus?
Merci d'avance.
Partager