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