Debian Codegraph @

src/services/castleopendocument_shellexecute.inc

raw
1 {%MainUnit castleopendocument.pas}
2 {
3 Copyright 2012-2024 Michalis Kamburelis and Lazarus developers.
4
5 This file is part of "Castle Game Engine".
6
7 "Castle Game Engine" is free software; see the file COPYING.txt,
8 included in this distribution, for details about the copyright.
9 Parts of this file are based on Lazarus LCL code, which has
10 exactly the same license as our "Castle Game Engine":
11 LGPL with static linking exception, see COPYING.txt for details.
12
13 "Castle Game Engine" is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16
17 ----------------------------------------------------------------------------
18 }
19
20 { OpenUrl and OpenDocument implementations for Windows, using ShellExecute. }
21
22 {$ifdef read_uses}
23 Windows,
24 {$ifndef FPC} ShellApi, {$endif}
25 {$endif}
26
27 {$ifdef read_implementation}
28
29 { Based on Lazarus LCL: lcl/include/sysenvapis_win.inc }
30
31 function OpenUrl(AUrl: String): Boolean;
32 var
33 {$IFDEF WinCE}
34 Info: SHELLEXECUTEINFO;
35 {$ELSE}
36 ws: WideString;
37 ans: AnsiString;
38 {$ENDIF}
39 begin
40 Result := False;
41 if AUrl = '' then Exit;
42
43 {$IFDEF WinCE}
44 FillChar(Info, SizeOf(Info), 0);
45 Info.cbSize := SizeOf(Info);
46 Info.fMask := SEE_MASK_FLAG_NO_UI;
47 Info.lpVerb := 'open';
48 Info.lpFile := PWideChar(UTF8Decode(AUrl));
49 Result := ShellExecuteEx(@Info);
50 {$ELSE}
51 if Win32Platform = VER_PLATFORM_WIN32_NT then
52 begin
53 {$ifdef FPC}
54 ws := UTF8Decode(AUrl);
55 {$else}
56 ws := AUrl;
57 {$endif}
58 Result := ShellExecuteW(0, 'open', PWideChar(ws), nil, nil, SW_SHOWNORMAL) > 32;
59 end
60 else
61 begin
62 {$ifdef FPC}
63 ans := Utf8ToAnsi(AUrl); // utf8 must be converted to Windows Ansi-codepage
64 {$else}
65 ans := AnsiString(AUrl);
66 {$endif}
67 Result := ShellExecuteA(0, 'open', PAnsiChar(ans), nil, nil, SW_SHOWNORMAL) > 32;
68 end;
69 {$ENDIF}
70 end;
71
72 // Open a document with the default application associated with it in the system
73 function OpenDocument(APath: String): Boolean;
74 begin
75 Result := OpenUrl(APath);
76 end;
77
78 {$endif read_implementation}