[SNDVOL32] Add the small line dialog
[reactos.git] / base / applications / 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21 #include "regedit.h"
22
23 BOOL ProcessCmdLine(LPWSTR lpCmdLine);
24
25 /*******************************************************************************
26 * Global Variables:
27 */
28
29 HINSTANCE hInst;
30 HWND hFrameWnd;
31 HWND hStatusBar;
32 HMENU hMenuFrame;
33 HMENU hPopupMenus = 0;
34 UINT nClipboardFormat;
35 LPCWSTR strClipboardFormat = L"TODO: SET CORRECT FORMAT";
36
37 #define MAX_LOADSTRING 100
38 WCHAR szTitle[MAX_LOADSTRING];
39 WCHAR szFrameClass[MAX_LOADSTRING];
40 WCHAR szChildClass[MAX_LOADSTRING];
41
42
43 /*******************************************************************************
44 *
45 *
46 * FUNCTION: InitInstance(HANDLE, int)
47 *
48 * PURPOSE: Saves instance handle and creates main window
49 *
50 * COMMENTS:
51 *
52 * In this function, we save the instance handle in a global variable and
53 * create and display the main program window.
54 */
55
56 BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
57 {
58 BOOL AclUiAvailable;
59 HMENU hEditMenu;
60
61 WNDCLASSEXW wcFrame;
62 WNDCLASSEXW wcChild;
63 ATOM hFrameWndClass;
64
65 ZeroMemory(&wcFrame, sizeof(WNDCLASSEXW));
66 wcFrame.cbSize = sizeof(WNDCLASSEXW);
67 wcFrame.lpfnWndProc = FrameWndProc;
68 wcFrame.hInstance = hInstance;
69 wcFrame.hIcon = LoadIconW(hInstance, MAKEINTRESOURCEW(IDI_REGEDIT));
70 wcFrame.hIconSm = (HICON)LoadImageW(hInstance, MAKEINTRESOURCEW(IDI_REGEDIT),
71 IMAGE_ICON, GetSystemMetrics(SM_CXSMICON),
72 GetSystemMetrics(SM_CYSMICON), LR_SHARED);
73 wcFrame.hCursor = LoadCursorW(NULL, IDC_ARROW);
74 wcFrame.lpszClassName = szFrameClass;
75
76 hFrameWndClass = RegisterClassExW(&wcFrame); /* register frame window class */
77
78 ZeroMemory(&wcChild, sizeof(WNDCLASSEXW));
79 wcChild.cbSize = sizeof(WNDCLASSEXW);
80 wcChild.lpfnWndProc = ChildWndProc;
81 wcChild.cbWndExtra = sizeof(HANDLE);
82 wcChild.hInstance = hInstance;
83 wcChild.hIcon = LoadIconW(hInstance, MAKEINTRESOURCEW(IDI_REGEDIT));
84 wcChild.hCursor = LoadCursorW(NULL, IDC_ARROW);
85 wcChild.lpszClassName = szChildClass;
86 wcChild.hIconSm = (HICON)LoadImageW(hInstance, MAKEINTRESOURCEW(IDI_REGEDIT),
87 IMAGE_ICON, GetSystemMetrics(SM_CXSMICON),
88 GetSystemMetrics(SM_CYSMICON), LR_SHARED);
89
90 RegisterClassExW(&wcChild); /* register child windows class */
91
92 RegisterHexEditorClass(hInstance);
93
94 hMenuFrame = LoadMenuW(hInstance, MAKEINTRESOURCEW(IDR_REGEDIT_MENU));
95 hPopupMenus = LoadMenuW(hInstance, MAKEINTRESOURCEW(IDR_POPUP_MENUS));
96
97 /* Initialize the Windows Common Controls DLL */
98 // TODO: Replace this call by InitCommonControlsEx(_something_)
99 InitCommonControls();
100
101 hEditMenu = GetSubMenu(hMenuFrame, 1);
102
103 AclUiAvailable = InitializeAclUiDll();
104 if(!AclUiAvailable)
105 {
106 /* hide the Edit/Permissions... menu entry */
107 if(hEditMenu != NULL)
108 {
109 RemoveMenu(hEditMenu, ID_EDIT_PERMISSIONS, MF_BYCOMMAND);
110 /* remove the separator after the menu item */
111 RemoveMenu(hEditMenu, 4, MF_BYPOSITION);
112 }
113 }
114
115 if(hEditMenu != NULL)
116 SetMenuDefaultItem(hEditMenu, ID_EDIT_MODIFY, MF_BYCOMMAND);
117
118 nClipboardFormat = RegisterClipboardFormatW(strClipboardFormat);
119 /* if (nClipboardFormat == 0) {
120 DWORD dwError = GetLastError();
121 } */
122
123 hFrameWnd = CreateWindowExW(WS_EX_WINDOWEDGE, (LPCWSTR)(UlongToPtr(hFrameWndClass)), szTitle,
124 WS_OVERLAPPEDWINDOW | WS_CLIPSIBLINGS | WS_CLIPCHILDREN,
125 CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
126 NULL, hMenuFrame, hInstance, NULL/*lpParam*/);
127
128 if (!hFrameWnd)
129 {
130 return FALSE;
131 }
132
133 /* Create the status bar */
134 hStatusBar = CreateStatusWindowW(WS_VISIBLE | WS_CHILD | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | SBT_NOBORDERS,
135 L"", hFrameWnd, STATUS_WINDOW);
136 if (hStatusBar)
137 {
138 /* Create the status bar panes */
139 SetupStatusBar(hFrameWnd, FALSE);
140 CheckMenuItem(GetSubMenu(hMenuFrame, ID_VIEW_MENU), ID_VIEW_STATUSBAR, MF_BYCOMMAND | MF_CHECKED);
141 }
142
143 LoadSettings();
144 UpdateWindow(hFrameWnd);
145 return TRUE;
146 }
147
148 /******************************************************************************/
149
150 /*
151 * We need to destroy the main menu before destroying the main window
152 * to avoid a memory leak.
153 */
154
155 void DestroyMainMenu()
156 {
157 DestroyMenu(hMenuFrame);
158 }
159
160 /******************************************************************************/
161
162 void ExitInstance(HINSTANCE hInstance)
163 {
164 UnregisterHexEditorClass(hInstance);
165
166 DestroyMenu(hPopupMenus);
167 UnloadAclUiDll();
168 }
169
170 BOOL TranslateChildTabMessage(PMSG msg)
171 {
172 if (msg->message != WM_KEYDOWN) return FALSE;
173
174 /* Allow Ctrl+A on address bar */
175 if ((msg->hwnd == g_pChildWnd->hAddressBarWnd) &&
176 (msg->message == WM_KEYDOWN) &&
177 (msg->wParam == L'A') && (GetKeyState(VK_CONTROL) < 0))
178 {
179 SendMessageW(msg->hwnd, EM_SETSEL, 0, -1);
180 return TRUE;
181 }
182
183 if (msg->wParam != VK_TAB) return FALSE;
184 if (GetParent(msg->hwnd) != g_pChildWnd->hWnd) return FALSE;
185 PostMessageW(g_pChildWnd->hWnd, WM_COMMAND, ID_SWITCH_PANELS, 0);
186 return TRUE;
187 }
188
189 int APIENTRY wWinMain(HINSTANCE hInstance,
190 HINSTANCE hPrevInstance,
191 LPWSTR lpCmdLine,
192 int nCmdShow)
193 {
194 MSG msg;
195 HACCEL hAccel;
196
197 UNREFERENCED_PARAMETER(hPrevInstance);
198
199 /* Initialize global strings */
200 LoadStringW(hInstance, IDS_APP_TITLE, szTitle, COUNT_OF(szTitle));
201 LoadStringW(hInstance, IDC_REGEDIT_FRAME, szFrameClass, COUNT_OF(szFrameClass));
202 LoadStringW(hInstance, IDC_REGEDIT, szChildClass, COUNT_OF(szChildClass));
203
204 if (ProcessCmdLine(lpCmdLine))
205 {
206 return 0;
207 }
208
209 switch (GetUserDefaultUILanguage())
210 {
211 case MAKELANGID(LANG_HEBREW, SUBLANG_DEFAULT):
212 SetProcessDefaultLayout(LAYOUT_RTL);
213 break;
214
215 default:
216 break;
217 }
218 /* Store instance handle in our global variable */
219 hInst = hInstance;
220
221 /* Perform application initialization */
222 if (!InitInstance(hInstance, nCmdShow))
223 {
224 return 0;
225 }
226 hAccel = LoadAcceleratorsW(hInstance, MAKEINTRESOURCEW(ID_ACCEL));
227
228 /* Main message loop */
229 while (GetMessageW(&msg, NULL, 0, 0))
230 {
231 if (!TranslateAcceleratorW(hFrameWnd, hAccel, &msg) &&
232 !TranslateChildTabMessage(&msg))
233 {
234 TranslateMessage(&msg);
235 DispatchMessageW(&msg);
236 }
237 }
238
239 ExitInstance(hInstance);
240 return (int)msg.wParam;
241 }
242
243 /* EOF */