Autor Beitrag
TheUnknown
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 334



BeitragVerfasst: Sa 06.10.07 12:29 
Hi!

Ich möchte ein Programm schreiben (mit GUI). Das Programm kann über TOpenDialog EXE auswählen. Und wenn die EXE-Datei von meinem Programm ausgewählt wurde, soll mein Programm sagen, ob diese EXE-Datei eine Textbildschirmanwendung (sozusagen nur auf der "DOS-Ebene" arbeitet ist, oder eines, das ein GUI (also TForm, TLabels, blabla) besitzt.

Wichtig ist mir dabei, nicht nur blanke DOS-Programme zu erkennen, sondern auch "Windows-Programme", die soz. den "DOS-Box-Style" haben.

Gibt's da eine Methode? Ich habe mir schon die Hacken nach Infos abgesucht, aber nichts gefunden!
BenBE
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 8721
Erhaltene Danke: 191

Win95, Win98SE, Win2K, WinXP
D1S, D3S, D4S, D5E, D6E, D7E, D9PE, D10E, D12P, DXEP, L0.9\FPC2.0
BeitragVerfasst: Sa 06.10.07 12:55 
Im Einfachsten Fall könntest Du schauen, welches Anwendungs-Subsystem im EXE-Header angegeben ist.

Alternativ könntest Du schauen, ob AllocateConsoleWindow importiert wird.

_________________
Anyone who is capable of being elected president should on no account be allowed to do the job.
Ich code EdgeMonkey - In dubio pro Setting.
TheUnknown Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 334



BeitragVerfasst: Sa 06.10.07 12:56 
user profile iconBenBE hat folgendes geschrieben:
Im Einfachsten Fall könntest Du schauen, welches Anwendungs-Subsystem im EXE-Header angegeben ist.

Alternativ könntest Du schauen, ob AllocateConsoleWindow importiert wird.


Ja, dass in der Datei selbst so eine Info steht, dachte ich mir, aber ich weiss nicht, wie ich sie abrufe.
BenBE
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 8721
Erhaltene Danke: 191

Win95, Win98SE, Win2K, WinXP
D1S, D3S, D4S, D5E, D6E, D7E, D9PE, D10E, D12P, DXEP, L0.9\FPC2.0
BeitragVerfasst: Sa 06.10.07 12:58 
Schau Dir einfach mal TUFKAPLs Delphi-Crashkurs an. Der sollte schon ein paar Fragen beantworten.

Ferner kann ich nur das Lesen des MSDNs in Bezug auf die EXE-Header empfehlen ;-)

_________________
Anyone who is capable of being elected president should on no account be allowed to do the job.
Ich code EdgeMonkey - In dubio pro Setting.
TheUnknown Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 334



BeitragVerfasst: Sa 06.10.07 19:03 
Also ehrlich gesagt, komm ich mit Euren Vorschlägen nicht klar. Ich bastel wie wild, aber es klappt nicht und so langsam fehlt mir der Nerv, das weiter zu probieren...

Gibt's denn keine 10-bis-30-Zeilen-Prozedur, die man auf die Schnelle dafür basteln könnte? Oder vll sogar eine fertig API-Funktion?
hathor
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: Sa 06.10.07 22:06 
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:
procedure TMainForm.Button1Click(Sender: TObject);
var
  FI: TSHFileInfo;
  ExeType: DWord;
const
  MZ = $5A4D; //"MZ"
  NE = $504E; //"NE"
  PE = $4550; //"PE"
