ntdll: Implement RtlIsEcCode().
[wine.git] / programs / regedit / main.c
blob4cc00d730a78937665b1b1c3fcb52c0dd17bdd54
1 /*
2 * Regedit main function
4 * Copyright (C) 2002 Robert Dickenson <robd@reactos.org>
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.
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.
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
21 #define WIN32_LEAN_AND_MEAN /* Exclude rarely-used stuff from Windows headers */
22 #include <windows.h>
23 #include <commctrl.h>
24 #include <fcntl.h>
25 #include "wine/debug.h"
27 #define REGEDIT_DECLARE_FUNCTIONS
28 #include "main.h"
30 WINE_DEFAULT_DEBUG_CHANNEL(regedit);
32 WCHAR g_pszDefaultValueName[64];
34 BOOL ProcessCmdLine(WCHAR *cmdline);
36 const WCHAR *reg_class_namesW[] = {L"HKEY_LOCAL_MACHINE", L"HKEY_USERS",
37 L"HKEY_CLASSES_ROOT", L"HKEY_CURRENT_CONFIG",
38 L"HKEY_CURRENT_USER", L"HKEY_DYN_DATA"
41 /*******************************************************************************
42 * Global Variables:
45 HINSTANCE hInst;
46 HWND hFrameWnd;
47 HWND hStatusBar;
48 HMENU hMenuFrame;
49 HMENU hPopupMenus = 0;
50 UINT nClipboardFormat;
52 #define MAX_LOADSTRING 100
53 static WCHAR szTitle[MAX_LOADSTRING];
54 const WCHAR szChildClass[] = L"REGEDIT";
55 static const WCHAR szFrameClass[] = L"RegEdit_RegEdit";
57 static BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
59 WCHAR empty = 0;
60 WNDCLASSEXW wndclass = {0};
62 /* Frame class */
63 wndclass.cbSize = sizeof(WNDCLASSEXW);
64 wndclass.style = CS_HREDRAW | CS_VREDRAW;
65 wndclass.lpfnWndProc = FrameWndProc;
66 wndclass.hInstance = hInstance;
67 wndclass.hIcon = LoadIconW(hInstance, MAKEINTRESOURCEW(IDI_REGEDIT));
68 wndclass.hCursor = LoadCursorW(0, (LPCWSTR)IDC_ARROW);
69 wndclass.lpszClassName = szFrameClass;
70 wndclass.hIconSm = LoadImageW(hInstance, MAKEINTRESOURCEW(IDI_REGEDIT), IMAGE_ICON,
71 GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), LR_SHARED);
72 RegisterClassExW(&wndclass);
74 /* Child class */
75 wndclass.lpfnWndProc = ChildWndProc;
76 wndclass.cbWndExtra = sizeof(HANDLE);
77 wndclass.lpszClassName = szChildClass;
78 wndclass.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
79 RegisterClassExW(&wndclass);
81 hMenuFrame = LoadMenuW(hInstance, MAKEINTRESOURCEW(IDR_REGEDIT_MENU));
82 hPopupMenus = LoadMenuW(hInstance, MAKEINTRESOURCEW(IDR_POPUP_MENUS));
84 /* Initialize the Windows Common Controls DLL */
85 InitCommonControls();
87 /* register our hex editor control */
88 HexEdit_Register();
90 nClipboardFormat = RegisterClipboardFormatW(L"TODO: Set correct format");
92 hFrameWnd = CreateWindowExW(0, szFrameClass, szTitle,
93 WS_OVERLAPPEDWINDOW | WS_EX_CLIENTEDGE,
94 CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
95 NULL, hMenuFrame, hInstance, NULL/*lpParam*/);
97 if (!hFrameWnd) {
98 return FALSE;
101 /* Create the status bar */
102 hStatusBar = CreateStatusWindowW(WS_VISIBLE|WS_CHILD|WS_CLIPSIBLINGS|SBT_NOBORDERS,
103 &empty, hFrameWnd, STATUS_WINDOW);
104 if (hStatusBar) {
105 /* Create the status bar panes */
106 SetupStatusBar(hFrameWnd, FALSE);
107 CheckMenuItem(GetSubMenu(hMenuFrame, ID_VIEW_MENU), ID_VIEW_STATUSBAR, MF_BYCOMMAND|MF_CHECKED);
109 ShowWindow(hFrameWnd, nCmdShow);
110 UpdateWindow(hFrameWnd);
111 return TRUE;
114 /******************************************************************************/
116 static void ExitInstance(void)
118 DestroyMenu(hMenuFrame);
121 static BOOL TranslateChildTabMessage(MSG *msg)
123 if (msg->message != WM_KEYDOWN) return FALSE;
124 if (msg->wParam != VK_TAB) return FALSE;
125 if (GetParent(msg->hwnd) != g_pChildWnd->hWnd) return FALSE;
126 PostMessageW(g_pChildWnd->hWnd, WM_COMMAND, ID_SWITCH_PANELS, 0);
127 return TRUE;
130 int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int nCmdShow)
132 MSG msg;
133 HACCEL hAccel;
134 BOOL is_wow64;
136 if (ProcessCmdLine(GetCommandLineW())) {
137 return 0;
140 if (IsWow64Process( GetCurrentProcess(), &is_wow64 ) && is_wow64)
142 static const WCHAR filename[] = L"C:\\windows\\regedit.exe";
143 STARTUPINFOW si;
144 PROCESS_INFORMATION pi;
145 void *redir;
146 DWORD exit_code;
148 memset( &si, 0, sizeof(si) );
149 si.cb = sizeof(si);
151 Wow64DisableWow64FsRedirection( &redir );
152 if (CreateProcessW( filename, GetCommandLineW(), NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi ))
154 WINE_TRACE( "restarting %s\n", wine_dbgstr_w(filename) );
155 WaitForSingleObject( pi.hProcess, INFINITE );
156 GetExitCodeProcess( pi.hProcess, &exit_code );
157 ExitProcess( exit_code );
159 else WINE_ERR( "failed to restart 64-bit %s, err %ld\n", wine_dbgstr_w(filename), GetLastError() );
160 Wow64RevertWow64FsRedirection( redir );
163 InitCommonControls();
165 /* Initialize global strings */
166 LoadStringW(hInstance, IDS_APP_TITLE, szTitle, ARRAY_SIZE(szTitle));
167 LoadStringW(hInstance, IDS_REGISTRY_DEFAULT_VALUE, g_pszDefaultValueName, ARRAY_SIZE(g_pszDefaultValueName));
169 /* Store instance handle in our global variable */
170 hInst = hInstance;
172 /* Perform application initialization */
173 if (!InitInstance(hInstance, nCmdShow)) {
174 return FALSE;
176 hAccel = LoadAcceleratorsW(hInstance, MAKEINTRESOURCEW(IDC_REGEDIT));
178 /* Main message loop */
179 while (GetMessageW(&msg, NULL, 0, 0)) {
180 if (!TranslateAcceleratorW(hFrameWnd, hAccel, &msg)
181 && !TranslateChildTabMessage(&msg)) {
182 TranslateMessage(&msg);
183 DispatchMessageW(&msg);
186 ExitInstance();
187 return msg.wParam;