Comment obtenir des légendes de fenêtres réelles en cours d’exécution?

J’ai une question: je dois simplement obtenir des légendes de toutes les fenêtres dans une liste, par légendes, je veux dire le “Bloc-notes”, “Total Commander” – simplement le texte affiché dans le bord supérieur d’une fenêtre.

Jusqu’à présent, je suis arrivé ici

function EnumWindowProc(hHwnd: HWND; lParam : integer): boolean; stdcall; var pPid : DWORD; title, ClassName : ssortingng; begin if (hHwnd=NULL) then begin result := false; end else begin GetWindowThreadProcessId(hHwnd,pPid); SetLength(ClassName, 255); SetLength(ClassName, GetClassName(hHwnd, PChar(className), Length(className))); SetLength(title, 255); SetLength(title, GetWindowText(hHwnd, PChar(title), Length(title))); OptionsForm.ListBox1.Items.Add(title); OptionsForm.Memo1.Lines.Add ('Class Name = ' + className + '; Title = ' + title + '; HWND = ' + IntToStr(hHwnd) + '; Pid = ' + IntToStr(pPid)); Result := true; end; end; 

Mais bon, il retourne toutes sortes de “fenêtres”, différents foyers de formes etc. Comment puis-je ne récupérer que les “principales”?

Voici un échantillon des résultats:

 Class Name = Shell_TrayWnd; Title = ; HWND = 65898; Pid = 3776 Class Name = CiceroUIWndFrame; Title = CiceroUIWndFrame; HWND = 65976; Pid = 3776 Class Name = THelpInsightWindowImpl; Title = HelpInsightWindow; HWND = 1577734; Pid = 4852 Class Name = THelpInsightWindowImpl; Title = HelpInsightWindow; HWND = 591660; Pid = 4852 Class Name = TTokenWindow; Title = CodeParamWindow; HWND = 985436; Pid = 4852 Class Name = TaskSwitcherWnd; Title = Přepínání úloh; HWND = 66824; Pid = 3776 Class Name = tooltips_class32; Title = ; HWND = 198982; Pid = 1768 Class Name = tooltips_class32; Title = ; HWND = 66046; Pid = 3776 Class Name = _SearchEditBoxFakeWindow; Title = ; HWND = 66024; Pid = 3776 Class Name = tooltips_class32; Title = ; HWND = 66008; Pid = 3776 Class Name = tooltips_class32; Title = ; HWND = 131538; Pid = 3776 Class Name = Desktop User Picture; Title = Magicmaster; HWND = 65982; Pid = 3776 Class Name = DV2ControlHost; Title = Nabídka Start; HWND = 65978; Pid = 3776 Class Name = tooltips_class32; Title = ; HWND = 327840; Pid = 1768 Class Name = tooltips_class32; Title = ; HWND = 460808; Pid = 1768 Class Name = CTSCTooltip; Title = ; HWND = 266710; Pid = 2792 Class Name = Auto-Suggest Dropdown; Title = ; HWND = 69884; Pid = 4732 Class Name = Auto-Suggest Dropdown; Title = ; HWND = 69802; Pid = 4732 Class Name = TaskbarNotifierClass; Title = DAP Message Center; HWND = 68924; Pid = 4732 Class Name = tooltips_class32; Title = ; HWND = 134356; Pid = 1992 Class Name = ATKOSD; Title = ATKOSD; HWND = 65884; Pid = 3636 

Merci d’avance!

Les informations importantes sont contenues dans la rubrique MSDN décrivant la barre des tâches . Essentiellement, vous devez énumérer les fenêtres de niveau supérieur et choisir celles qui sont visibles, sans propriétaire et qui ont le style de fenêtre WS_EX_APPWINDOW .

Ce programme vous montre comment c’est fait:

 program EnumTaskbarWindows; {$APPTYPE CONSOLE} uses SysUtils, Windows; function EnumWindowsProc(hwnd: HWND; lParam: LPARAM): BOOL; stdcall; var s: ssortingng; IsVisible, IsOwned, IsAppWindow: Boolean; begin Result := True;//carry on enumerating IsVisible := IsWindowVisible(hwnd); if not IsVisible then exit; IsOwned := GetWindow(hwnd, GW_OWNER)<>0; if IsOwned then exit; IsAppWindow := GetWindowLongPtr(hwnd, GWL_STYLE) and WS_EX_APPWINDOW<>0; if not IsAppWindow then exit; SetLength(s, GetWindowTextLength(hwnd)); GetWindowText(hwnd, PChar(s), Length(s)+1); Writeln(s); end; begin EnumWindows(@EnumWindowsProc, 0); end. 

Vous voulez vérifier les propriétés de ces fenêtres. Par exemple, excluez toute fenêtre non visible. Vous faites cela avec GetWindowInfo . Les propriétés à rechercher: aucune légende ( WS_CAPTION manquant dans dwStyle ) ou non visible (indicateur WS_VISIBLE ). Vous voudrez peut-être aussi vérifier les fenêtres qui sont déplacées hors de l’écran, mais c’est un peu difficile (il peut y avoir plusieurs moniteurs, même avec des décalages négatifs)