main.c 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  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. const WCHAR *reg_class_namesW[] = {L"HKEY_LOCAL_MACHINE", L"HKEY_USERS",
  32. L"HKEY_CLASSES_ROOT", L"HKEY_CURRENT_CONFIG",
  33. L"HKEY_CURRENT_USER", L"HKEY_DYN_DATA"
  34. };
  35. /*******************************************************************************
  36. * Global Variables:
  37. */
  38. HINSTANCE hInst;
  39. HWND hFrameWnd;
  40. HWND hStatusBar;
  41. HMENU hMenuFrame;
  42. HMENU hPopupMenus = 0;
  43. UINT nClipboardFormat;
  44. #define MAX_LOADSTRING 100
  45. static WCHAR szTitle[MAX_LOADSTRING];
  46. const WCHAR szChildClass[] = L"REGEDIT";
  47. static const WCHAR szFrameClass[] = L"RegEdit_RegEdit";
  48. static BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
  49. {
  50. WCHAR empty = 0;
  51. WNDCLASSEXW wndclass = {0};
  52. /* Frame class */
  53. wndclass.cbSize = sizeof(WNDCLASSEXW);
  54. wndclass.style = CS_HREDRAW | CS_VREDRAW;
  55. wndclass.lpfnWndProc = FrameWndProc;
  56. wndclass.hInstance = hInstance;
  57. wndclass.hIcon = LoadIconW(hInstance, MAKEINTRESOURCEW(IDI_REGEDIT));
  58. wndclass.hCursor = LoadCursorW(0, (LPCWSTR)IDC_ARROW);
  59. wndclass.lpszClassName = szFrameClass;
  60. wndclass.hIconSm = LoadImageW(hInstance, MAKEINTRESOURCEW(IDI_REGEDIT), IMAGE_ICON,
  61. GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), LR_SHARED);
  62. RegisterClassExW(&wndclass);
  63. /* Child class */
  64. wndclass.lpfnWndProc = ChildWndProc;
  65. wndclass.cbWndExtra = sizeof(HANDLE);
  66. wndclass.lpszClassName = szChildClass;
  67. RegisterClassExW(&wndclass);
  68. hMenuFrame = LoadMenuW(hInstance, MAKEINTRESOURCEW(IDR_REGEDIT_MENU));
  69. hPopupMenus = LoadMenuW(hInstance, MAKEINTRESOURCEW(IDR_POPUP_MENUS));
  70. /* Initialize the Windows Common Controls DLL */
  71. InitCommonControls();
  72. /* register our hex editor control */
  73. HexEdit_Register();
  74. nClipboardFormat = RegisterClipboardFormatW(L"TODO: Set correct format");
  75. hFrameWnd = CreateWindowExW(0, szFrameClass, szTitle,
  76. WS_OVERLAPPEDWINDOW | WS_EX_CLIENTEDGE,
  77. CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
  78. NULL, hMenuFrame, hInstance, NULL/*lpParam*/);
  79. if (!hFrameWnd) {
  80. return FALSE;
  81. }
  82. /* Create the status bar */
  83. hStatusBar = CreateStatusWindowW(WS_VISIBLE|WS_CHILD|WS_CLIPSIBLINGS|SBT_NOBORDERS,
  84. &empty, hFrameWnd, STATUS_WINDOW);
  85. if (hStatusBar) {
  86. /* Create the status bar panes */
  87. SetupStatusBar(hFrameWnd, FALSE);
  88. CheckMenuItem(GetSubMenu(hMenuFrame, ID_VIEW_MENU), ID_VIEW_STATUSBAR, MF_BYCOMMAND|MF_CHECKED);
  89. }
  90. ShowWindow(hFrameWnd, nCmdShow);
  91. UpdateWindow(hFrameWnd);
  92. return TRUE;
  93. }
  94. /******************************************************************************/
  95. static void ExitInstance(void)
  96. {
  97. DestroyMenu(hMenuFrame);
  98. }
  99. static BOOL TranslateChildTabMessage(MSG *msg)
  100. {
  101. if (msg->message != WM_KEYDOWN) return FALSE;
  102. if (msg->wParam != VK_TAB) return FALSE;
  103. if (GetParent(msg->hwnd) != g_pChildWnd->hWnd) return FALSE;
  104. PostMessageW(g_pChildWnd->hWnd, WM_COMMAND, ID_SWITCH_PANELS, 0);
  105. return TRUE;
  106. }
  107. int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int nCmdShow)
  108. {
  109. MSG msg;
  110. HACCEL hAccel;
  111. BOOL is_wow64;
  112. InitCommonControls();
  113. if (ProcessCmdLine(GetCommandLineW())) {
  114. return 0;
  115. }
  116. if (IsWow64Process( GetCurrentProcess(), &is_wow64 ) && is_wow64)
  117. {
  118. static const WCHAR filename[] = L"C:\\windows\\regedit.exe";
  119. STARTUPINFOW si;
  120. PROCESS_INFORMATION pi;
  121. void *redir;
  122. DWORD exit_code;
  123. memset( &si, 0, sizeof(si) );
  124. si.cb = sizeof(si);
  125. Wow64DisableWow64FsRedirection( &redir );
  126. if (CreateProcessW( filename, GetCommandLineW(), NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi ))
  127. {
  128. WINE_TRACE( "restarting %s\n", wine_dbgstr_w(filename) );
  129. WaitForSingleObject( pi.hProcess, INFINITE );
  130. GetExitCodeProcess( pi.hProcess, &exit_code );
  131. ExitProcess( exit_code );
  132. }
  133. else WINE_ERR( "failed to restart 64-bit %s, err %ld\n", wine_dbgstr_w(filename), GetLastError() );
  134. Wow64RevertWow64FsRedirection( redir );
  135. }
  136. /* Initialize global strings */
  137. LoadStringW(hInstance, IDS_APP_TITLE, szTitle, ARRAY_SIZE(szTitle));
  138. LoadStringW(hInstance, IDS_REGISTRY_DEFAULT_VALUE, g_pszDefaultValueName, ARRAY_SIZE(g_pszDefaultValueName));
  139. /* Store instance handle in our global variable */
  140. hInst = hInstance;
  141. /* Perform application initialization */
  142. if (!InitInstance(hInstance, nCmdShow)) {
  143. return FALSE;
  144. }
  145. hAccel = LoadAcceleratorsW(hInstance, MAKEINTRESOURCEW(IDC_REGEDIT));
  146. /* Main message loop */
  147. while (GetMessageW(&msg, NULL, 0, 0)) {
  148. if (!TranslateAcceleratorW(hFrameWnd, hAccel, &msg)
  149. && !TranslateChildTabMessage(&msg)) {
  150. TranslateMessage(&msg);
  151. DispatchMessageW(&msg);
  152. }
  153. }
  154. ExitInstance();
  155. return msg.wParam;
  156. }