begin
  if dlgOpen.Execute then
  begin
    //Get display name and type description
    SHGetFileInfo(PChar(dlgOpen.FileName), 0, FI, SizeOf(FI),
      SHGFI_DISPLAYNAME or SHGFI_TYPENAME);
    lblDisplayName.Caption := FI.szDisplayName;
    lblFileType.Caption := FI.szTypeName;

    //Get EXE type
    ExeType := SHGetFileInfo(PChar(dlgOpen.FileName), 0, FI, SizeOf(FI),
      SHGFI_EXETYPE);
    if ExeType = MZ then
      lblExeType.Caption := 'MS-DOS .EXE, .COM or .BAT file'
    else
    if ExeType = PE then
      lblExeType.Caption := 'Win32 console application'
    else
    if ((LoWord(ExeType) = NE) or
        (LoWord(ExeType) = PE)) and
       ((HiWord(ExeType) = $0300) or
        (HiWord(ExeType) = $0350) or
        (HiWord(ExeType) = $0400)) then
      lblExeType.Caption := 'Windows application'
    else
      lblExeType.Caption := 'Not an executable file';
  end
end;
Einloggen, um Attachments anzusehen!
hathor
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: Sa 06.10.07 23:34 
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:
37:
38:
39:
40:
41:
function exetype(fn:pathstr):TExeType;
var f       : file;
    magic   : array[0..1] of char;
    hdadr   : longint;
    version : byte;
begin
  assign(f,fn);
  resetfm(f,FMDenyWrite);
  blockread(f,magic,2);
  seek(f,60);
  blockread(f,hdadr,4);
  if (ioresult<>0) or (magic<>'MZ') then
    exetype:=ET_Unknown
  else if odd(hdadr) then
    exetype:=ET_DOS
  else
  begin { MK 01/00 Fix f�r LZEXE gepackte Dateien }
    if (hdadr > 0) and (hdadr < FileSize(f)-54) then
    begin
      seek(f,hdadr);
      blockread(f,magic,2);
      if ioresult<>0 then
        exetype:=ET_DOS
      else if magic='PE' then
        exetype:=ET_Win32
      else if magic='LX' then
        exetype:=ET_OS2_32
      else if magic<>'NE' then
        exetype:=ET_DOS
      else begin
        seek(f,hdadr+54);
        blockread(f,version,1);
        if version=2 then exetype:=ET_Win16
        else exetype:=ET_OS2_16;
        end;
    end else
      exetype := ET_DOS;
  end;
  close(f);
  if ioresult<>0 then;
end;
TheUnknown Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 334



BeitragVerfasst: So 07.10.07 08:30 
user profile iconhathor hat folgendes geschrieben:
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:
procedure TMainForm.Button1Click(Sender: TObject);
var
  FI: TSHFileInfo;
  ExeType: DWord;
const
  MZ = $5A4D; //"MZ"
  NE = $504E; //"NE"
  PE = $4550; //"PE"
begin
  if dlgOpen.Execute then
  begin
    //Get display name and type description
    SHGetFileInfo(PChar(dlgOpen.FileName), 0, FI, SizeOf(FI),
      SHGFI_DISPLAYNAME or SHGFI_TYPENAME);
    lblDisplayName.Caption := FI.szDisplayName;
    lblFileType.Caption := FI.szTypeName;

    //Get EXE type
    ExeType := SHGetFileInfo(PChar(dlgOpen.FileName), 0, FI, SizeOf(FI),
      SHGFI_EXETYPE);
    if ExeType = MZ then
      lblExeType.Caption := 'MS-DOS .EXE, .COM or .BAT file'
    else
    if ExeType = PE then
      lblExeType.Caption := 'Win32 console application'
    else
    if ((LoWord(ExeType) = NE) or
        (LoWord(ExeType) = PE)) and
       ((HiWord(ExeType) = $0300) or
        (HiWord(ExeType) = $0350) or
        (HiWord(ExeType) = $0400)) then
      lblExeType.Caption := 'Windows application'
    else
      lblExeType.Caption := 'Not an executable file';
  end
end;


Dankeschön! Genau DAS ist es, was ich brauchte! VIELEN DANK!
Dieses Thema ist gesperrt, Du kannst keine Beiträge editieren oder beantworten.

Das Thema wurde von einem Team-Mitglied geschlossen. Wenn du mit der Schließung des Themas nicht einverstanden bist, kontaktiere bitte das Team.