main.c 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. /*
  2. * Regedit main function
  3. *
  4. * Copyright (C) 2002 Robert Dickenson <robd@reactos.org>
  5. *
  6. * This library is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 2.1 of the License, or (at your option) any later version.
  10. *
  11. * This library is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public
  17. * License along with this library; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
  19. */
  20. #define WIN32_LEAN_AND_MEAN /* Exclude rarely-used stuff from Windows headers */
  21. #include <windows.h>
  22. #include <commctrl.h>
  23. #include <stdlib.h>
  24. #include <fcntl.h>
  25. #include "wine/debug.h"
  26. #define REGEDIT_DECLARE_FUNCTIONS
  27. #include "main.h"
  28. WINE_DEFAULT_DEBUG_CHANNEL(regedit);
  29. WCHAR g_pszDefaultValueName[64];
  30. BOOL ProcessCmdLine(WCHAR *cmdline);
  31. static const WCHAR hkey_local_machine[] = {'H','K','E','Y','_','L','O','C','A','L','_','M','A','C','H','I','N','E',0};
  32. static const WCHAR hkey_users[] = {'H','K','E','Y','_','U','S','E','R','S',0};
  33. static const WCHAR hkey_classes_root[] = {'H','K','E','Y','_','C','L','A','S','S','E','S','_','R','O','O','T',0};
  34. static const WCHAR hkey_current_config[] = {'H','K','E','Y','_','C','U','R','R','E','N','T','_','C','O','N','F','I','G',0};
  35. static const WCHAR hkey_current_user[] = {'H','K','E','Y','_','C','U','R','R','E','N','T','_','U','S','E','R',0};
  36. static const WCHAR hkey_dyn_data[] = {'H','K','E','Y','_','D','Y','N','_','D','A','T','A',0};
  37. const WCHAR *reg_class_namesW[] = {hkey_local_machine, hkey_users,
  38. hkey_classes_root, hkey_current_config,
  39. hkey_current_user, hkey_dyn_data
  40. };
  41. /*******************************************************************************
  42. * Global Variables:
  43. */
  44. HINSTANCE hInst;
  45. HWND hFrameWnd;
  46. HWND hStatusBar;
  47. HMENU hMenuFrame;
  48. HMENU hPopupMenus = 0;
  49. UINT nClipboardFormat;
  50. const WCHAR strClipboardFormat[] = {'T','O','D','O',':',' ','S','E','T',' ','C','O','R','R','E','C','T',' ','F','O','R','M','A','T',0};
  51. #define MAX_LOADSTRING 100
  52. WCHAR szTitle[MAX_LOADSTRING];
  53. const WCHAR szFrameClass[] = {'R','e','g','E','d','i','t','_','R','e','g','E','d','i','t',0};
  54. const WCHAR szChildClass[] = {'R','E','G','E','D','I','T',0};
  55. static BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
  56. {
  57. WCHAR empty = 0;
  58. WNDCLASSEXW wndclass = {0};
  59. /* Frame class */
  60. wndclass.cbSize = sizeof(WNDCLASSEXW);
  61. wndclass.style = CS_HREDRAW | CS_VREDRAW;
  62. wndclass.lpfnWndProc = FrameWndProc;
  63. wndclass.hInstance = hInstance;
  64. wndclass.hIcon = LoadIconW(hInstance, MAKEINTRESOURCEW(IDI_REGEDIT));
  65. wndclass.hCursor = LoadCursorW(0, (LPCWSTR)IDC_ARROW);
  66. wndclass.lpszClassName = szFrameClass;
  67. wndclass.hIconSm = LoadImageW(hInstance, MAKEINTRESOURCEW(IDI_REGEDIT), IMAGE_ICON,
  68. GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), LR_SHARED);
  69. RegisterClassExW(&wndclass);
  70. /* Child class */
  71. wndclass.lpfnWndProc = ChildWndProc;
  72. wndclass.cbWndExtra = sizeof(HANDLE);
  73. wndclass.lpszClassName = szChildClass;
  74. RegisterClassExW(&wndclass);
  75. hMenuFrame = LoadMenuW(hInstance, MAKEINTRESOURCEW(IDR_REGEDIT_MENU));
  76. hPopupMenus = LoadMenuW(hInstance, MAKEINTRESOURCEW(IDR_POPUP_MENUS));
  77. /* Initialize the Windows Common Controls DLL */
  78. InitCommonControls();
  79. /* register our hex editor control */
  80. HexEdit_Register();
  81. nClipboardFormat = RegisterClipboardFormatW(strClipboardFormat);
  82. hFrameWnd = CreateWindowExW(0, szFrameClass, szTitle,
  83. WS_OVERLAPPEDWINDOW | WS_EX_CLIENTEDGE,
  84. CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
  85. NULL, hMenuFrame, hInstance, NULL/*lpParam*/);
  86. if (!hFrameWnd) {
  87. return FALSE;
  88. }
  89. /* Create the status bar */
  90. hStatusBar = CreateStatusWindowW(WS_VISIBLE|WS_CHILD|WS_CLIPSIBLINGS|SBT_NOBORDERS,
  91. &empty, hFrameWnd, STATUS_WINDOW);
  92. if (hStatusBar) {
  93. /* Create the status bar panes */
  94. SetupStatusBar(hFrameWnd, FALSE);
  95. CheckMenuItem(GetSubMenu(hMenuFrame, ID_VIEW_MENU), ID_VIEW_STATUSBAR, MF_BYCOMMAND|MF_CHECKED);
  96. }
  97. ShowWindow(hFrameWnd, nCmdShow);
  98. UpdateWindow(hFrameWnd);
  99. return TRUE;
  100. }
  101. /******************************************************************************/
  102. static void ExitInstance(void)
  103. {
  104. DestroyMenu(hMenuFrame);
  105. }
  106. static BOOL TranslateChildTabMessage(MSG *msg)
  107. {
  108. if (msg->message != WM_KEYDOWN) return FALSE;
  109. if (msg->wParam != VK_TAB) return FALSE;
  110. if (GetParent(msg->hwnd) != g_pChildWnd->hWnd) return FALSE;
  111. PostMessageW(g_pChildWnd->hWnd, WM_COMMAND, ID_SWITCH_PANELS, 0);
  112. return TRUE;
  113. }
  114. int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int nCmdShow)
  115. {
  116. MSG msg;
  117. HACCEL hAccel;
  118. BOOL is_wow64;
  119. if (ProcessCmdLine(GetCommandLineW())) {
  120. return 0;
  121. }
  122. if (IsWow64Process( GetCurrentProcess(), &is_wow64 ) && is_wow64)
  123. {
  124. static const WCHAR filename[] = L"C:\\windows\\regedit.exe";
  125. STARTUPINFOW si;
  126. PROCESS_INFORMATION pi;
  127. void *redir;
  128. DWORD exit_code;
  129. memset( &si, 0, sizeof(si) );
  130. si.cb = sizeof(si);
  131. Wow64DisableWow64FsRedirection( &redir );
  132. if (CreateProcessW( filename, GetCommandLineW(), NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi ))
  133. {
  134. WINE_TRACE( "restarting %s\n", wine_dbgstr_w(filename) );
  135. WaitForSingleObject( pi.hProcess, INFINITE );
  136. GetExitCodeProcess( pi.hProcess, &exit_code );
  137. ExitProcess( exit_code );
  138. }
  139. else WINE_ERR( "failed to restart 64-bit %s, err %d\n", wine_dbgstr_w(filename), GetLastError() );
  140. Wow64RevertWow64FsRedirection( redir );
  141. }
  142. /* Initialize global strings */
  143. LoadStringW(hInstance, IDS_APP_TITLE, szTitle, ARRAY_SIZE(szTitle));
  144. LoadStringW(hInstance, IDS_REGISTRY_DEFAULT_VALUE, g_pszDefaultValueName, ARRAY_SIZE(g_pszDefaultValueName));
  145. /* Store instance handle in our global variable */
  146. hInst = hInstance;
  147. /* Perform application initialization */
  148. if (!InitInstance(hInstance, nCmdShow)) {
  149. return FALSE;
  150. }
  151. hAccel = LoadAcceleratorsW(hInstance, MAKEINTRESOURCEW(IDC_REGEDIT));
  152. /* Main message loop */
  153. while (GetMessageW(&msg, NULL, 0, 0)) {
  154. if (!TranslateAcceleratorW(hFrameWnd, hAccel, &msg)
  155. && !TranslateChildTabMessage(&msg)) {
  156. TranslateMessage(&msg);
  157. DispatchMessageW(&msg);
  158. }
  159. }
  160. ExitInstance();
  161. return msg.wParam;
  162. }