ieframe: Moved dialog resources to ieframe.
[wine/testsucceed.git] / programs / regedit / main.c
blobd764702e24e5b50548eaa1967b69cedbd03b0568
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 <tchar.h>
26 #include <stdio.h>
27 #include <fcntl.h>
29 #define REGEDIT_DECLARE_FUNCTIONS
30 #include "main.h"
32 WCHAR g_pszDefaultValueName[64];
34 BOOL ProcessCmdLine(LPSTR lpCmdLine);
36 static const WCHAR hkey_local_machine[] = {'H','K','E','Y','_','L','O','C','A','L','_','M','A','C','H','I','N','E',0};
37 static const WCHAR hkey_users[] = {'H','K','E','Y','_','U','S','E','R','S',0};
38 static const WCHAR hkey_classes_root[] = {'H','K','E','Y','_','C','L','A','S','S','E','S','_','R','O','O','T',0};
39 static const WCHAR hkey_current_config[] = {'H','K','E','Y','_','C','U','R','R','E','N','T','_','C','O','N','F','I','G',0};
40 static const WCHAR hkey_current_user[] = {'H','K','E','Y','_','C','U','R','R','E','N','T','_','U','S','E','R',0};
41 static const WCHAR hkey_dyn_data[] = {'H','K','E','Y','_','D','Y','N','_','D','A','T','A',0};
43 const WCHAR *reg_class_namesW[] = {hkey_local_machine, hkey_users,
44 hkey_classes_root, hkey_current_config,
45 hkey_current_user, hkey_dyn_data
48 /*******************************************************************************
49 * Global Variables:
52 HINSTANCE hInst;
53 HWND hFrameWnd;
54 HWND hStatusBar;
55 HMENU hMenuFrame;
56 HMENU hPopupMenus = 0;
57 UINT nClipboardFormat;
58 const WCHAR strClipboardFormat[] = {'T','O','D','O',':',' ','S','E','T',' ','C','O','R','R','E','C','T',' ','F','O','R','M','A','T',0};
61 #define MAX_LOADSTRING 100
62 WCHAR szTitle[MAX_LOADSTRING];
63 const WCHAR szFrameClass[] = {'R','E','G','E','D','I','T','_','F','R','A','M','E',0};
64 const WCHAR szChildClass[] = {'R','E','G','E','D','I','T',0};
66 static BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
68 WCHAR empty = 0;
69 WNDCLASSEXW wndclass = {0};
71 /* Frame class */
72 wndclass.cbSize = sizeof(WNDCLASSEXW);
73 wndclass.style = CS_HREDRAW | CS_VREDRAW;
74 wndclass.lpfnWndProc = FrameWndProc;
75 wndclass.hInstance = hInstance;
76 wndclass.hIcon = LoadIconW(hInstance, MAKEINTRESOURCEW(IDI_REGEDIT));
77 wndclass.hCursor = LoadCursorW(0, (LPCWSTR)IDC_ARROW);
78 wndclass.lpszClassName = szFrameClass;
79 wndclass.hIconSm = LoadImageW(hInstance, MAKEINTRESOURCEW(IDI_REGEDIT), IMAGE_ICON,
80 GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), LR_SHARED);
81 RegisterClassExW(&wndclass);
83 /* Child class */
84 wndclass.lpfnWndProc = ChildWndProc;
85 wndclass.cbWndExtra = sizeof(HANDLE);
86 wndclass.lpszClassName = szChildClass;
87 RegisterClassExW(&wndclass);
89 hMenuFrame = LoadMenuW(hInstance, MAKEINTRESOURCEW(IDR_REGEDIT_MENU));
90 hPopupMenus = LoadMenuW(hInstance, MAKEINTRESOURCEW(IDR_POPUP_MENUS));
92 /* Initialize the Windows Common Controls DLL */
93 InitCommonControls();
95 /* register our hex editor control */
96 HexEdit_Register();
98 nClipboardFormat = RegisterClipboardFormatW(strClipboardFormat);
100 hFrameWnd = CreateWindowExW(0, szFrameClass, szTitle,
101 WS_OVERLAPPEDWINDOW | WS_EX_CLIENTEDGE,
102 CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
103 NULL, hMenuFrame, hInstance, NULL/*lpParam*/);
105 if (!hFrameWnd) {
106 return FALSE;
109 /* Create the status bar */
110 hStatusBar = CreateStatusWindowW(WS_VISIBLE|WS_CHILD|WS_CLIPSIBLINGS|SBT_NOBORDERS,
111 &empty, hFrameWnd, STATUS_WINDOW);
112 if (hStatusBar) {
113 /* Create the status bar panes */
114 SetupStatusBar(hFrameWnd, FALSE);
115 CheckMenuItem(GetSubMenu(hMenuFrame, ID_VIEW_MENU), ID_VIEW_STATUSBAR, MF_BYCOMMAND|MF_CHECKED);
117 ShowWindow(hFrameWnd, nCmdShow);
118 UpdateWindow(hFrameWnd);
119 return TRUE;
122 /******************************************************************************/
124 static void ExitInstance(void)
126 DestroyMenu(hMenuFrame);
129 static BOOL TranslateChildTabMessage(MSG *msg)
131 if (msg->message != WM_KEYDOWN) return FALSE;
132 if (msg->wParam != VK_TAB) return FALSE;
133 if (GetParent(msg->hwnd) != g_pChildWnd->hWnd) return FALSE;
134 PostMessageW(g_pChildWnd->hWnd, WM_COMMAND, ID_SWITCH_PANELS, 0);
135 return TRUE;
138 int APIENTRY WinMain(HINSTANCE hInstance,
139 HINSTANCE hPrevInstance,
140 LPSTR lpCmdLine,
141 int nCmdShow)
143 MSG msg;
144 HACCEL hAccel;
146 if (ProcessCmdLine(lpCmdLine)) {
147 return 0;
150 /* Initialize global strings */
151 LoadStringW(hInstance, IDS_APP_TITLE, szTitle, COUNT_OF(szTitle));
152 LoadStringW(hInstance, IDS_REGISTRY_DEFAULT_VALUE, g_pszDefaultValueName, COUNT_OF(g_pszDefaultValueName));
154 /* Store instance handle in our global variable */
155 hInst = hInstance;
157 /* Perform application initialization */
158 if (!InitInstance(hInstance, nCmdShow)) {
159 return FALSE;
161 hAccel = LoadAcceleratorsW(hInstance, MAKEINTRESOURCEW(IDC_REGEDIT));
163 /* Main message loop */
164 while (GetMessageW(&msg, NULL, 0, 0)) {
165 if (!TranslateAcceleratorW(hFrameWnd, hAccel, &msg)
166 && !TranslateChildTabMessage(&msg)) {
167 TranslateMessage(&msg);
168 DispatchMessageW(&msg);
171 ExitInstance();
172 return msg.wParam;