Bonjour,

Voici maintenant 3 jours que je planche sur le même sujet, à savoir récupérer le Handle d'une application style FireFox afin de pouvoir la déplacer comme bon me semble avec un MoveWindow. En effet, je voudrais bouger les fenêtre mais sans quel soit au premier plan, et sans passer par un FindWindow car je ne connais pas forcément sa classe ni son nom de barre de titre.

Ce sujet est en relation avec mon post sur Récupérer le moniteur sur lequel se trouve une fenêtre/application.

Le but, c'est de lister les processus, regarder si ils ont une fenêtre (les services, et autres, je m'en occupe pas) et de pouvoir intéragir sur le bon Handle pour y appliquer mon MoveWindow.
J'ai fait un bout de code, mais ça ne fonctionne pas
J'ai encore du mal avec les fonctions API (ça tombe, je n'utilise pas les bonnes).
Voici le code :
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
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
unit Unit1;
 
interface
 
uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls,TlHelp32,Math ;
 
type
  PFindWindowsStruct = ^TFindWindowsStruct;
  TFindWindowsStruct = record
    ProcessID: DWORD;
    HandleList: TList;
  end;
 
 TProcessInformations = record
   ProcessID : DWORD;
   ProcessHandle : THandle;
 end;
 
 
 
type
  TForm1 = class(TForm)
    Button1: TButton;
    Edit1: TEdit;
    GroupBox1: TGroupBox;
    GroupBox2: TGroupBox;
    StaticText1: TStaticText;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    StaticText2: TStaticText;
    StaticText3: TStaticText;
    Label4: TLabel;
    StaticText4: TStaticText;
    GroupBox3: TGroupBox;
    Button2: TButton;
    Label5: TLabel;
    Label6: TLabel;
    Edit2: TEdit;
    Edit3: TEdit;
    Label7: TLabel;
    Label8: TLabel;
    Edit4: TEdit;
    Edit5: TEdit;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
  private
    { Déclarations privées }
  public
    { Déclarations publiques }
  end;
 
var
  Form1: TForm1;
 
implementation
 
{$R *.dfm}
 
function EnumWindowsProc(hwnd: HWND; lParam: LPARAM): boolean; stdcall;
var
  dwProcessId: DWORD;
begin
  if lParam <> 0 then
  begin
    GetWindowThreadProcessId(hwnd, dwProcessId);
    with PFindWindowsStruct(lParam)^ do
      if dwProcessID = ProcessID then
        HandleList.Add(Pointer(hwnd));
    result:= true;
  end
  else
    result:= false;
end;
 
procedure FindProcessWindows(ProcessID: Integer; Handles: TList);
var
  findWindowsStruct: TFindWindowsStruct;
begin
  findWindowsStruct.ProcessID:= ProcessID;
  findWindowsStruct.HandleList:= Handles;
  EnumWindows(@EnumWindowsProc, Integer(@findWindowsStruct));
end;
 
function getProcessID(const ProcessName : string) : TProcessInformations;
var ProcessEntry32 : TProcessEntry32;
    HSnapShot : THandle;
    HProcess : THandle;
begin
  Result.ProcessID := 0;
  Result.ProcessHandle := INVALID_HANDLE_VALUE;
 
  HSnapShot := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
  if HSnapShot = 0 then exit;
 
  ProcessEntry32.dwSize := sizeof(ProcessEntry32);
  if Process32First(HSnapShot, ProcessEntry32) then
  repeat
    if CompareText(ProcessEntry32.szExeFile, ProcessName) = 0 then
    begin
      HProcess := OpenProcess(PROCESS_TERMINATE, False, ProcessEntry32.th32ProcessID);
      Result.ProcessHandle := HProcess;
      Result.ProcessID := ProcessEntry32.th32ProcessID;
      CloseHandle(HProcess);
      Break;
    end;
  until not Process32Next(HSnapShot, ProcessEntry32);
  CloseHandle(HSnapshot);
end;
 
 
procedure TForm1.Button2Click(Sender: TObject);
var
 handles: TList;
 i : integer;
begin
  handles:= TList.Create;
    try
      FindProcessWindows(getProcessID(Edit1.Text).ProcessID, handles);
      for i := 0 to handles.Count - 1 do
      begin
        if(IsWindow(Integer(handles[i])))then
          MoveWindow (Integer(handles[i]),StrToInt(Edit2.Text),StrToInt(Edit3.Text),StrToInt(Edit4.Text),StrToInt(Edit5.Text),true);
      end;
    finally
      handles.Free;
    end;
end;
 
end.
J'espère que vous pourrez m'indiquer les bonnes directions dans lesquelles je dois chercher...
Merci par avance

Ero