1 | /* |
---|
2 | * Starts a browser with a given URL. |
---|
3 | * by Eugene Romanenko |
---|
4 | * |
---|
5 | * This code is in the public domain and has no copyright. |
---|
6 | */ |
---|
7 | |
---|
8 | #define INCL_DOS |
---|
9 | #define INCL_WIN |
---|
10 | #include <os2.h> |
---|
11 | |
---|
12 | #include <string.h> |
---|
13 | |
---|
14 | |
---|
15 | static char browserExe[ CCHMAXPATH ] = ""; |
---|
16 | static char browserDir[ CCHMAXPATH ] = ""; |
---|
17 | |
---|
18 | static void detectBrowser(); |
---|
19 | |
---|
20 | // Starts the browser, returns 1 if started, 0 otherwise. |
---|
21 | int startBrowser( const char *url ) |
---|
22 | { |
---|
23 | PROGDETAILS pd; |
---|
24 | HAPP happ = NULL; |
---|
25 | |
---|
26 | if ( url == NULL ) { |
---|
27 | return 0; |
---|
28 | } |
---|
29 | |
---|
30 | if ( browserExe[0] == 0 ) { |
---|
31 | detectBrowser(); |
---|
32 | } |
---|
33 | |
---|
34 | if ( browserExe[0] == 0 ) { |
---|
35 | return 0; |
---|
36 | } |
---|
37 | |
---|
38 | pd.Length = sizeof( PROGDETAILS ); |
---|
39 | pd.progt.progc = PROG_DEFAULT; |
---|
40 | pd.progt.fbVisible = SHE_VISIBLE; |
---|
41 | pd.pszTitle = NULL; |
---|
42 | pd.pszExecutable = browserExe; |
---|
43 | pd.pszParameters = NULL; |
---|
44 | pd.pszStartupDir = ( browserDir[0] == 0 ) ? NULL : browserDir; |
---|
45 | pd.pszIcon = NULL; |
---|
46 | pd.pszEnvironment = NULL; |
---|
47 | pd.swpInitial.fl = SWP_ACTIVATE; |
---|
48 | pd.swpInitial.cy = 0; |
---|
49 | pd.swpInitial.cx = 0; |
---|
50 | pd.swpInitial.y = 0; |
---|
51 | pd.swpInitial.x = 0; |
---|
52 | pd.swpInitial.hwndInsertBehind = HWND_TOP; |
---|
53 | pd.swpInitial.hwnd = NULLHANDLE; |
---|
54 | pd.swpInitial.ulReserved1 = 0; |
---|
55 | pd.swpInitial.ulReserved2 = 0; |
---|
56 | happ = WinStartApp( NULLHANDLE, &pd, url, NULL, 0 ); |
---|
57 | return ( happ != NULL ); |
---|
58 | } |
---|
59 | |
---|
60 | static void detectBrowser() |
---|
61 | { |
---|
62 | char *prfApp = "WPURLDEFAULTSETTINGS"; |
---|
63 | |
---|
64 | if ( browserExe[0] == 0 ) |
---|
65 | { |
---|
66 | PrfQueryProfileString( HINI_USER, prfApp, "DefaultBrowserExe", "", |
---|
67 | browserExe, CCHMAXPATH ); |
---|
68 | PrfQueryProfileString( HINI_USER, prfApp, "DefaultWorkingDir", "", |
---|
69 | browserDir, CCHMAXPATH ); |
---|
70 | } |
---|
71 | |
---|
72 | if ( browserExe[0] == 0 ) |
---|
73 | { |
---|
74 | APIRET rc; |
---|
75 | rc = DosSearchPath( SEARCH_CUR_DIRECTORY | SEARCH_ENVIRONMENT | SEARCH_IGNORENETERRS, |
---|
76 | "PATH", "NETSCAPE.EXE", browserExe, CCHMAXPATH ); |
---|
77 | if ( rc != 0 ) { |
---|
78 | strcpy( browserExe , "" ); |
---|
79 | } |
---|
80 | } |
---|
81 | } |
---|
82 | |
---|
83 | |
---|