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 */
26 #include "wine/debug.h"
28 #define REGEDIT_DECLARE_FUNCTIONS
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 /*******************************************************************************
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
)
70 WNDCLASSEXW wndclass
= {0};
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
);
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 */
96 /* register our hex editor control */
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*/);
110 /* Create the status bar */
111 hStatusBar
= CreateStatusWindowW(WS_VISIBLE
|WS_CHILD
|WS_CLIPSIBLINGS
|SBT_NOBORDERS
,
112 &empty
, hFrameWnd
, STATUS_WINDOW
);
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
);
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);
139 int WINAPI
wWinMain(HINSTANCE hInstance
, HINSTANCE hPrevInstance
, LPWSTR lpCmdLine
, int nCmdShow
)
145 if (ProcessCmdLine(GetCommandLineW())) {
149 if (IsWow64Process( GetCurrentProcess(), &is_wow64
) && is_wow64
)
151 static const WCHAR filename
[] = L
"C:\\windows\\regedit.exe";
153 PROCESS_INFORMATION pi
;
157 memset( &si
, 0, sizeof(si
) );
160 Wow64DisableWow64FsRedirection( &redir
);
161 if (CreateProcessW( filename
, GetCommandLineW(), NULL
, NULL
, FALSE
, 0, NULL
, NULL
, &si
, &pi
))
163 WINE_TRACE( "restarting %s\n", wine_dbgstr_w(filename
) );
164 WaitForSingleObject( pi
.hProcess
, INFINITE
);
165 GetExitCodeProcess( pi
.hProcess
, &exit_code
);
166 ExitProcess( exit_code
);
168 else WINE_ERR( "failed to restart 64-bit %s, err %d\n", wine_dbgstr_w(filename
), GetLastError() );
169 Wow64RevertWow64FsRedirection( redir
);
172 /* Initialize global strings */
173 LoadStringW(hInstance
, IDS_APP_TITLE
, szTitle
, ARRAY_SIZE(szTitle
));
174 LoadStringW(hInstance
, IDS_REGISTRY_DEFAULT_VALUE
, g_pszDefaultValueName
, ARRAY_SIZE(g_pszDefaultValueName
));
176 /* Store instance handle in our global variable */
179 /* Perform application initialization */
180 if (!InitInstance(hInstance
, nCmdShow
)) {
183 hAccel
= LoadAcceleratorsW(hInstance
, MAKEINTRESOURCEW(IDC_REGEDIT
));
185 /* Main message loop */
186 while (GetMessageW(&msg
, NULL
, 0, 0)) {
187 if (!TranslateAcceleratorW(hFrameWnd
, hAccel
, &msg
)
188 && !TranslateChildTabMessage(&msg
)) {
189 TranslateMessage(&msg
);
190 DispatchMessageW(&msg
);