c0b8ea9b6c1a5f9e02809b825849fd646ba59b24
[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 #ifdef _MSC_VER
24 #include "stdafx.h"
25 #else
26 #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
27 #include <windows.h>
28 #include <commctrl.h>
29 #include <stdlib.h>
30 #include <malloc.h>
31 #include <memory.h>
32 #include <tchar.h>
33 #include <process.h>
34 #include <stdio.h>
35 #endif
36
37 #include "main.h"
38 #include "framewnd.h"
39 #include "childwnd.h"
40
41
42 ////////////////////////////////////////////////////////////////////////////////
43 // Global Variables:
44 //
45
46 HINSTANCE hInst;
47 HWND hFrameWnd;
48 HWND hStatusBar;
49 HMENU hMenuFrame;
50
51 TCHAR szTitle[MAX_LOADSTRING];
52 TCHAR szFrameClass[MAX_LOADSTRING];
53 TCHAR szChildClass[MAX_LOADSTRING];
54
55
56 ////////////////////////////////////////////////////////////////////////////////
57 //
58 //
59 // FUNCTION: InitInstance(HANDLE, int)
60 //
61 // PURPOSE: Saves instance handle and creates main window
62 //
63 // COMMENTS:
64 //
65 // In this function, we save the instance handle in a global variable and
66 // create and display the main program window.
67 //
68
69 BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
70 {
71 WNDCLASSEX wcFrame = {
72 sizeof(WNDCLASSEX),
73 CS_HREDRAW | CS_VREDRAW/*style*/,
74 FrameWndProc,
75 0/*cbClsExtra*/,
76 0/*cbWndExtra*/,
77 hInstance,
78 LoadIcon(hInstance, MAKEINTRESOURCE(IDI_REGEDIT)),
79 LoadCursor(0, IDC_ARROW),
80 0/*hbrBackground*/,
81 0/*lpszMenuName*/,
82 szFrameClass,
83 (HICON)LoadImage(hInstance, MAKEINTRESOURCE(IDI_REGEDIT), IMAGE_ICON,
84 GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), LR_SHARED)
85 };
86 ATOM hFrameWndClass = RegisterClassEx(&wcFrame); // register frame window class
87
88 WNDCLASSEX wcChild = {
89 sizeof(WNDCLASSEX),
90 CS_HREDRAW | CS_VREDRAW/*style*/,
91 ChildWndProc,
92 0/*cbClsExtra*/,
93 sizeof(HANDLE)/*cbWndExtra*/,
94 hInstance,
95 LoadIcon(hInstance, MAKEINTRESOURCE(IDI_REGEDIT)),
96 LoadCursor(0, IDC_ARROW),
97 0/*hbrBackground*/,
98 0/*lpszMenuName*/,
99 szChildClass,
100 (HICON)LoadImage(hInstance, MAKEINTRESOURCE(IDI_REGEDIT), IMAGE_ICON,
101 GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), LR_SHARED)
102
103 };
104 ATOM hChildWndClass = RegisterClassEx(&wcChild); // register child windows class
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
141 int APIENTRY WinMain(HINSTANCE hInstance,
142 HINSTANCE hPrevInstance,
143 LPSTR lpCmdLine,
144 int nCmdShow)
145 {
146 MSG msg;
147 HACCEL hAccel;
148
149 // Initialize global strings
150 LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
151 LoadString(hInstance, IDC_REGEDIT_FRAME, szFrameClass, MAX_LOADSTRING);
152 LoadString(hInstance, IDC_REGEDIT, szChildClass, MAX_LOADSTRING);
153
154 // Store instance handle in our global variable
155 hInst = hInstance;
156
157 // Perform application initialization:
158 if (!InitInstance(hInstance, nCmdShow)) {
159 return FALSE;
160 }
161 hAccel = LoadAccelerators(hInstance, (LPCTSTR)IDC_REGEDIT);
162
163 // Main message loop:
164 while (GetMessage(&msg, (HWND)NULL, 0, 0)) {
165 if (!TranslateAccelerator(msg.hwnd, hAccel, &msg)) {
166 TranslateMessage(&msg);
167 DispatchMessage(&msg);
168 }
169 }
170 ExitInstance();
171 return msg.wParam;
172 }