shell32/tests: Use the available ARRAY_SIZE() macro.
[wine.git] / programs / regedit / main.c
blob80f935027e87bc21c53a501ef86aa9ee4471bdf5
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 <stdlib.h>
25 #include <fcntl.h>
26 #include "wine/debug.h"
28 #define REGEDIT_DECLARE_FUNCTIONS
29 #include "main.h"
31 WINE_DEFAULT_DEBUG_CHANNEL(regedit);
33 WCHAR g_pszDefaultValueName[64];
35 BOOL ProcessCmdLine(WCHAR *cmdline);
37 static const WCHAR hkey_local_machine[] = {'H','K','E','Y','_','L','O','C','A','L','_','M','A','C','H','I','N','E',0};
38 static const WCHAR hkey_users[] = {'H','K','E','Y','_','U','S','E','R','S',0};
39 static const WCHAR hkey_classes_root[] = {'H','K','E','Y','_','C','L','A','S','S','E','S','_','R','O','O','T',0};
40 static const WCHAR hkey_current_config[] = {'H','K','E','Y','_','C','U','R','R','E','N','T','_','C','O','N','F','I','G',0};
41 static const WCHAR hkey_current_user[] = {'H','K','E','Y','_','C','U','R','R','E','N','T','_','U','S','E','R',0};
42 static const WCHAR hkey_dyn_data[] = {'H','K','E','Y','_','D','Y','N','_','D','A','T','A',0};
44 const WCHAR *reg_class_namesW[] = {hkey_local_machine, hkey_users,
45 hkey_classes_root, hkey_current_config,
46 hkey_current_user, hkey_dyn_data
49 /*******************************************************************************
50 * Global Variables:
53 HINSTANCE hInst;
54 HWND hFrameWnd;
55 HWND hStatusBar;
56 HMENU hMenuFrame;
57 HMENU hPopupMenus = 0;
58 UINT nClipboardFormat;
59 const WCHAR strClipboardFormat[] = {'T','O','D','O',':',' ','S','E','T',' ','C','O','R','R','E','C','T',' ','F','O','R','M','A','T',0};
62 #define MAX_LOADSTRING 100
63 WCHAR szTitle[MAX_LOADSTRING];
64 const WCHAR szFrameClass[] = {'R','e','g','E','d','i','t','_','R','e','g','E','d','i','t',0};
65 const WCHAR szChildClass[] = {'R','E','G','E','D','I','T',0};
67 static BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
69 WCHAR empty = 0;
70 WNDCLASSEXW wndclass = {0};
72 /* Frame class */
73 wndclass.cbSize = sizeof(WNDCLASSEXW);
74 wndclass.style = CS_HREDRAW | CS_VREDRAW;
75 wndclass.lpfnWndProc = FrameWndProc;
76 wndclass.hInstance = hInstance;
77 wndclass.hIcon = LoadIconW(hInstance, MAKEINTRESOURCEW(IDI_REGEDIT));
78 wndclass.hCursor = LoadCursorW(0, (LPCWSTR)IDC_ARROW);
79 wndclass.lpszClassName = szFrameClass;
80 wndclass.hIconSm = LoadImageW(hInstance, MAKEINTRESOURCEW(IDI_REGEDIT), IMAGE_ICON,
81 GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), LR_SHARED);
82 RegisterClassExW(&wndclass);
84 /* Child class */
85 wndclass.lpfnWndProc = ChildWndProc;
86 wndclass.cbWndExtra = sizeof(HANDLE);
87 wndclass.lpszClassName = szChildClass;
88 RegisterClassExW(&wndclass);
90 hMenuFrame = LoadMenuW(hInstance, MAKEINTRESOURCEW(IDR_REGEDIT_MENU));
91 hPopupMenus = LoadMenuW(hInstance, MAKEINTRESOURCEW(IDR_POPUP_MENUS));
93 /* Initialize the Windows Common Controls DLL */
94 InitCommonControls();
96 /* register our hex editor control */
97 HexEdit_Register();
99 nClipboardFormat = RegisterClipboardFormatW(strClipboardFormat);
101 hFrameWnd = CreateWindowExW(0, szFrameClass, szTitle,
102 WS_OVERLAPPEDWINDOW | WS_EX_CLIENTEDGE,
103 CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
104 NULL, hMenuFrame, hInstance, NULL/*lpParam*/);
106 if (!hFrameWnd) {
107 return FALSE;
110 /* Create the status bar */
111 hStatusBar = CreateStatusWindowW(WS_VISIBLE|WS_CHILD|WS_CLIPSIBLINGS|SBT_NOBORDERS,
112 &empty, hFrameWnd, STATUS_WINDOW);
113 if (hStatusBar) {
114 /* Create the status bar panes */
115 SetupStatusBar(hFrameWnd, FALSE);
116 CheckMenuItem(GetSubMenu(hMenuFrame, ID_VIEW_MENU), ID_VIEW_STATUSBAR, MF_BYCOMMAND|MF_CHECKED);
118 ShowWindow(hFrameWnd, nCmdShow);
119 UpdateWindow(hFrameWnd);
120 return TRUE;
123 /******************************************************************************/
125 static void ExitInstance(void)
127 DestroyMenu(hMenuFrame);
130 static BOOL TranslateChildTabMessage(MSG *msg)
132 if (msg->message != WM_KEYDOWN) return FALSE;
133 if (msg->wParam != VK_TAB) return FALSE;
134 if (GetParent(msg->hwnd) != g_pChildWnd->hWnd) return FALSE;
135 PostMessageW(g_pChildWnd->hWnd, WM_COMMAND, ID_SWITCH_PANELS, 0);
136 return TRUE;
139 int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int nCmdShow)
141 MSG msg;
142 HACCEL hAccel;
143 BOOL is_wow64;
145 if (ProcessCmdLine(GetCommandLineW())) {
146 return 0;
149 if (IsWow64Process( GetCurrentProcess(), &is_wow64 ) && is_wow64)
151 STARTUPINFOW si;
152 PROCESS_INFORMATION pi;
153 WCHAR filename[MAX_PATH];
154 void *redir;
155 DWORD exit_code;
157 memset( &si, 0, sizeof(si) );
158 si.cb = sizeof(si);
159 GetModuleFileNameW( 0, filename, MAX_PATH );
161 Wow64DisableWow64FsRedirection( &redir );
162 if (CreateProcessW( filename, GetCommandLineW(), NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi ))
164 WINE_TRACE( "restarting %s\n", wine_dbgstr_w(filename) );
165 WaitForSingleObject( pi.hProcess, INFINITE );
166 GetExitCodeProcess( pi.hProcess, &exit_code );
167 ExitProcess( exit_code );
169 else WINE_ERR( "failed to restart 64-bit %s, err %d\n", wine_dbgstr_w(filename), GetLastError() );
170 Wow64RevertWow64FsRedirection( redir );
173 /* Initialize global strings */
174 LoadStringW(hInstance, IDS_APP_TITLE, szTitle, ARRAY_SIZE(szTitle));
175 LoadStringW(hInstance, IDS_REGISTRY_DEFAULT_VALUE, g_pszDefaultValueName, ARRAY_SIZE(g_pszDefaultValueName));
177 /* Store instance handle in our global variable */
178 hInst = hInstance;
180 /* Perform application initialization */
181 if (!InitInstance(hInstance, nCmdShow)) {
182 return FALSE;
184 hAccel = LoadAcceleratorsW(hInstance, MAKEINTRESOURCEW(IDC_REGEDIT));
186 /* Main message loop */
187 while (GetMessageW(&msg, NULL, 0, 0)) {
188 if (!TranslateAcceleratorW(hFrameWnd, hAccel, &msg)
189 && !TranslateChildTabMessage(&msg)) {
190 TranslateMessage(&msg);
191 DispatchMessageW(&msg);
194 ExitInstance();
195 return msg.wParam;