Added framework for new application - calc.
[reactos.git] / rosapps / calc / main.c
1 /*
2 * ReactOS calc
3 *
4 * calc.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 <tchar.h>
26
27 #include "main.h"
28 #include "button.h"
29 #include "settings.h"
30
31
32 // Global Variables:
33 HINSTANCE hInst;
34 HWND hDlgWnd;
35 CALC_TYPES CalcType;
36
37 BOOL bDigitGrouping = FALSE;
38
39
40 #define BEGIN_CMD_MAP(a) switch(##a) {
41 #define CMD_MAP_ENTRY(a, b) case a: b(); break;
42 #define END_CMD_MAP(a) }
43
44
45 BOOL OnCreate(HWND hWnd)
46 {
47 HMENU hMenu;
48 HMENU hViewMenu;
49
50 hMenu = GetMenu(hDlgWnd);
51 hViewMenu = GetSubMenu(hMenu, ID_MENU_VIEW);
52 if (bDigitGrouping) {
53 CheckMenuItem(hViewMenu, ID_VIEW_DIGIT_GROUPING, MF_BYCOMMAND|MF_CHECKED);
54 }
55
56 //SendMessage(hDlgWnd, WM_SETICON, ICON_BIG, (LPARAM)LoadIcon(hInst, MAKEINTRESOURCE(IDI_CALC)));
57
58 // Initialize the Windows Common Controls DLL
59 //InitCommonControls();
60
61 return TRUE;
62 }
63
64 void OnEditCopy(void)
65 {
66 SendMessage(GetDlgItem(hDlgWnd, IDC_EDIT1), WM_COMMAND, MAKELONG(ID_EDIT_COPY, 0), 0);
67 }
68
69 void OnEditPaste(void)
70 {
71 SendMessage(GetDlgItem(hDlgWnd, IDC_EDIT1), WM_COMMAND, MAKELONG(ID_EDIT_PASTE, 0), 0);
72 }
73
74 void OnViewStandard(void)
75 {
76 CalcType = STANDARD;
77 DestroyWindow(hDlgWnd);
78 }
79
80 void OnViewScientific(void)
81 {
82 CalcType = SCIENTIFIC;
83 DestroyWindow(hDlgWnd);
84 }
85
86 void OnViewDigitGrouping(void)
87 {
88 HMENU hMenu = GetMenu(hDlgWnd);
89 HMENU hViewMenu = GetSubMenu(hMenu, ID_MENU_VIEW);
90 bDigitGrouping = !bDigitGrouping;
91 if (bDigitGrouping) {
92 CheckMenuItem(hViewMenu, ID_VIEW_DIGIT_GROUPING, MF_BYCOMMAND|MF_CHECKED);
93 } else {
94 CheckMenuItem(hViewMenu, ID_VIEW_DIGIT_GROUPING, MF_BYCOMMAND|MF_UNCHECKED);
95 }
96 }
97
98 void OnHelpTopics(void)
99 {
100 WinHelp(hDlgWnd, _T("calc"), HELP_CONTENTS, 0);
101 }
102
103 void OnHelpAbout(void)
104 {
105 }
106
107 // Message handler for dialog box.
108 LRESULT CALLBACK CalcWndProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
109 {
110 switch (message) {
111 case WM_INITDIALOG:
112 hDlgWnd = hDlg;
113 InitColours();
114 return OnCreate(hDlg);
115
116 case WM_DRAWITEM:
117 DrawItem((LPDRAWITEMSTRUCT)lParam);
118 return TRUE;
119
120 case WM_COMMAND:
121 if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL) {
122 EndDialog(hDlg, LOWORD(wParam));
123 return TRUE;
124 }
125
126 if (HIWORD(wParam) == BN_CLICKED) {
127 switch (LOWORD(wParam)) {
128 // case IDC_OWNERDRAW:
129 // // application-defined processing
130 // break;
131 }
132 }
133
134 BEGIN_CMD_MAP(LOWORD(wParam))
135 CMD_MAP_ENTRY(ID_EDIT_COPY, OnEditCopy)
136 CMD_MAP_ENTRY(ID_EDIT_PASTE, OnEditPaste)
137 CMD_MAP_ENTRY(ID_VIEW_STANDARD, OnViewStandard)
138 CMD_MAP_ENTRY(ID_VIEW_SCIENTIFIC, OnViewScientific)
139 CMD_MAP_ENTRY(ID_VIEW_DIGIT_GROUPING, OnViewDigitGrouping)
140 CMD_MAP_ENTRY(ID_HELP_TOPICS, OnHelpTopics)
141 CMD_MAP_ENTRY(ID_HELP_ABOUT, OnHelpAbout)
142 END_CMD_MAP(0)
143 break;
144
145 case WM_NOTIFY:
146 {
147 int idctrl;
148 LPNMHDR pnmh;
149 idctrl = (int)wParam;
150 pnmh = (LPNMHDR)lParam;
151 /*
152 if ((pnmh->hwndFrom == hTabWnd) &&
153 (pnmh->idFrom == IDC_TAB) &&
154 (pnmh->code == TCN_SELCHANGE))
155 {
156 _OnTabWndSelChange();
157 }
158 */
159 }
160 break;
161
162 case WM_DESTROY:
163 WinHelp(hDlgWnd, _T("regedit"), HELP_QUIT, 0);
164 return DefWindowProc(hDlg, message, wParam, lParam);
165 }
166 return 0;
167 }
168
169 int APIENTRY WinMain(HINSTANCE hInstance,
170 HINSTANCE hPrevInstance,
171 LPSTR lpCmdLine,
172 int nCmdShow)
173 {
174 CALC_TYPES CurrentCalcType;
175
176 // Initialize global variables
177 hInst = hInstance;
178
179 // Load our settings from the registry
180 LoadSettings();
181
182 do {
183 CurrentCalcType = CalcType;
184 switch (CalcType) {
185 case HP42S:
186 break;
187 case SCIENTIFIC:
188 DialogBox(hInst, (LPCTSTR)IDD_SCIENTIFIC, NULL, (DLGPROC)CalcWndProc);
189 break;
190 case STANDARD:
191 default:
192 DialogBox(hInst, (LPCTSTR)IDD_STANDARD, NULL, (DLGPROC)CalcWndProc);
193 break;
194 }
195 } while (CalcType != CurrentCalcType);
196
197 // Save our settings to the registry
198 SaveSettings();
199 return 0;
200 }
201