Exe Dateien ausführen

rigo

Grünschnabel
Wie kann ich einem Button in Delphie 7 sagen, dass er eine andere .exe Datei ausführt wenn man ihn drückt?
 
Okay, über Hilfe im Menü hab ich es auch nicht gefunden, aber über F1, während der Cursor in diesem Wort steht (weiß nicht, wie man das umschreiben soll...)

The ShellExecute function opens or prints a specified file. The file can be an executable file or a document file. See ShellExecuteEx also.

HINSTANCE ShellExecute(

HWND hwnd, // handle to parent window
LPCTSTR lpOperation, // pointer to string that specifies operation to perform
LPCTSTR lpFile, // pointer to filename or folder name string
LPCTSTR lpParameters, // pointer to string that specifies executable-file parameters
LPCTSTR lpDirectory, // pointer to string that specifies default directory
INT nShowCmd // whether file is shown when opened
);

Hoffe, es hilft...

Hellie
 
Irgendwie check ich das nicht...
Kannst du mir das mal an einem Beispiel zeigen, in dem du einfach mal ein Programm einrägst, dass man damit startet?
 
Also...

Als erstes brauchst du ein Handle, da kannst du form1.handle schreiben, dann das, was du machen willst, "open" in diesem Fall, dann die Datei (muss imo erst in PChar umgewandelt werden), dann bestimmte Parameter, mit denen das Programm geöffnet werden soll (nil), dann weiß ich leider nicht, was da hin soll :-( , und danach ein Parameter, wie das Programm geöffnet werden soll (im Normalfall sw_show)

Um zum Beispiel Notepad zu öffnen lautet der Befehl so:

shellexecute(form1.Handle, 'open', PChar('C:\Windows\notepad.exe'), nil, nil, sw_show);

Andere Arten, das Programm zu öffnen:

SW_HIDE Hides the window and activates another window.
SW_MAXIMIZE Maximizes the specified window.
SW_MINIMIZE Minimizes the specified window and activates the next top-level window in the Z order.
SW_RESTORE Activates and displays the window. If the window is minimized or maximized, Windows restores it to its original size and position. An application should specify this flag when restoring a minimized window.
SW_SHOW Activates the window and displays it in its current size and position.
SW_SHOWDEFAULT Sets the show state based on the SW_ flag specified in the STARTUPINFO structure passed to the CreateProcess function by the program that started the application. An application should call ShowWindow with this flag to set the initial show state of its main window.
SW_SHOWMAXIMIZED Activates the window and displays it as a maximized window.
SW_SHOWMINIMIZED Activates the window and displays it as a minimized window.
SW_SHOWMINNOACTIVE Displays the window as a minimized window. The active window remains active.
SW_SHOWNA Displays the window in its current state. The active window remains active.
SW_SHOWNOACTIVATE Displays a window in its most recent size and position. The active window remains active.
SW_SHOWNORMAL Activates and displays a window. If the window is minimized or maximized, Windows restores it to its original size and position. An application should specify this flag when displaying the window for the first time.

Hellie
 
Habs schon woanders gefunden, und da gehts anders. Und es funktioniert:

uses
ShellAPI

(...)

procedure TForm1.Button2Click(Sender: TObject);
begin
ShellExecute(Application.Handle, 'open', 'c:\blabla.exe', nil, nil, SW_SHOW);
application.terminate;
end;
 
Und jetzt gleich die 2te Frage:

Wie kann ich ein iframe in mein Programm machen? (bitte testen, bevor man postet ^^)
 
Was geht da anders? Lediglich ist das Handle nicht das von Form1 sondern von der Application und es wird eine andere Datei geöffnet.
Und application.terminate gehört da schon gar nicht mehr dazu, das macht etwas ganz anderes...

Na gut, ShellAPI, das hat bei mir gefehlt, das stimmt, bindest du das ein, klappt mein Code genauso.

Du hast sicher mitbekommen, dass ich es vermeiden wollte, einen fertigen Code ohne Erklärung zu tippen, damit du nur noch kopieren und einfügen musst. Denn eine Programmiersprache lernen, heißt nicht copy'n'paste, sondern verstehen.

Aber was in aller Welt ist ein iFrame?

Helli
 
Original geschrieben von Hellie
Aber was in aller Welt ist ein iFrame?
Nichts was in irgendeiner Weise mit einer Applikation zu tun hätte, es sei denn er schreib eine HTML Rendering Engine.
Original geschrieben von rigo
[...]? (bitte testen, bevor man postet ^^)
Die Hilfe von Hellie hatte nur den Fehler, dass die ShellAPI nicht erwähnt wurde. Also bitte etwas weniger fordernd. Man sollte erwarten können, dass schon das Stichwort ShellExecute reicht. Schließlich hast du ja dann auch das Beispiel inklusive ShellAPI gefunden. Wo liegt also das Problem? Gehst du davon aus, hier einen Anspruch auf kopierbereiten Code zu haben?

Was dein "iFrame" Problem angeht, gehe ich mal davon aus, dass du eine Webseite in einem Programm darstellen willst. Dazu gibt's unter dem Reiter "Internet" der VCL die WebBrowser Komponente. Die packst du auf dein Formular. Um jetzt beim Erzeugen des Formulars eine URL anzuzeigen, fügst du folgende Zeile in das OnCreate Ereignis deines Formulars ein:
Code:
WebBrowser1.Navigate('http://tutorials.de/');
Sollte die Komponente nicht vorhanden sein (weiß nicht ab welcher Edition die dabei ist), schau dir die Seite an, um das entsprechende ActiveX Control des IE einzubinden: http://www.cryer.co.uk/brian/delphi/howto_install_twebbrowser.htm .

Das sollte bei weitem reichen, das Problem zu lösen.

Peter
 

Neue Beiträge

Zurück