display the computer selection dialog for remote registry administration
[reactos.git] / reactos / subsys / system / regedit / main.c
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20
21 #define WIN32_LEAN_AND_MEAN /* Exclude rarely-used stuff from Windows headers */
22 #include <windows.h>
23 #include <commctrl.h>
24 #include <accctrl.h>
25 #include <unknwn.h>
26 #include <stdlib.h>
27 #include <tchar.h>
28 #include <process.h>
29 #include <stdio.h>
30 #include <fcntl.h>
31 #include <aclui.h>
32 #include <cguid.h>
33 #include <objbase.h>
34
35 #include "main.h"
36 #include "hexedit.h"
37 #include "security.h"
38
39 BOOL ProcessCmdLine(LPSTR lpCmdLine);
40
41
42 /*******************************************************************************
43 * Global Variables:
44 */
45
46 HINSTANCE hInst;
47 HWND hFrameWnd;
48 HWND hStatusBar;
49 HMENU hMenuFrame;
50 HMENU hPopupMenus = 0;
51 UINT nClipboardFormat;
52 LPCTSTR strClipboardFormat = _T("TODO: SET CORRECT FORMAT");
53
54
55 #define MAX_LOADSTRING 100
56 TCHAR szTitle[MAX_LOADSTRING];
57 TCHAR szFrameClass[MAX_LOADSTRING];
58 TCHAR szChildClass[MAX_LOADSTRING];
59
60
61 /*******************************************************************************
62 *
63 *
64 * FUNCTION: InitInstance(HANDLE, int)
65 *
66 * PURPOSE: Saves instance handle and creates main window
67 *
68 * COMMENTS:
69 *
70 * In this function, we save the instance handle in a global variable and
71 * create and display the main program window.
72 */
73
74 BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
75 {
76 BOOL AclUiAvailable;
77
78 WNDCLASSEX wcFrame = {
79 sizeof(WNDCLASSEX),
80 CS_HREDRAW | CS_VREDRAW/*style*/,
81 FrameWndProc,
82 0/*cbClsExtra*/,
83 0/*cbWndExtra*/,
84 hInstance,
85 LoadIcon(hInstance, MAKEINTRESOURCE(IDI_REGEDIT)),
86 LoadCursor(0, IDC_ARROW),
87 0/*hbrBackground*/,
88 0/*lpszMenuName*/,
89 szFrameClass,
90 (HICON)LoadImage(hInstance, MAKEINTRESOURCE(IDI_REGEDIT), IMAGE_ICON,
91 GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), LR_SHARED)
92 };
93 ATOM hFrameWndClass = RegisterClassEx(&wcFrame); /* register frame window class */
94
95 WNDCLASSEX wcChild = {
96 sizeof(WNDCLASSEX),
97 CS_HREDRAW | CS_VREDRAW/*style*/,
98 ChildWndProc,
99 0/*cbClsExtra*/,
100 sizeof(HANDLE)/*cbWndExtra*/,
101 hInstance,
102 LoadIcon(hInstance, MAKEINTRESOURCE(IDI_REGEDIT)),
103 LoadCursor(0, IDC_ARROW),
104 0/*hbrBackground*/,
105 0/*lpszMenuName*/,
106 szChildClass,
107 (HICON)LoadImage(hInstance, MAKEINTRESOURCE(IDI_REGEDIT), IMAGE_ICON,
108 GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), LR_SHARED)
109
110 };
111 ATOM hChildWndClass = RegisterClassEx(&wcChild); /* register child windows class */
112 hChildWndClass = hChildWndClass; /* warning eater */
113
114 RegisterHexEditorClass(hInstance);
115
116 hMenuFrame = LoadMenu(hInstance, MAKEINTRESOURCE(IDR_REGEDIT_MENU));
117 hPopupMenus = LoadMenu(hInstance, MAKEINTRESOURCE(IDR_POPUP_MENUS));
118
119 /* Initialize the Windows Common Controls DLL */
120 InitCommonControls();
121
122 HMENU hEditMenu;
123 hEditMenu = GetSubMenu(hMenuFrame, 1);
124
125 AclUiAvailable = InitializeAclUiDll();
126 if(!AclUiAvailable)
127 {
128 /* hide the Edit/Permissions... menu entry */
129 if(hEditMenu != NULL)
130 {
131 RemoveMenu(hEditMenu, ID_EDIT_PERMISSIONS, MF_BYCOMMAND);
132 /* remove the separator after the menu item */
133 RemoveMenu(hEditMenu, 4, MF_BYPOSITION);
134 }
135 }
136
137 if(hEditMenu != NULL)
138 SetMenuDefaultItem(hEditMenu, ID_EDIT_MODIFY, MF_BYCOMMAND);
139
140 nClipboardFormat = RegisterClipboardFormat(strClipboardFormat);
141 /* if (nClipboardFormat == 0) {
142 DWORD dwError = GetLastError();
143 } */
144
145 hFrameWnd = CreateWindowEx(WS_EX_WINDOWEDGE, (LPCTSTR)(int)hFrameWndClass, szTitle,
146 WS_OVERLAPPEDWINDOW | WS_CLIPSIBLINGS | WS_CLIPCHILDREN,
147 CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
148 NULL, hMenuFrame, hInstance, NULL/*lpParam*/);
149
150 if (!hFrameWnd) {
151 return FALSE;
152 }
153
154 /* Create the status bar */
155 hStatusBar = CreateStatusWindow(WS_VISIBLE|WS_CHILD|WS_CLIPSIBLINGS|SBT_NOBORDERS,
156 _T(""), hFrameWnd, STATUS_WINDOW);
157 if (hStatusBar) {
158 /* Create the status bar panes */
159 SetupStatusBar(hFrameWnd, FALSE);
160 CheckMenuItem(GetSubMenu(hMenuFrame, ID_VIEW_MENU), ID_VIEW_STATUSBAR, MF_BYCOMMAND|MF_CHECKED);
161 }
162 ShowWindow(hFrameWnd, nCmdShow);
163 UpdateWindow(hFrameWnd);
164 return TRUE;
165 }
166
167 /******************************************************************************/
168
169 void ExitInstance(HINSTANCE hInstance)
170 {
171 UnregisterHexEditorClass(hInstance);
172 DestroyMenu(hMenuFrame);
173 DestroyMenu(hPopupMenus);
174 UnloadAclUiDll();
175 }
176
177 BOOL TranslateChildTabMessage(MSG *msg)
178 {
179 if (msg->message != WM_KEYDOWN) return FALSE;
180 if (msg->wParam != VK_TAB) return FALSE;
181 if (GetParent(msg->hwnd) != g_pChildWnd->hWnd) return FALSE;
182 PostMessage(g_pChildWnd->hWnd, WM_COMMAND, ID_SWITCH_PANELS, 0);
183 return TRUE;
184 }
185
186 int APIENTRY WinMain(HINSTANCE hInstance,
187 HINSTANCE hPrevInstance,
188 LPSTR lpCmdLine,
189 int nCmdShow)
190 {
191 MSG msg;
192 HACCEL hAccel;
193 HRESULT hComInit;
194 /*
195 int hCrt;
196 FILE *hf;
197 AllocConsole();
198 hCrt = _open_osfhandle((long)GetStdHandle(STD_OUTPUT_HANDLE), _O_TEXT);
199 hf = _fdopen(hCrt, "w");
200 *stdout = *hf;
201 setvbuf(stdout, NULL, _IONBF, 0);
202
203 wprintf(L"command line exit, hInstance = %d\n", hInstance);
204 getch();
205 FreeConsole();
206 return 0;
207 */
208
209 if (ProcessCmdLine(lpCmdLine)) {
210 return 0;
211 }
212
213 /* Initialize global strings */
214 LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
215 LoadString(hInstance, IDC_REGEDIT_FRAME, szFrameClass, MAX_LOADSTRING);
216 LoadString(hInstance, IDC_REGEDIT, szChildClass, MAX_LOADSTRING);
217
218 /* Store instance handle in our global variable */
219 hInst = hInstance;
220
221 /* Perform application initialization */
222 if (!InitInstance(hInstance, nCmdShow)) {
223 return FALSE;
224 }
225 hAccel = LoadAccelerators(hInstance, (LPCTSTR)IDC_REGEDIT);
226
227 /* initialize the COM library for the remote registry object picker dialog */
228 hComInit = CoInitialize(NULL);
229
230 /* Main message loop */
231 while (GetMessage(&msg, (HWND)NULL, 0, 0)) {
232 if (!TranslateAccelerator(msg.hwnd, hAccel, &msg)
233 && !TranslateChildTabMessage(&msg)) {
234 TranslateMessage(&msg);
235 DispatchMessage(&msg);
236 }
237 }
238
239 if (SUCCEEDED(hComInit))
240 {
241 CoUninitialize();
242 }
243
244 ExitInstance(hInstance);
245 return msg.wParam;
246 }