regedit: Convert menu & statusbar handling to unicode.
[wine] / programs / 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 St, Fifth Floor, Boston, MA 02110-1301, 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 <stdlib.h>
25 #include <tchar.h>
26 #include <stdio.h>
27 #include <fcntl.h>
28
29 #define REGEDIT_DECLARE_FUNCTIONS
30 #include "main.h"
31
32 TCHAR g_pszDefaultValueName[64];
33 WCHAR g_pszDefaultValueNameW[64];
34
35 BOOL ProcessCmdLine(LPSTR lpCmdLine);
36
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};
43
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
47                                   };
48
49 /*******************************************************************************
50  * Global Variables:
51  */
52
53 HINSTANCE hInst;
54 HWND hFrameWnd;
55 HWND hStatusBar;
56 HMENU hMenuFrame;
57 HMENU hPopupMenus = 0;
58 UINT nClipboardFormat;
59 LPCTSTR strClipboardFormat = _T("TODO: SET CORRECT FORMAT");
60
61
62 #define MAX_LOADSTRING  100
63 TCHAR szTitle[MAX_LOADSTRING];
64 const TCHAR szFrameClass[] = {'R','E','G','E','D','I','T','_','F','R','A','M','E',0};
65 const TCHAR szChildClass[] = {'R','E','G','E','D','I','T',0};
66
67
68 /*******************************************************************************
69  *
70  *
71  *   FUNCTION: InitInstance(HANDLE, int)
72  *
73  *   PURPOSE: Saves instance handle and creates main window
74  *
75  *   COMMENTS:
76  *
77  *        In this function, we save the instance handle in a global variable and
78  *        create and display the main program window.
79  */
80
81 static BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
82 {
83     WCHAR empty = 0;
84     WNDCLASSEX wcFrame = {
85                              sizeof(WNDCLASSEX),
86                              CS_HREDRAW | CS_VREDRAW/*style*/,
87                              FrameWndProc,
88                              0/*cbClsExtra*/,
89                              0/*cbWndExtra*/,
90                              hInstance,
91                              LoadIcon(hInstance, MAKEINTRESOURCE(IDI_REGEDIT)),
92                              LoadCursor(0, IDC_ARROW),
93                              0/*hbrBackground*/,
94                              0/*lpszMenuName*/,
95                              szFrameClass,
96                              (HICON)LoadImage(hInstance, MAKEINTRESOURCE(IDI_REGEDIT), IMAGE_ICON,
97                                               GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), LR_SHARED)
98                          };
99     ATOM hFrameWndClass = RegisterClassEx(&wcFrame); /* register frame window class */
100
101     WNDCLASSEX wcChild = {
102                              sizeof(WNDCLASSEX),
103                              CS_HREDRAW | CS_VREDRAW/*style*/,
104                              ChildWndProc,
105                              0/*cbClsExtra*/,
106                              sizeof(HANDLE)/*cbWndExtra*/,
107                              hInstance,
108                              LoadIcon(hInstance, MAKEINTRESOURCE(IDI_REGEDIT)),
109                              LoadCursor(0, IDC_ARROW),
110                              0/*hbrBackground*/,
111                              0/*lpszMenuName*/,
112                              szChildClass,
113                              (HICON)LoadImage(hInstance, MAKEINTRESOURCE(IDI_REGEDIT), IMAGE_ICON,
114                                               GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), LR_SHARED)
115
116                          };
117     ATOM hChildWndClass = RegisterClassEx(&wcChild); /* register child windows class */
118     hChildWndClass = hChildWndClass; /* warning eater */
119
120     hMenuFrame = LoadMenuW(hInstance, MAKEINTRESOURCEW(IDR_REGEDIT_MENU));
121     hPopupMenus = LoadMenuW(hInstance, MAKEINTRESOURCEW(IDR_POPUP_MENUS));
122
123     /* Initialize the Windows Common Controls DLL */
124     InitCommonControls();
125
126     /* register our hex editor control */
127     HexEdit_Register();
128
129     nClipboardFormat = RegisterClipboardFormat(strClipboardFormat);
130     /* if (nClipboardFormat == 0) {
131         DWORD dwError = GetLastError();
132     } */
133
134     hFrameWnd = CreateWindowEx(0, MAKEINTRESOURCE(hFrameWndClass), szTitle,
135                                WS_OVERLAPPEDWINDOW | WS_EX_CLIENTEDGE,
136                                CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
137                                NULL, hMenuFrame, hInstance, NULL/*lpParam*/);
138
139     if (!hFrameWnd) {
140         return FALSE;
141     }
142
143     /* Create the status bar */
144     hStatusBar = CreateStatusWindowW(WS_VISIBLE|WS_CHILD|WS_CLIPSIBLINGS|SBT_NOBORDERS,
145                                     &empty, hFrameWnd, STATUS_WINDOW);
146     if (hStatusBar) {
147         /* Create the status bar panes */
148         SetupStatusBar(hFrameWnd, FALSE);
149         CheckMenuItem(GetSubMenu(hMenuFrame, ID_VIEW_MENU), ID_VIEW_STATUSBAR, MF_BYCOMMAND|MF_CHECKED);
150     }
151     ShowWindow(hFrameWnd, nCmdShow);
152     UpdateWindow(hFrameWnd);
153     return TRUE;
154 }
155
156 /******************************************************************************/
157
158 static void ExitInstance(void)
159 {
160     DestroyMenu(hMenuFrame);
161 }
162
163 static BOOL TranslateChildTabMessage(MSG *msg)
164 {
165     if (msg->message != WM_KEYDOWN) return FALSE;
166     if (msg->wParam != VK_TAB) return FALSE;
167     if (GetParent(msg->hwnd) != g_pChildWnd->hWnd) return FALSE;
168     PostMessage(g_pChildWnd->hWnd, WM_COMMAND, ID_SWITCH_PANELS, 0);
169     return TRUE;
170 }
171
172 int APIENTRY WinMain(HINSTANCE hInstance,
173                      HINSTANCE hPrevInstance,
174                      LPSTR     lpCmdLine,
175                      int       nCmdShow)
176 {
177     MSG msg;
178     HACCEL hAccel;
179
180     if (ProcessCmdLine(lpCmdLine)) {
181         return 0;
182     }
183
184     /* Initialize global strings */
185     LoadString(hInstance, IDS_APP_TITLE, szTitle, COUNT_OF(szTitle));
186     LoadString(hInstance, IDS_REGISTRY_DEFAULT_VALUE, g_pszDefaultValueName, COUNT_OF(g_pszDefaultValueName));
187     LoadStringW(hInstance, IDS_REGISTRY_DEFAULT_VALUE, g_pszDefaultValueNameW, COUNT_OF(g_pszDefaultValueNameW));
188
189     /* Store instance handle in our global variable */
190     hInst = hInstance;
191
192     /* Perform application initialization */
193     if (!InitInstance(hInstance, nCmdShow)) {
194         return FALSE;
195     }
196     hAccel = LoadAccelerators(hInstance, (LPCTSTR)IDC_REGEDIT);
197
198     /* Main message loop */
199     while (GetMessage(&msg, NULL, 0, 0)) {
200         if (!TranslateAccelerator(hFrameWnd, hAccel, &msg)
201            && !TranslateChildTabMessage(&msg)) {
202             TranslateMessage(&msg);
203             DispatchMessage(&msg);
204         }
205     }
206     ExitInstance();
207     return msg.wParam;
208 }