win32.cpp 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437
  1. /* -*- mode: c; tab-width: 4; c-basic-offset: 4; c-file-style: "linux" -*- */
  2. //
  3. // Copyright (c) 2009-2011, Wei Mingzhi <whistler_wmz@users.sf.net>.
  4. // Copyright (c) 2011-2017, SDLPAL development team.
  5. // All rights reserved.
  6. //
  7. // This file is part of SDLPAL.
  8. //
  9. // SDLPAL is free software: you can redistribute it and/or modify
  10. // it under the terms of the GNU General Public License as published by
  11. // the Free Software Foundation, either version 3 of the License, or
  12. // (at your option) any later version.
  13. //
  14. // This program is distributed in the hope that it will be useful,
  15. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. // GNU General Public License for more details.
  18. //
  19. // You should have received a copy of the GNU General Public License
  20. // along with this program. If not, see <http://www.gnu.org/licenses/>.
  21. //
  22. // win32.cpp: WIN32-specific codes.
  23. // @Author: Lou Yihua <louyihua@21cn.com>, 2016.
  24. //
  25. #define UNICODE
  26. #define _UNICODE
  27. #define _CRT_SECURE_NO_WARNINGS
  28. #include <tchar.h>
  29. #include <windows.h>
  30. #include <commctrl.h>
  31. #include <shlobj.h>
  32. #include <string>
  33. #include "resource.h"
  34. #include "../global.h"
  35. #include "../util.h"
  36. #include "../palcfg.h"
  37. #include "../resampler.h"
  38. PAL_C_LINKAGE char* stoupper(char* s)
  39. {
  40. char* p = strdup(s);
  41. while (*p = toupper(*p)) p++;
  42. return s;
  43. }
  44. #define ComboBox_AddString(hwndDlg, idCtrl, lpsz) \
  45. (BOOL)SNDMSG(GetDlgItem((hwndDlg), (idCtrl)), CB_ADDSTRING, (WPARAM)(0), (LPARAM)(lpsz))
  46. #define ComboBox_SetCurSel(hwndDlg, idCtrl, index) \
  47. (BOOL)SNDMSG(GetDlgItem((hwndDlg), (idCtrl)), CB_SETCURSEL, (WPARAM)(index), (LPARAM)(0))
  48. #define ComboBox_GetCurSel(hwndDlg, idCtrl) \
  49. (int)SNDMSG(GetDlgItem((hwndDlg), (idCtrl)), CB_GETCURSEL, (WPARAM)(0), (LPARAM)(0))
  50. #define TrackBar_SetRange(hwndDlg, idCtrl, min, max, redraw) \
  51. (BOOL)SNDMSG(GetDlgItem((hwndDlg), (idCtrl)), TBM_SETRANGE, (WPARAM)(redraw), (LPARAM)(MAKELONG((min), (max))))
  52. #define TrackBar_SetPos(hwndDlg, idCtrl, pos, redraw) \
  53. (BOOL)SNDMSG(GetDlgItem((hwndDlg), (idCtrl)), TBM_SETPOS, (WPARAM)(redraw), (LPARAM)(pos))
  54. #define TrackBar_GetPos(hwndDlg, idCtrl) \
  55. (int)SNDMSG(GetDlgItem((hwndDlg), (idCtrl)), TBM_GETPOS, (WPARAM)(0), (LPARAM)(0))
  56. #define EnableDlgItem(hwnd, nIDControl, bEnable) \
  57. EnableWindow(GetDlgItem((hwnd), (nIDControl)), (bEnable))
  58. HINSTANCE g_hInstance;
  59. WORD g_wLanguage;
  60. int WINAPI LoadStringEx(
  61. HINSTANCE hInstance,
  62. UINT uID,
  63. LANGID wLang,
  64. LPTSTR lpBuffer,
  65. int nBufferMax
  66. )
  67. {
  68. auto hrc = FindResourceEx(hInstance, RT_STRING, MAKEINTRESOURCE((uID >> 4) + 1), wLang);
  69. if (nullptr == hrc) return 0;
  70. auto begin = (LPCWSTR)LockResource(LoadResource(hInstance, hrc));
  71. for (int idx = 0; idx < (int)(uID & 0xf); idx++)
  72. begin += *begin + 1;
  73. if (nBufferMax == 0)
  74. {
  75. *((LPCWSTR*)lpBuffer) = begin;
  76. return sizeof(LPCWSTR);
  77. }
  78. else
  79. {
  80. wcsncpy(lpBuffer, begin + 1, min(nBufferMax, *begin));
  81. if (nBufferMax <= *begin)
  82. {
  83. lpBuffer[nBufferMax - 1] = '\0';
  84. return nBufferMax - 1;
  85. }
  86. else
  87. {
  88. lpBuffer[*begin] = '\0';
  89. return *begin;
  90. }
  91. }
  92. }
  93. std::wstring LoadResourceString(UINT uID)
  94. {
  95. auto hrc = FindResourceEx(g_hInstance, RT_STRING, MAKEINTRESOURCE((uID >> 4) + 1), g_wLanguage);
  96. if (hrc)
  97. {
  98. auto begin = (LPCWSTR)LockResource(LoadResource(g_hInstance, hrc));
  99. for (int idx = 0; idx < (int)(uID & 0xf); idx++)
  100. begin += *begin + 1;
  101. return std::wstring(begin + 1, *begin);
  102. }
  103. return L"";
  104. }
  105. void SaveSettings(HWND hwndDlg, BOOL fWriteFile)
  106. {
  107. int textLen;
  108. if (IsDlgButtonChecked(hwndDlg, IDC_USEMSGFILE) && (textLen = GetWindowTextLengthA(GetDlgItem(hwndDlg, IDC_MSGFILE))) > 0)
  109. {
  110. gConfig.pszMsgFile = (char*)realloc(gConfig.pszMsgFile, textLen + 1);
  111. GetDlgItemTextA(hwndDlg, IDC_MSGFILE, gConfig.pszMsgFile, textLen + 1);
  112. }
  113. else
  114. {
  115. free(gConfig.pszMsgFile); gConfig.pszMsgFile = nullptr;
  116. }
  117. if (IsDlgButtonChecked(hwndDlg, IDC_USELOGFILE) && (textLen = GetWindowTextLengthA(GetDlgItem(hwndDlg, IDC_LOGFILE))) > 0)
  118. {
  119. gConfig.pszLogFile = (char*)realloc(gConfig.pszLogFile, textLen + 1);
  120. GetDlgItemTextA(hwndDlg, IDC_LOGFILE, gConfig.pszLogFile, textLen + 1);
  121. }
  122. else
  123. {
  124. free(gConfig.pszLogFile); gConfig.pszLogFile = nullptr;
  125. }
  126. if (IsDlgButtonChecked(hwndDlg, IDC_USEFONTFILE) && (textLen = GetWindowTextLengthA(GetDlgItem(hwndDlg, IDC_FONTFILE))) > 0)
  127. {
  128. gConfig.pszFontFile = (char*)realloc(gConfig.pszFontFile, textLen + 1);
  129. GetDlgItemTextA(hwndDlg, IDC_FONTFILE, gConfig.pszFontFile, textLen + 1);
  130. }
  131. else
  132. {
  133. free(gConfig.pszFontFile); gConfig.pszFontFile = nullptr;
  134. }
  135. if ((textLen = GetWindowTextLength(GetDlgItem(hwndDlg, IDC_GAMEPATH))) > 0)
  136. {
  137. gConfig.pszGamePath = (char*)realloc(gConfig.pszGamePath, textLen + 1);
  138. GetDlgItemTextA(hwndDlg, IDC_GAMEPATH, gConfig.pszGamePath, textLen + 1);
  139. }
  140. else
  141. {
  142. free(gConfig.pszGamePath); gConfig.pszGamePath = nullptr;
  143. }
  144. gConfig.fFullScreen = IsDlgButtonChecked(hwndDlg, IDC_FULLSCREEN);
  145. gConfig.fUseTouchOverlay = IsDlgButtonChecked(hwndDlg, IDC_TOUCHOVERLAY);
  146. gConfig.fEnableAviPlay = IsDlgButtonChecked(hwndDlg, IDC_ENABLEAVI);
  147. gConfig.fKeepAspectRatio = IsDlgButtonChecked(hwndDlg, IDC_ASPECTRATIO);
  148. gConfig.eCDType = (MUSICTYPE)(ComboBox_GetCurSel(hwndDlg, IDC_CD) + MUSIC_MP3);
  149. gConfig.eMusicType = (MUSICTYPE)ComboBox_GetCurSel(hwndDlg, IDC_BGM);
  150. gConfig.eOPLType = (OPLTYPE)(ComboBox_GetCurSel(hwndDlg, IDC_OPL));
  151. gConfig.iLogLevel = (LOGLEVEL)(ComboBox_GetCurSel(hwndDlg, IDC_LOGLEVEL));
  152. gConfig.iAudioChannels = IsDlgButtonChecked(hwndDlg, IDC_STEREO) ? 2 : 1;
  153. gConfig.iSampleRate = GetDlgItemInt(hwndDlg, IDC_SAMPLERATE, nullptr, FALSE);
  154. gConfig.wAudioBufferSize = GetDlgItemInt(hwndDlg, IDC_AUDIOBUFFER, nullptr, FALSE);
  155. gConfig.iMusicVolume = TrackBar_GetPos(hwndDlg, IDC_MUSICVOLUME);
  156. gConfig.iSoundVolume = TrackBar_GetPos(hwndDlg, IDC_SOUNDVOLUME);
  157. gConfig.iResampleQuality = TrackBar_GetPos(hwndDlg, IDC_QUALITY);
  158. if (gConfig.eMusicType == MUSIC_RIX)
  159. {
  160. gConfig.fUseSurroundOPL = IsDlgButtonChecked(hwndDlg, IDC_SURROUNDOPL);
  161. gConfig.iOPLSampleRate = GetDlgItemInt(hwndDlg, IDC_OPLSR, nullptr, FALSE);
  162. }
  163. if (fWriteFile) PAL_SaveConfig();
  164. }
  165. void ResetControls(HWND hwndDlg)
  166. {
  167. TCHAR buffer[100];
  168. EnableDlgItem(hwndDlg, IDC_OPL, gConfig.eMusicType == MUSIC_RIX);
  169. EnableDlgItem(hwndDlg, IDC_SURROUNDOPL, gConfig.eMusicType == MUSIC_RIX);
  170. EnableDlgItem(hwndDlg, IDC_OPLSR, gConfig.eMusicType == MUSIC_RIX);
  171. CheckDlgButton(hwndDlg, IDC_FULLSCREEN, gConfig.fFullScreen);
  172. CheckDlgButton(hwndDlg, IDC_TOUCHOVERLAY, gConfig.fUseTouchOverlay);
  173. CheckDlgButton(hwndDlg, IDC_ENABLEAVI, gConfig.fEnableAviPlay);
  174. CheckDlgButton(hwndDlg, IDC_ASPECTRATIO, gConfig.fKeepAspectRatio);
  175. CheckDlgButton(hwndDlg, IDC_SURROUNDOPL, gConfig.fUseSurroundOPL);
  176. CheckDlgButton(hwndDlg, IDC_STEREO, gConfig.iAudioChannels == 2);
  177. CheckDlgButton(hwndDlg, IDC_USEMSGFILE, gConfig.pszMsgFile != nullptr);
  178. EnableDlgItem(hwndDlg, IDC_BRMSG, gConfig.pszMsgFile != nullptr);
  179. CheckDlgButton(hwndDlg, IDC_USEFONTFILE, gConfig.pszFontFile != nullptr);
  180. EnableDlgItem(hwndDlg, IDC_BRFONT, gConfig.pszFontFile != nullptr);
  181. CheckDlgButton(hwndDlg, IDC_USELOGFILE, gConfig.pszLogFile != nullptr);
  182. EnableDlgItem(hwndDlg, IDC_BRLOG, gConfig.pszLogFile != nullptr);
  183. ComboBox_SetCurSel(hwndDlg, IDC_CD, gConfig.eCDType - MUSIC_MP3);
  184. ComboBox_SetCurSel(hwndDlg, IDC_BGM, gConfig.eMusicType);
  185. ComboBox_SetCurSel(hwndDlg, IDC_OPL, gConfig.eOPLType);
  186. ComboBox_SetCurSel(hwndDlg, IDC_LOGLEVEL, gConfig.iLogLevel);
  187. SetDlgItemText(hwndDlg, IDC_SAMPLERATE, _itot(gConfig.iSampleRate, buffer, 10));
  188. SetDlgItemText(hwndDlg, IDC_OPLSR, _itot(gConfig.iOPLSampleRate, buffer, 10));
  189. SetDlgItemText(hwndDlg, IDC_AUDIOBUFFER, _itot(gConfig.wAudioBufferSize, buffer, 10));
  190. if (gConfig.pszGamePath) SetDlgItemTextA(hwndDlg, IDC_GAMEPATH, gConfig.pszGamePath);
  191. if (gConfig.pszMsgFile) SetDlgItemTextA(hwndDlg, IDC_MSGFILE, gConfig.pszMsgFile);
  192. if (gConfig.pszFontFile) SetDlgItemTextA(hwndDlg, IDC_FONTFILE, gConfig.pszFontFile);
  193. if (gConfig.pszLogFile) SetDlgItemTextA(hwndDlg, IDC_LOGFILE, gConfig.pszLogFile);
  194. TrackBar_SetPos(hwndDlg, IDC_QUALITY, gConfig.iResampleQuality, TRUE);
  195. TrackBar_SetPos(hwndDlg, IDC_MUSICVOLUME, gConfig.iMusicVolume, TRUE);
  196. TrackBar_SetPos(hwndDlg, IDC_SOUNDVOLUME, gConfig.iSoundVolume, TRUE);
  197. }
  198. INT_PTR InitProc(HWND hwndDlg, HWND hwndCtrl, LPARAM lParam)
  199. {
  200. InitCommonControls();
  201. auto log_levels = LoadResourceString(IDC_LOGLEVEL);
  202. for (size_t pos = 0; pos != std::string::npos; )
  203. {
  204. std::wstring item;
  205. auto next = log_levels.find(L';', pos);
  206. if (next != std::string::npos)
  207. {
  208. item.assign(log_levels.c_str() + pos, next - pos);
  209. pos = next + 1;
  210. }
  211. else
  212. {
  213. item.assign(log_levels.c_str() + pos);
  214. pos = next;
  215. }
  216. if (item.length() > 0)
  217. {
  218. ComboBox_AddString(hwndDlg, IDC_LOGLEVEL, item.c_str());
  219. }
  220. }
  221. ComboBox_AddString(hwndDlg, IDC_CD, TEXT("MP3"));
  222. ComboBox_AddString(hwndDlg, IDC_CD, TEXT("OGG"));
  223. ComboBox_AddString(hwndDlg, IDC_BGM, TEXT("MIDI"));
  224. ComboBox_AddString(hwndDlg, IDC_BGM, TEXT("RIX"));
  225. ComboBox_AddString(hwndDlg, IDC_BGM, TEXT("MP3"));
  226. ComboBox_AddString(hwndDlg, IDC_BGM, TEXT("OGG"));
  227. ComboBox_AddString(hwndDlg, IDC_OPL, TEXT("DOSBOX"));
  228. ComboBox_AddString(hwndDlg, IDC_OPL, TEXT("MAME"));
  229. ComboBox_AddString(hwndDlg, IDC_OPL, TEXT("DOSBOXNEW"));
  230. TrackBar_SetRange(hwndDlg, IDC_QUALITY, RESAMPLER_QUALITY_MIN, RESAMPLER_QUALITY_MAX, FALSE);
  231. TrackBar_SetRange(hwndDlg, IDC_MUSICVOLUME, 0, PAL_MAX_VOLUME, FALSE);
  232. TrackBar_SetRange(hwndDlg, IDC_SOUNDVOLUME, 0, PAL_MAX_VOLUME, FALSE);
  233. ResetControls(hwndDlg);
  234. WINDOWINFO wi = { sizeof(WINDOWINFO) };
  235. RECT rcWork;
  236. if (SystemParametersInfo(SPI_GETWORKAREA, 0, &rcWork, 0) && GetWindowInfo(hwndDlg, &wi))
  237. {
  238. int x = ((rcWork.right - rcWork.left) - (wi.rcWindow.right - wi.rcWindow.left)) / 2;
  239. int y = ((rcWork.bottom - rcWork.top) - (wi.rcWindow.bottom - wi.rcWindow.top)) / 2;
  240. SetWindowPos(hwndDlg, 0, x, y, 0, 0, SWP_NOSIZE | SWP_NOOWNERZORDER | SWP_SHOWWINDOW);
  241. }
  242. return TRUE;
  243. }
  244. INT_PTR ButtonProc(HWND hwndDlg, WORD idControl, HWND hwndCtrl)
  245. {
  246. switch (idControl)
  247. {
  248. case IDOK:
  249. gConfig.fLaunchSetting = FALSE;
  250. SaveSettings(hwndDlg, TRUE);
  251. EndDialog(hwndDlg, IDOK);
  252. return TRUE;
  253. case IDCANCEL:
  254. EndDialog(hwndDlg, IDCANCEL);
  255. return TRUE;
  256. case IDC_DEFAULT:
  257. PAL_LoadConfig(FALSE);
  258. ResetControls(hwndDlg);
  259. return TRUE;
  260. case IDC_BRGAME:
  261. {
  262. TCHAR szName[MAX_PATH * 2], szTitle[200];
  263. BROWSEINFO bi = { hwndDlg, nullptr, szName, szTitle, BIF_USENEWUI, nullptr, NULL, 0 };
  264. LoadStringEx(g_hInstance, IDC_BRGAME, g_wLanguage, szTitle, 200);
  265. auto pidl = SHBrowseForFolder(&bi);
  266. if (pidl)
  267. {
  268. SHGetPathFromIDList(pidl, szName);
  269. int n = _tcslen(szName);
  270. if (szName[n - 1] != '\\') _tcscat(szName, L"\\");
  271. SetDlgItemText(hwndDlg, IDC_GAMEPATH, szName);
  272. }
  273. return TRUE;
  274. }
  275. case IDC_BRFONT:
  276. case IDC_BRMSG:
  277. case IDC_BRLOG:
  278. {
  279. TCHAR szFilePath[MAX_PATH * 2] = { 0 };
  280. auto filter = LoadResourceString(idControl + 1);
  281. auto title = LoadResourceString(idControl);
  282. for (auto i = filter.begin(); i != filter.end(); *i = (*i == '|') ? '\0' : *i, i++);
  283. OPENFILENAME ofn = {
  284. sizeof(OPENFILENAME), hwndDlg, nullptr,
  285. filter.c_str(), nullptr, 0, 0,
  286. szFilePath, sizeof(szFilePath) / sizeof(TCHAR),
  287. nullptr, 0, nullptr, title.c_str(),
  288. OFN_HIDEREADONLY | OFN_PATHMUSTEXIST | (idControl != IDC_BRLOG ? OFN_FILEMUSTEXIST : (DWORD)0)
  289. };
  290. if (idControl == IDC_BRLOG ? GetSaveFileName(&ofn) : GetOpenFileName(&ofn))
  291. {
  292. SetDlgItemText(hwndDlg, idControl + 1, ofn.lpstrFile);
  293. }
  294. return TRUE;
  295. }
  296. case IDC_USEMSGFILE:
  297. case IDC_USEFONTFILE:
  298. case IDC_USELOGFILE:
  299. EnableDlgItem(hwndDlg, idControl + 1, IsDlgButtonChecked(hwndDlg, idControl));
  300. return TRUE;
  301. default: return FALSE;
  302. }
  303. }
  304. INT_PTR ComboBoxProc(HWND hwndDlg, WORD idControl, HWND hwndCtrl)
  305. {
  306. switch (idControl)
  307. {
  308. case IDC_BGM:
  309. EnableDlgItem(hwndDlg, IDC_OPL, ComboBox_GetCurSel(hwndDlg, IDC_BGM) == MUSIC_RIX);
  310. EnableDlgItem(hwndDlg, IDC_SURROUNDOPL, ComboBox_GetCurSel(hwndDlg, IDC_BGM) == MUSIC_RIX);
  311. EnableDlgItem(hwndDlg, IDC_OPLSR, ComboBox_GetCurSel(hwndDlg, IDC_BGM) == MUSIC_RIX);
  312. return TRUE;
  313. default:
  314. return FALSE;
  315. }
  316. }
  317. INT_PTR CommandProc(HWND hwndDlg, WORD command, WORD idControl, HWND hwndCtrl)
  318. {
  319. switch (command)
  320. {
  321. case BN_CLICKED: return ButtonProc(hwndDlg, idControl, hwndCtrl);
  322. case CBN_SELCHANGE: return ComboBoxProc(hwndDlg, idControl, hwndCtrl);
  323. default: return FALSE;
  324. }
  325. }
  326. INT_PTR CALLBACK LauncherDialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
  327. {
  328. switch (uMsg)
  329. {
  330. case WM_INITDIALOG: return InitProc(hwndDlg, (HWND)wParam, lParam);
  331. case WM_COMMAND: return CommandProc(hwndDlg, HIWORD(wParam), LOWORD(wParam), (HWND)lParam);
  332. case WM_CLOSE: return EndDialog(hwndDlg, 0);
  333. default: return FALSE;
  334. }
  335. }
  336. typedef LANGID(__stdcall *GETLANGUAGEID)(void);
  337. extern "C" int UTIL_Platform_Init(int argc, char* argv[])
  338. {
  339. SDL_setenv("SDL_AUDIODRIVER","directsound",1);
  340. // Try to get Vista+ API at runtime, and falls back to XP's API if not found
  341. GETLANGUAGEID GetLanguage = (GETLANGUAGEID)GetProcAddress(GetModuleHandle(TEXT("Kernel32.dll")), "GetThreadUILanguage");
  342. if (!GetLanguage) GetLanguage = GetUserDefaultLangID;
  343. // Defaults log to debug output
  344. UTIL_LogAddOutputCallback([](LOGLEVEL, const char* str, const char*)->void {
  345. OutputDebugStringA(str);
  346. }, PAL_DEFAULT_LOGLEVEL);
  347. g_hInstance = GetModuleHandle(nullptr);
  348. g_wLanguage = GetLanguage();
  349. if (PRIMARYLANGID(g_wLanguage) == LANG_CHINESE)
  350. {
  351. if (SUBLANGID(g_wLanguage) == SUBLANG_CHINESE_SIMPLIFIED || SUBLANGID(g_wLanguage) == SUBLANG_CHINESE_SINGAPORE)
  352. g_wLanguage = MAKELANGID(LANG_CHINESE, SUBLANG_CHINESE_SIMPLIFIED);
  353. else
  354. g_wLanguage = MAKELANGID(LANG_CHINESE, SUBLANG_CHINESE_TRADITIONAL);
  355. }
  356. else
  357. g_wLanguage = MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL);
  358. auto dlg = (LPCDLGTEMPLATE)LockResource(LoadResource(g_hInstance, FindResourceEx(g_hInstance, RT_DIALOG, MAKEINTRESOURCE(IDD_LAUNCHER), g_wLanguage)));
  359. if (gConfig.fLaunchSetting && DialogBoxIndirect(GetModuleHandle(nullptr), dlg, nullptr, LauncherDialogProc) != IDOK)
  360. return -1;
  361. else
  362. return 0;
  363. }
  364. extern "C" VOID UTIL_Platform_Quit(VOID) {}
  365. extern "C" BOOL
  366. UTIL_GetScreenSize(
  367. DWORD *pdwScreenWidth,
  368. DWORD *pdwScreenHeight
  369. )
  370. {
  371. return (pdwScreenWidth && pdwScreenHeight && *pdwScreenWidth && *pdwScreenHeight);
  372. }
  373. extern "C"
  374. BOOL UTIL_IsAbsolutePath(LPCSTR lpszFileName)
  375. {
  376. char szDrive[_MAX_DRIVE], szDir[_MAX_DIR], szFname[_MAX_FNAME], szExt[_MAX_EXT];
  377. #if !defined(__MINGW32__) // MinGW Distro's win32 api lacks this...Anyway, winxp lacks this too
  378. if (_splitpath_s(lpszFileName, szDrive, szDir, szFname, szExt) == 0)
  379. #else
  380. _splitpath(lpszFileName, szDrive, szDir, szFname, szExt);
  381. if ( errno !=EINVAL )
  382. #endif
  383. return (strlen(szDrive) > 0 && (szDir[0] == '\\' || szDir[0] == '/'));
  384. else
  385. return FALSE;
  386. }