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