Einzelnen Beitrag anzeigen

hathor
(Gast)

n/a Beiträge
 
#2

AW: Zwei Windows Explorer starten und nebeneinander bildschirmfüllend positionieren

  Alt 23. Jun 2015, 10:22
Anmerkungen:

Jedem Window ein eigenes Handle.
SetWindowPos ist überflüssig.
Ohne Sleep geht es bei mir nicht.
DirectoryExists immer anwenden.
WINDOWS ist - wie üblich - verwirrend:
Pfadname: C:\Users\HATHOR\Documents
Window-Title: Dokumente

Delphi-Quellcode:
   Var hwnd_Explorer1, hwnd_Explorer2 : HWND;

   If DirectoryExists('C:\Users\HATHOR\Documents') then
   BEGIN
     ShellExecute(Form1.Handle, Nil, PChar('C:\Users\HATHOR\Documents'), Nil, Nil, SW_SHOW);
        Application.ProcessMessages; Sleep(500);
     hwnd_Explorer1 := FindWindow(Nil, 'Dokumente');
     MoveWindow(hwnd_Explorer1, 0, 0, (Screen.Width div 2), Screen.WorkAreaHeight, True);
// SetWindowPos(hwnd_Explorer1, HWND_NOTOPMOST,0,0,0,0, SWP_NOSIZE);
   END;
//
   If DirectoryExists('F:\TOOLS') then
   BEGIN
     ShellExecute(Form1.Handle, Nil, PChar('F:\TOOLS'), Nil, Nil, SW_SHOW);
        Application.ProcessMessages; Sleep(500);
     hwnd_Explorer2 := FindWindow(Nil, 'F:\TOOLS');
     MoveWindow(hwnd_Explorer2, (Screen.Width div 2), 0, (Screen.Width div 2), Screen.WorkAreaHeight, True);
// SetWindowPos(hwnd_Explorer2, HWND_NOTOPMOST,0,0,0,0, SWP_NOSIZE);
   END;
Das ganze lässt sich vereinfachen - mehr braucht man nicht, wenn das Programm sonst nichts tut:
Delphi-Quellcode:
procedure TForm1.FormCreate(Sender: TObject);
Var hwnd_Explorer1, hwnd_Explorer2 : HWND;
begin
   If DirectoryExists('C:\Users\HATHOR\Documents') then
   BEGIN
     ShellExecute(Form1.Handle, Nil, PChar('C:\Users\HATHOR\Documents'), Nil, Nil, SW_SHOW);
        Application.ProcessMessages; Sleep(500);
     hwnd_Explorer1 := FindWindow(Nil, 'Dokumente');
     MoveWindow(hwnd_Explorer1, 0, 0, (Screen.Width div 2), Screen.WorkAreaHeight, True);
   END;
   If DirectoryExists('F:\TOOLS') then
   BEGIN
     ShellExecute(Form1.Handle, Nil, PChar('F:\TOOLS'), Nil, Nil, SW_SHOW);
        Application.ProcessMessages; Sleep(500);
     hwnd_Explorer2 := FindWindow(Nil, 'F:\TOOLS');
     MoveWindow(hwnd_Explorer2, (Screen.Width div 2), 0, (Screen.Width div 2), Screen.WorkAreaHeight, True);
   END;
Application.Terminate;
end;

Geändert von hathor (23. Jun 2015 um 14:05 Uhr)
  Mit Zitat antworten Zitat