Basic Control Panel created.
[reactos.git] / rosapps / control / main.c
1 /*
2 * ReactOS control
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
36
37 ////////////////////////////////////////////////////////////////////////////////
38 // Global Variables:
39 //
40
41 HINSTANCE hInst;
42 HWND hFrameWnd;
43 HWND hStatusBar;
44 HMENU hMenuFrame;
45
46 TCHAR szTitle[MAX_LOADSTRING];
47 TCHAR szWindowClass[MAX_LOADSTRING];
48
49
50 ////////////////////////////////////////////////////////////////////////////////
51 //
52 //
53 // FUNCTION: InitInstance(HANDLE, int)
54 //
55 // PURPOSE: Saves instance handle and creates main window
56 //
57 // COMMENTS:
58 //
59 // In this function, we save the instance handle in a global variable and
60 // create and display the main program window.
61 //
62
63 BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
64 {
65 WNDCLASSEX wcFrame = {
66 sizeof(WNDCLASSEX),
67 CS_HREDRAW | CS_VREDRAW/*style*/,
68 FrameWndProc,
69 0/*cbClsExtra*/,
70 0/*cbWndExtra*/,
71 hInstance,
72 LoadIcon(hInstance, MAKEINTRESOURCE(IDI_CONTROL)),
73 LoadCursor(0, IDC_ARROW),
74 0/*hbrBackground*/,
75 0/*lpszMenuName*/,
76 szWindowClass,
77 (HICON)LoadImage(hInstance, MAKEINTRESOURCE(IDI_CONTROL), IMAGE_ICON,
78 GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), LR_SHARED)
79 };
80 ATOM hFrameWndClass = RegisterClassEx(&wcFrame); // register frame window class
81
82 hMenuFrame = LoadMenu(hInstance, MAKEINTRESOURCE(IDR_CONTROL_MENU));
83
84 // Initialize the Windows Common Controls DLL
85 InitCommonControls();
86
87 hFrameWnd = CreateWindowEx(0, (LPCTSTR)(int)hFrameWndClass, szTitle,
88 WS_OVERLAPPEDWINDOW | WS_EX_CLIENTEDGE,
89 CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
90 NULL, hMenuFrame, hInstance, NULL/*lpParam*/);
91
92 if (!hFrameWnd) {
93 return FALSE;
94 }
95
96 // Create the status bar
97 hStatusBar = CreateStatusWindow(WS_VISIBLE|WS_CHILD|WS_CLIPSIBLINGS|SBT_NOBORDERS,
98 _T(""), hFrameWnd, STATUS_WINDOW);
99 if (hStatusBar) {
100 // Create the status bar panes
101 SetupStatusBar(hFrameWnd, FALSE);
102 CheckMenuItem(GetSubMenu(hMenuFrame, ID_VIEW_MENU), ID_VIEW_STATUSBAR, MF_BYCOMMAND|MF_CHECKED);
103 }
104 ShowWindow(hFrameWnd, nCmdShow);
105 UpdateWindow(hFrameWnd);
106 return TRUE;
107 }
108
109 ////////////////////////////////////////////////////////////////////////////////
110
111 void ExitInstance(void)
112 {
113 DestroyMenu(hMenuFrame);
114 }
115
116
117 int APIENTRY WinMain(HINSTANCE hInstance,
118 HINSTANCE hPrevInstance,
119 LPSTR lpCmdLine,
120 int nCmdShow)
121 {
122 MSG msg;
123 HACCEL hAccel;
124
125 // Initialize global strings
126 LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
127 LoadString(hInstance, IDC_CONTROL, szWindowClass, MAX_LOADSTRING);
128
129 // Store instance handle in our global variable
130 hInst = hInstance;
131
132 // Perform application initialization:
133 if (!InitInstance(hInstance, nCmdShow)) {
134 return FALSE;
135 }
136 hAccel = LoadAccelerators(hInstance, (LPCTSTR)IDC_CONTROL);
137
138 // Main message loop:
139 while (GetMessage(&msg, (HWND)NULL, 0, 0)) {
140 if (!TranslateAccelerator(msg.hwnd, hAccel, &msg)) {
141 TranslateMessage(&msg);
142 DispatchMessage(&msg);
143 }
144 }
145 ExitInstance();
146 return msg.wParam;
147 }