Added command line handling from wine regedit, removed stdafx rubbish.
[reactos.git] / rosapps / regedit / main.c
1 /*
2 * ReactOS regedit
3 *
4 * main.c
5 *
6 * Copyright (C) 2002 Robert Dickenson <robd@reactos.org>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 */
22
23 #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
24 #include <windows.h>
25 #include <commctrl.h>
26 #include <stdlib.h>
27 #include <malloc.h>
28 #include <memory.h>
29 #include <tchar.h>
30 #include <process.h>
31 #include <stdio.h>
32
33 #include "main.h"
34 #include "framewnd.h"
35 #include "childwnd.h"
36
37
38 BOOL ProcessCmdLine(LPSTR lpCmdLine);
39
40
41 ////////////////////////////////////////////////////////////////////////////////
42 // Global Variables:
43 //
44
45 HINSTANCE hInst;
46 HWND hFrameWnd;
47 HWND hStatusBar;
48 HMENU hMenuFrame;
49
50 TCHAR szTitle[MAX_LOADSTRING];
51 TCHAR szFrameClass[MAX_LOADSTRING];
52 TCHAR szChildClass[MAX_LOADSTRING];
53
54
55 ////////////////////////////////////////////////////////////////////////////////
56 //
57 //
58 // FUNCTION: InitInstance(HANDLE, int)
59 //
60 // PURPOSE: Saves instance handle and creates main window
61 //
62 // COMMENTS:
63 //
64 // In this function, we save the instance handle in a global variable and
65 // create and display the main program window.
66 //
67
68 BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
69 {
70 WNDCLASSEX wcFrame = {
71 sizeof(WNDCLASSEX),
72 CS_HREDRAW | CS_VREDRAW/*style*/,
73 FrameWndProc,
74 0/*cbClsExtra*/,
75 0/*cbWndExtra*/,
76 hInstance,
77 LoadIcon(hInstance, MAKEINTRESOURCE(IDI_REGEDIT)),
78 LoadCursor(0, IDC_ARROW),
79 0/*hbrBackground*/,
80 0/*lpszMenuName*/,
81 szFrameClass,
82 (HICON)LoadImage(hInstance, MAKEINTRESOURCE(IDI_REGEDIT), IMAGE_ICON,
83 GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), LR_SHARED)
84 };
85 ATOM hFrameWndClass = RegisterClassEx(&wcFrame); // register frame window class
86
87 WNDCLASSEX wcChild = {
88 sizeof(WNDCLASSEX),
89 CS_HREDRAW | CS_VREDRAW/*style*/,
90 ChildWndProc,
91 0/*cbClsExtra*/,
92 sizeof(HANDLE)/*cbWndExtra*/,
93 hInstance,
94 LoadIcon(hInstance, MAKEINTRESOURCE(IDI_REGEDIT)),
95 LoadCursor(0, IDC_ARROW),
96 0/*hbrBackground*/,
97 0/*lpszMenuName*/,
98 szChildClass,
99 (HICON)LoadImage(hInstance, MAKEINTRESOURCE(IDI_REGEDIT), IMAGE_ICON,
100 GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), LR_SHARED)
101
102 };
103 ATOM hChildWndClass = RegisterClassEx(&wcChild); // register child windows class
104 hChildWndClass = hChildWndClass; // warning eater
105
106 hMenuFrame = LoadMenu(hInstance, MAKEINTRESOURCE(IDR_REGEDIT_MENU));
107
108 // Initialize the Windows Common Controls DLL
109 InitCommonControls();
110
111 hFrameWnd = CreateWindowEx(0, (LPCTSTR)(int)hFrameWndClass, szTitle,
112 WS_OVERLAPPEDWINDOW | WS_EX_CLIENTEDGE,
113 CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
114 NULL, hMenuFrame, hInstance, NULL/*lpParam*/);
115
116 if (!hFrameWnd) {
117 return FALSE;
118 }
119
120 // Create the status bar
121 hStatusBar = CreateStatusWindow(WS_VISIBLE|WS_CHILD|WS_CLIPSIBLINGS|SBT_NOBORDERS,
122 _T(""), hFrameWnd, STATUS_WINDOW);
123 if (hStatusBar) {
124 // Create the status bar panes
125 SetupStatusBar(hFrameWnd, FALSE);
126 CheckMenuItem(GetSubMenu(hMenuFrame, ID_VIEW_MENU), ID_VIEW_STATUSBAR, MF_BYCOMMAND|MF_CHECKED);
127 }
128 ShowWindow(hFrameWnd, nCmdShow);
129 UpdateWindow(hFrameWnd);
130 return TRUE;
131 }
132
133 ////////////////////////////////////////////////////////////////////////////////
134
135 void ExitInstance(void)
136 {
137 DestroyMenu(hMenuFrame);
138 }
139
140 int APIENTRY WinMain(HINSTANCE hInstance,
141 HINSTANCE hPrevInstance,
142 LPSTR lpCmdLine,
143 int nCmdShow)
144 {
145 MSG msg;
146 HACCEL hAccel;
147
148 if (ProcessCmdLine(lpCmdLine)) {
149 return 0;
150 }
151
152 // Initialize global strings
153 LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
154 LoadString(hInstance, IDC_REGEDIT_FRAME, szFrameClass, MAX_LOADSTRING);
155 LoadString(hInstance, IDC_REGEDIT, szChildClass, MAX_LOADSTRING);
156
157 // Store instance handle in our global variable
158 hInst = hInstance;
159
160 // Perform application initialization:
161 if (!InitInstance(hInstance, nCmdShow)) {
162 return FALSE;
163 }
164 hAccel = LoadAccelerators(hInstance, (LPCTSTR)IDC_REGEDIT);
165
166 // Main message loop:
167 while (GetMessage(&msg, (HWND)NULL, 0, 0)) {
168 if (!TranslateAccelerator(msg.hwnd, hAccel, &msg)) {
169 TranslateMessage(&msg);
170 DispatchMessage(&msg);
171 }
172 }
173 ExitInstance();
174 return msg.wParam;
175 }