Autor Beitrag
mjeheuer
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 30



BeitragVerfasst: So 28.01.07 16:58 
Hallo zusammen

Ich habe in der Vergangenheit immer wieder die Funktion WinExecAndWait_32 benutzt um aus Delphi heraus externe Programme zu starten. Das funktioniert auch fehlerfrei.
Was mir jetzt zum ersten mal auffällt ist, das es mir nicht gelingt ein PDF-File zu öffnen. Ich bin immer davon ausgegangen das wenn ich das PDF-File übergebe, der Acropbat Reader automatisch startet und das PDF-File dann anzeigt.
Hier passiert aber garnichts. Keine Fehlermeldung, kein PDF-File.
Habe ich da falsch gedacht, oder mache ich einen Fehler?
Wie kann ich, ohne den Pfad zum Acrobat Reader zu kennen, das PDF-File mit der Funktion öffnen?

Ich rufe die Funktion wie folgt auf: WinExecAndWait_32('Hilfe.pdf',1,false);
wobei die Hilfe.pdf im gleichen Verzeichnis ist wie mein Delphi-Programm.

Gruß
Michael



ausblenden volle Höhe Delphi-Quelltext
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:
function WinExecAndWait_32(FileName: string; Visibility: Integer; bWait: Boolean = False): Longword;
var { by Pat Ritchey }
  zAppName: array[0..512of Char;
  zCurDir: array[0..255of Char;
  WorkDir: string;
  StartupInfo: TStartupInfo;
  ProcessInfo: TProcessInformation;
begin
  StrPCopy(zAppName, FileName);
  GetDir(0, WorkDir);
  StrPCopy(zCurDir, WorkDir);
  FillChar(StartupInfo, SizeOf(StartupInfo), #0);
  StartupInfo.cb := SizeOf(StartupInfo);
  StartupInfo.dwFlags := STARTF_USESHOWWINDOW;
  StartupInfo.wShowWindow := Visibility;
  if not CreateProcess(nil,
    zAppName, // pointer to command line string
    nil// pointer to process security attributes
    nil// pointer to thread security attributes
    False, // handle inheritance flag
    CREATE_NEW_CONSOLE or // creation flags
    NORMAL_PRIORITY_CLASS,
    nil//pointer to new environment block
    nil// pointer to current directory name
    StartupInfo, // pointer to STARTUPINFO
    ProcessInfo) // pointer to PROCESS_INF
    then Result := WAIT_FAILED
  else
  begin
    if bWait then
      WaitForSingleObject(ProcessInfo.hProcess, INFINITE);
    GetExitCodeProcess(ProcessInfo.hProcess, Result);
    CloseHandle(ProcessInfo.hProcess);
    CloseHandle(ProcessInfo.hThread);
  end;
end{ WinExecAndWait32 }
Roadrunner116
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 89

Win XP Home, Ubuntu Linux 6.06
Delphi 7, Java, PHP
BeitragVerfasst: So 28.01.07 21:01 
hab d anicht so viel Ahnung von, aber ich öffne HTML-Seiten mit shellexecute, müsste mit pdf auch gehen!

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
if ShellExecute(Application.Handle,
                 'open',
                 PChar({Dateipfad+Name}),
                 NilNil, SW_NORMAL) <= 32 then
    ShowMessage('Es ist ein Fehler aufgetreten');


Gruß Jonas
mjeheuer Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 30



BeitragVerfasst: Mo 29.01.07 10:22 
user profile iconRoadrunner116 hat folgendes geschrieben:
hab d anicht so viel Ahnung von, aber ich öffne HTML-Seiten mit shellexecute, müsste mit pdf auch gehen!

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
if ShellExecute(Application.Handle,
                 'open',
                 PChar({Dateipfad+Name}),
                 NilNil, SW_NORMAL) <= 32 then
    ShowMessage('Es ist ein Fehler aufgetreten');


Gruß Jonas


Hallo Jonas

Danke für den Tip. Das funktioniert tatsächlich auch bei PDF-Dateien.
Trotzdem Schade das es scheinbar nicht mit der WinExecAndWait_32 funktioniert da ich die ohnehin schon in meinem Programm habe.

Gruß
Michael
ssb-blume
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 375
Erhaltene Danke: 7

XP, W7, W8
Deutschland
BeitragVerfasst: Sa 03.02.07 12:45 
Muesste auch funzen, wenn im Betriebssystem die Dateierweiterung .pdf auf den Reader angemeldet ist.
Aber ich weiss nicht wie, kenne das nur bei NORTON, da gibst sowas..

Andererseits geht aber auch die Funktion

CreateProcess aus der API, siehe mal in der Hilfe nach, wie die Parameter aussehen.

Ein Beispiel fuer die Verwendung findest Du in meiner Unit hier im Forum:

[Delphi, Win32] Unit für allgem. Dateibehandlung

_________________
Brain: an apparatus with which we think we think.