main.c 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  1. /*
  2. * WineCfg main entry point
  3. *
  4. * Copyright 2002 Jaco Greeff
  5. * Copyright 2003 Dimitrie O. Paun
  6. * Copyright 2003 Mike Hearn
  7. *
  8. * This library is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU Lesser General Public
  10. * License as published by the Free Software Foundation; either
  11. * version 2.1 of the License, or (at your option) any later version.
  12. *
  13. * This library 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. See the GNU
  16. * Lesser General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with this library; if not, write to the Free Software
  20. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
  21. *
  22. */
  23. #define WIN32_LEAN_AND_MEAN
  24. #define NONAMELESSUNION
  25. #include <windows.h>
  26. #include <commctrl.h>
  27. #include <objbase.h>
  28. #include <wine/debug.h>
  29. #include "resource.h"
  30. #include "winecfg.h"
  31. WINE_DEFAULT_DEBUG_CHANNEL(winecfg);
  32. static INT CALLBACK
  33. PropSheetCallback (HWND hWnd, UINT uMsg, LPARAM lParam)
  34. {
  35. switch (uMsg)
  36. {
  37. /*
  38. * hWnd = NULL, lParam == dialog resource
  39. */
  40. case PSCB_PRECREATE:
  41. break;
  42. case PSCB_INITIALIZED:
  43. /* Set the window icon */
  44. SendMessageW( hWnd, WM_SETICON, ICON_BIG,
  45. (LPARAM)LoadIconW( (HINSTANCE)GetWindowLongPtrW(hWnd, GWLP_HINSTANCE),
  46. MAKEINTRESOURCEW(IDI_WINECFG) ));
  47. break;
  48. default:
  49. break;
  50. }
  51. return 0;
  52. }
  53. #define NUM_PROPERTY_PAGES 7
  54. static INT_PTR
  55. doPropertySheet (HINSTANCE hInstance, HWND hOwner)
  56. {
  57. PROPSHEETPAGEW psp[NUM_PROPERTY_PAGES];
  58. PROPSHEETHEADERW psh;
  59. int pg = 0; /* start with page 0 */
  60. /*
  61. * Fill out the (Applications) PROPSHEETPAGE data structure
  62. * for the property sheet
  63. */
  64. psp[pg].dwSize = sizeof (PROPSHEETPAGEW);
  65. psp[pg].dwFlags = PSP_USETITLE;
  66. psp[pg].hInstance = hInstance;
  67. psp[pg].u.pszTemplate = MAKEINTRESOURCEW (IDD_APPCFG);
  68. psp[pg].u2.pszIcon = NULL;
  69. psp[pg].pfnDlgProc = AppDlgProc;
  70. psp[pg].pszTitle = load_string (IDS_TAB_APPLICATIONS);
  71. psp[pg].lParam = 0;
  72. pg++;
  73. /*
  74. * Fill out the (Libraries) PROPSHEETPAGE data structure
  75. * for the property sheet
  76. */
  77. psp[pg].dwSize = sizeof (PROPSHEETPAGEW);
  78. psp[pg].dwFlags = PSP_USETITLE;
  79. psp[pg].hInstance = hInstance;
  80. psp[pg].u.pszTemplate = MAKEINTRESOURCEW (IDD_DLLCFG);
  81. psp[pg].u2.pszIcon = NULL;
  82. psp[pg].pfnDlgProc = LibrariesDlgProc;
  83. psp[pg].pszTitle = load_string (IDS_TAB_DLLS);
  84. psp[pg].lParam = 0;
  85. pg++;
  86. /*
  87. * Fill out the (X11Drv) PROPSHEETPAGE data structure
  88. * for the property sheet
  89. */
  90. psp[pg].dwSize = sizeof (PROPSHEETPAGEW);
  91. psp[pg].dwFlags = PSP_USETITLE;
  92. psp[pg].hInstance = hInstance;
  93. psp[pg].u.pszTemplate = MAKEINTRESOURCEW (IDD_GRAPHCFG);
  94. psp[pg].u2.pszIcon = NULL;
  95. psp[pg].pfnDlgProc = GraphDlgProc;
  96. psp[pg].pszTitle = load_string (IDS_TAB_GRAPHICS);
  97. psp[pg].lParam = 0;
  98. pg++;
  99. psp[pg].dwSize = sizeof (PROPSHEETPAGEW);
  100. psp[pg].dwFlags = PSP_USETITLE;
  101. psp[pg].hInstance = hInstance;
  102. psp[pg].u.pszTemplate = MAKEINTRESOURCEW (IDD_DESKTOP_INTEGRATION);
  103. psp[pg].u2.pszIcon = NULL;
  104. psp[pg].pfnDlgProc = ThemeDlgProc;
  105. psp[pg].pszTitle = load_string (IDS_TAB_DESKTOP_INTEGRATION);
  106. psp[pg].lParam = 0;
  107. pg++;
  108. psp[pg].dwSize = sizeof (PROPSHEETPAGEW);
  109. psp[pg].dwFlags = PSP_USETITLE;
  110. psp[pg].hInstance = hInstance;
  111. psp[pg].u.pszTemplate = MAKEINTRESOURCEW (IDD_DRIVECFG);
  112. psp[pg].u2.pszIcon = NULL;
  113. psp[pg].pfnDlgProc = DriveDlgProc;
  114. psp[pg].pszTitle = load_string (IDS_TAB_DRIVES);
  115. psp[pg].lParam = 0;
  116. pg++;
  117. psp[pg].dwSize = sizeof (PROPSHEETPAGEW);
  118. psp[pg].dwFlags = PSP_USETITLE;
  119. psp[pg].hInstance = hInstance;
  120. psp[pg].u.pszTemplate = MAKEINTRESOURCEW (IDD_AUDIOCFG);
  121. psp[pg].u2.pszIcon = NULL;
  122. psp[pg].pfnDlgProc = AudioDlgProc;
  123. psp[pg].pszTitle = load_string (IDS_TAB_AUDIO);
  124. psp[pg].lParam = 0;
  125. pg++;
  126. /*
  127. * Fill out the (General) PROPSHEETPAGE data structure
  128. * for the property sheet
  129. */
  130. psp[pg].dwSize = sizeof (PROPSHEETPAGEW);
  131. psp[pg].dwFlags = PSP_USETITLE;
  132. psp[pg].hInstance = hInstance;
  133. psp[pg].u.pszTemplate = MAKEINTRESOURCEW (IDD_ABOUTCFG);
  134. psp[pg].u2.pszIcon = NULL;
  135. psp[pg].pfnDlgProc = AboutDlgProc;
  136. psp[pg].pszTitle = load_string (IDS_TAB_ABOUT);
  137. psp[pg].lParam = 0;
  138. pg++;
  139. /*
  140. * Fill out the PROPSHEETHEADER
  141. */
  142. psh.dwSize = sizeof (PROPSHEETHEADERW);
  143. psh.dwFlags = PSH_PROPSHEETPAGE | PSH_USEICONID | PSH_USECALLBACK;
  144. psh.hwndParent = hOwner;
  145. psh.hInstance = hInstance;
  146. psh.u.pszIcon = MAKEINTRESOURCEW (IDI_WINECFG);
  147. psh.pszCaption = load_string (IDS_WINECFG_TITLE);
  148. psh.nPages = NUM_PROPERTY_PAGES;
  149. psh.u3.ppsp = psp;
  150. psh.pfnCallback = PropSheetCallback;
  151. psh.u2.nStartPage = 0;
  152. /*
  153. * Display the modal property sheet
  154. */
  155. return PropertySheetW (&psh);
  156. }
  157. /******************************************************************************
  158. * Name : ProcessCmdLine
  159. * Description: Checks command line parameters
  160. * Parameters : lpCmdLine - the command line
  161. * Returns : The return value to return from WinMain, or -1 to continue
  162. * program execution.
  163. */
  164. static int
  165. ProcessCmdLine(LPWSTR lpCmdLine)
  166. {
  167. if (!(lpCmdLine[0] == '/' || lpCmdLine[0] == '-'))
  168. {
  169. return -1;
  170. }
  171. if (lpCmdLine[1] == 'V' || lpCmdLine[1] == 'v')
  172. {
  173. if (wcslen(lpCmdLine) > 4)
  174. return set_winver_from_string(&lpCmdLine[3]) ? 0 : 1;
  175. print_current_winver();
  176. return 0;
  177. }
  178. if (lpCmdLine[1] == '?')
  179. {
  180. printf("Usage: winecfg [options]\n\n");
  181. printf("Options:\n");
  182. printf(" [no option] Launch the graphical version of this program.\n");
  183. printf(" /v Display the current global Windows version.\n");
  184. printf(" /v version Set global Windows version to 'version'.\n");
  185. printf(" /? Display this information and exit.\n\n");
  186. printf("Valid versions for 'version':\n\n");
  187. print_windows_versions();
  188. return 0;
  189. }
  190. return -1;
  191. }
  192. /*****************************************************************************
  193. * Name : WinMain
  194. * Description: Main windows entry point
  195. * Parameters : hInstance
  196. * hPrev
  197. * szCmdLine
  198. * nShow
  199. * Returns : Program exit code
  200. */
  201. int WINAPI
  202. wWinMain (HINSTANCE hInstance, HINSTANCE hPrev, LPWSTR cmdline, int nShow)
  203. {
  204. BOOL is_wow64;
  205. int cmd_ret;
  206. if (IsWow64Process( GetCurrentProcess(), &is_wow64 ) && is_wow64)
  207. {
  208. STARTUPINFOW si;
  209. PROCESS_INFORMATION pi;
  210. WCHAR filename[] = L"C:\\windows\\system32\\winecfg.exe";
  211. void *redir;
  212. DWORD exit_code;
  213. memset( &si, 0, sizeof(si) );
  214. si.cb = sizeof(si);
  215. Wow64DisableWow64FsRedirection( &redir );
  216. if (CreateProcessW( filename, GetCommandLineW(), NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi ))
  217. {
  218. WINE_TRACE( "restarting %s\n", wine_dbgstr_w(filename) );
  219. WaitForSingleObject( pi.hProcess, INFINITE );
  220. GetExitCodeProcess( pi.hProcess, &exit_code );
  221. ExitProcess( exit_code );
  222. }
  223. else WINE_ERR( "failed to restart 64-bit %s, err %d\n", wine_dbgstr_w(filename), GetLastError() );
  224. Wow64RevertWow64FsRedirection( redir );
  225. }
  226. if (initialize(hInstance)) {
  227. WINE_ERR("initialization failed, aborting\n");
  228. ExitProcess(1);
  229. }
  230. cmd_ret = ProcessCmdLine(cmdline);
  231. if (cmd_ret >= 0) return cmd_ret;
  232. /*
  233. * The next 9 lines should be all that is needed
  234. * for the Wine Configuration property sheet
  235. */
  236. InitCommonControls ();
  237. CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
  238. if (doPropertySheet (hInstance, NULL) > 0) {
  239. WINE_TRACE("OK\n");
  240. } else {
  241. WINE_TRACE("Cancel\n");
  242. }
  243. CoUninitialize();
  244. ExitProcess (0);
  245. return 0;
  246. }