]> icculus.org git repositories - taylor/freespace2.git/blob - src/platform/win.cpp
log out of tracker when mission ends (non-standalone)
[taylor/freespace2.git] / src / platform / win.cpp
1 /*
2  * Copyright (C) Volition, Inc. 1999.  All rights reserved.
3  *
4  * All source code herein is the property of Volition, Inc. You may not sell
5  * or otherwise commercially exploit the source or things you created based on
6  * the source.
7  */
8
9 #ifndef PLAT_UNIX
10
11 #define WIN32_LEAN_AND_MEAN
12 #include <windows.h>
13 #include <shellapi.h>
14
15 #include "SDL.h"
16 #include "osapi.h"
17
18
19 int platform_open_url(const char *url)
20 {
21         char s_url[256];
22
23         // make sure it's a valid www address
24         if ( !SDL_strncasecmp(url, "http://", 7) || !SDL_strncasecmp(url, "https://", 8) ) {
25                 SDL_strlcpy(s_url, url, SDL_arraysize(s_url));
26         } else {
27                 SDL_strlcpy(s_url, "http://", SDL_arraysize(s_url));
28                 SDL_strlcat(s_url, url, SDL_arraysize(s_url));
29         }
30
31         int rval = (int) ShellExecute(NULL, (LPCTSTR)"open", (LPCTSTR)s_url, NULL, NULL, SW_SHOW);
32
33         if (rval < 32) {
34                 switch (rval) {
35                         case 0:
36                         case ERROR_BAD_FORMAT:
37                         case SE_ERR_ACCESSDENIED:
38                         case SE_ERR_ASSOCINCOMPLETE:
39                         case SE_ERR_DDEBUSY:
40                         case SE_ERR_DDEFAIL:
41                         case SE_ERR_DDETIMEOUT:
42                         case SE_ERR_DLLNOTFOUND:
43                         case SE_ERR_OOM:
44                         case SE_ERR_SHARE:
45                         case SE_ERR_NOASSOC:
46                         case ERROR_FILE_NOT_FOUND:
47                         case ERROR_PATH_NOT_FOUND:
48                                 return -1;
49                 }
50         }
51
52         return 0;
53 }
54
55 static HHOOK winHook;
56 static unsigned int win_KMOD = 0;
57
58 LRESULT CALLBACK winkeyEater(int nCode, WPARAM wParam, LPARAM lParam)
59 {
60         if ( (nCode < 0) || (nCode != HC_ACTION) ) {
61                 return CallNextHookEx(winHook, nCode, wParam, lParam);
62         }
63
64         bool eat_key = false;
65         KBDLLHOOKSTRUCT *p = (KBDLLHOOKSTRUCT *)lParam;
66
67         switch (wParam) {
68                 case WM_KEYDOWN:
69                 case WM_KEYUP: {
70                         eat_key = (os_foreground() && ((p->vkCode == VK_LWIN) || (p->vkCode == VK_RWIN)));
71                         break;
72                 }
73
74                 default:
75                         break;
76         }
77
78         if (eat_key) {
79                 win_KMOD = (wParam == WM_KEYDOWN) ? KMOD_GUI : 0;
80                 return 1;
81         } else {
82                 return CallNextHookEx(winHook, nCode, wParam, lParam);
83         }
84 }
85
86 unsigned int platform_get_kmod()
87 {
88         return win_KMOD;
89 }
90
91 void platform_init()
92 {
93         // eat WIN/GUI key so that the OS doesn't mess us up
94         winHook = SetWindowsHookEx(WH_KEYBOARD_LL, winkeyEater, GetModuleHandle(NULL), 0);
95 }
96
97 void platform_close()
98 {
99         UnhookWindowsHookEx(winHook);
100 }
101
102 #endif