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 */
25 #include "wine/debug.h"
27 #define REGEDIT_DECLARE_FUNCTIONS
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 /*******************************************************************************
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
)
60 WNDCLASSEXW wndclass
= {0};
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
);
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 */
87 /* register our hex editor control */
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*/);
101 /* Create the status bar */
102 hStatusBar
= CreateStatusWindowW(WS_VISIBLE
|WS_CHILD
|WS_CLIPSIBLINGS
|SBT_NOBORDERS
,
103 &empty
, hFrameWnd
, STATUS_WINDOW
);
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
);
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);
130 int WINAPI
wWinMain(HINSTANCE hInstance
, HINSTANCE hPrevInstance
, LPWSTR lpCmdLine
, int nCmdShow
)
136 if (ProcessCmdLine(GetCommandLineW())) {
140 if (IsWow64Process( GetCurrentProcess(), &is_wow64
) && is_wow64
)
142 static const WCHAR filename
[] = L
"C:\\windows\\regedit.exe";
144 PROCESS_INFORMATION pi
;
148 memset( &si
, 0, 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 */
172 /* Perform application initialization */
173 if (!InitInstance(hInstance
, nCmdShow
)) {
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
);