Hallo,
ich hab ein Programm welches aus 2 Teilen besteht.
Zuerst gibt der Benutzer die .exe Datei an, dann wird der Handle dazu erkannt.
Des weiteren klick der Benutzer auf einen Button und das Window zur .exe Datei soll minimiert werden. Doch leider wird immer nur das Programm selber minimiert:
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:
| unit Unit1;
interface
uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, TLHelp32;
type TForm1 = class(TForm) Button1: TButton; Button2: TButton; Edit1: TEdit; Label1: TLabel; procedure Button1Click(Sender: TObject); procedure Button2Click(Sender: TObject); private public end;
var Form1: TForm1; WindowHandle: THandle; h:HWnd;
implementation
{$R *.DFM}
function GetWindowThreadProcessId(hWnd: HWND; var dwProcessId: DWORD): DWORD; stdcall; external 'user32.dll' name 'GetWindowThreadProcessId';
function MyEnumWindowProc(AHandle: THandle; LParam: LongWord): boolean; stdcall; var ProcessID: THandle; begin ProcessID := 0; GetWindowThreadProcessID(AHandle, ProcessID); Result := not (ProcessID = LParam); if not Result then WindowHandle := AHandle; end;
function GetWindowHandleByExeName(const AExeName: string): THandle; var SnapShot: THandle; p: TProcessEntry32; ProcessHandle: THandle; begin Result := 0; WindowHandle := 0; ProcessHandle := 0; p.dwSize := SizeOf(p); SnapShot := CreateToolhelp32Snapshot(TH32CS_SnapProcess, 0); try if Process32First(SnapShot, p) then repeat if AnsiLowerCase(AExeName) = AnsiLowerCase(p.szExeFile) then ProcessHandle := p.th32ProcessID; until (ProcessHandle <> 0) or not Process32Next(SnapShot, p); EnumWindows(@MyEnumWindowProc, ProcessHandle); Result := WindowHandle; finally CloseHandle(SnapShot); end; end;
procedure TForm1.Button2Click(Sender: TObject); var m_exe:string; begin m_exe := Edit1.Text; GetWindowHandleByExeName(m_exe);
end;
procedure TForm1.Button1Click(Sender: TObject);
begin h:=WindowHandle; postmessage(h,WM_SYSCOMMAND,SC_MINIMIZE,0);
end;
end. |
Im DAteianhang habe ich noch ein Bild wie es ausschaut.
Vielleicht kann mir ja jemand helfen, danke. =)