2002-07-16 19:15:12 +00:00
|
|
|
/*
|
|
|
|
* ReactOS calc
|
|
|
|
*
|
|
|
|
* calc.c
|
|
|
|
*
|
|
|
|
* Copyright (C) 2002 Robert Dickenson <robd@reactos.org>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
|
|
|
|
#include <windows.h>
|
2004-01-18 03:28:08 +00:00
|
|
|
#include <shellapi.h>
|
2002-07-16 19:15:12 +00:00
|
|
|
#include <tchar.h>
|
|
|
|
|
|
|
|
#include "main.h"
|
|
|
|
#include "button.h"
|
|
|
|
#include "settings.h"
|
|
|
|
|
|
|
|
|
|
|
|
// Global Variables:
|
|
|
|
HINSTANCE hInst;
|
|
|
|
HWND hDlgWnd;
|
2002-07-16 21:54:17 +00:00
|
|
|
TCHAR szTitle[MAX_LOADSTRING];
|
2002-07-16 19:15:12 +00:00
|
|
|
CALC_TYPES CalcType;
|
2002-07-16 21:54:17 +00:00
|
|
|
HACCEL hAccel;
|
2002-07-16 19:15:12 +00:00
|
|
|
|
|
|
|
BOOL bDigitGrouping = FALSE;
|
|
|
|
|
2004-01-15 05:27:18 +00:00
|
|
|
/*TODO: Figure out why we are copying MFC map style programming.
|
|
|
|
** This pattern is difficult to maintain.
|
|
|
|
*/
|
2002-07-16 19:15:12 +00:00
|
|
|
#define BEGIN_CMD_MAP(a) switch(##a) {
|
|
|
|
#define CMD_MAP_ENTRY(a, b) case a: b(); break;
|
|
|
|
#define END_CMD_MAP(a) }
|
|
|
|
|
|
|
|
|
|
|
|
BOOL OnCreate(HWND hWnd)
|
|
|
|
{
|
|
|
|
HMENU hMenu;
|
|
|
|
HMENU hViewMenu;
|
|
|
|
|
|
|
|
hMenu = GetMenu(hDlgWnd);
|
|
|
|
hViewMenu = GetSubMenu(hMenu, ID_MENU_VIEW);
|
|
|
|
if (bDigitGrouping) {
|
|
|
|
CheckMenuItem(hViewMenu, ID_VIEW_DIGIT_GROUPING, MF_BYCOMMAND|MF_CHECKED);
|
|
|
|
}
|
|
|
|
|
|
|
|
//SendMessage(hDlgWnd, WM_SETICON, ICON_BIG, (LPARAM)LoadIcon(hInst, MAKEINTRESOURCE(IDI_CALC)));
|
|
|
|
|
|
|
|
// Initialize the Windows Common Controls DLL
|
|
|
|
//InitCommonControls();
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void OnEditCopy(void)
|
|
|
|
{
|
2002-07-21 18:28:26 +00:00
|
|
|
SendMessage(GetDlgItem(hDlgWnd, IDC_RESULT), WM_COMMAND, MAKELONG(ID_EDIT_COPY, 0), 0);
|
2002-07-16 19:15:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void OnEditPaste(void)
|
|
|
|
{
|
2002-07-21 18:28:26 +00:00
|
|
|
SendMessage(GetDlgItem(hDlgWnd, IDC_RESULT), WM_COMMAND, MAKELONG(ID_EDIT_PASTE, 0), 0);
|
2002-07-16 19:15:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void OnViewStandard(void)
|
|
|
|
{
|
|
|
|
CalcType = STANDARD;
|
|
|
|
DestroyWindow(hDlgWnd);
|
|
|
|
}
|
|
|
|
|
|
|
|
void OnViewScientific(void)
|
|
|
|
{
|
|
|
|
CalcType = SCIENTIFIC;
|
|
|
|
DestroyWindow(hDlgWnd);
|
|
|
|
}
|
|
|
|
|
|
|
|
void OnViewDigitGrouping(void)
|
|
|
|
{
|
|
|
|
HMENU hMenu = GetMenu(hDlgWnd);
|
|
|
|
HMENU hViewMenu = GetSubMenu(hMenu, ID_MENU_VIEW);
|
|
|
|
bDigitGrouping = !bDigitGrouping;
|
|
|
|
if (bDigitGrouping) {
|
|
|
|
CheckMenuItem(hViewMenu, ID_VIEW_DIGIT_GROUPING, MF_BYCOMMAND|MF_CHECKED);
|
|
|
|
} else {
|
|
|
|
CheckMenuItem(hViewMenu, ID_VIEW_DIGIT_GROUPING, MF_BYCOMMAND|MF_UNCHECKED);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-07-16 21:54:17 +00:00
|
|
|
void OnViewHex(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void OnViewDecimal(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void OnViewOctal(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void OnViewBinary(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void OnViewDegrees(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void OnViewRadians(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void OnViewGrads(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2002-07-16 19:15:12 +00:00
|
|
|
void OnHelpTopics(void)
|
|
|
|
{
|
|
|
|
WinHelp(hDlgWnd, _T("calc"), HELP_CONTENTS, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void OnHelpAbout(void)
|
|
|
|
{
|
2004-01-18 03:28:08 +00:00
|
|
|
ShellAbout(hDlgWnd, _T("ReactOS Calculator"), _T(""), LoadIcon(hInst, MAKEINTRESOURCE(IDI_CALC)));
|
2002-07-16 19:15:12 +00:00
|
|
|
}
|
2004-01-18 03:28:08 +00:00
|
|
|
|
2004-01-15 05:27:18 +00:00
|
|
|
void OnButtonClick(int ButtonID)
|
|
|
|
{
|
|
|
|
}
|
2002-07-16 19:15:12 +00:00
|
|
|
// Message handler for dialog box.
|
|
|
|
LRESULT CALLBACK CalcWndProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
|
|
|
|
{
|
|
|
|
switch (message) {
|
|
|
|
case WM_INITDIALOG:
|
|
|
|
hDlgWnd = hDlg;
|
|
|
|
InitColours();
|
|
|
|
return OnCreate(hDlg);
|
|
|
|
|
|
|
|
case WM_DRAWITEM:
|
|
|
|
DrawItem((LPDRAWITEMSTRUCT)lParam);
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
case WM_COMMAND:
|
|
|
|
if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL) {
|
|
|
|
EndDialog(hDlg, LOWORD(wParam));
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (HIWORD(wParam) == BN_CLICKED) {
|
2004-01-15 05:27:18 +00:00
|
|
|
switch (LOWORD(wParam)) {
|
|
|
|
OnButtonClick(LOWORD(wParam));
|
|
|
|
//case IDC_OWNERDRAW:
|
2002-07-16 19:15:12 +00:00
|
|
|
// // application-defined processing
|
|
|
|
// break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-01-15 05:27:18 +00:00
|
|
|
//BEGIN_CMD_MAP( LOWORD(wParam) )
|
|
|
|
switch (LOWORD(wParam))
|
|
|
|
{
|
2002-07-16 19:15:12 +00:00
|
|
|
CMD_MAP_ENTRY(ID_EDIT_COPY, OnEditCopy)
|
|
|
|
CMD_MAP_ENTRY(ID_EDIT_PASTE, OnEditPaste)
|
|
|
|
CMD_MAP_ENTRY(ID_VIEW_STANDARD, OnViewStandard)
|
|
|
|
CMD_MAP_ENTRY(ID_VIEW_SCIENTIFIC, OnViewScientific)
|
|
|
|
CMD_MAP_ENTRY(ID_VIEW_DIGIT_GROUPING, OnViewDigitGrouping)
|
2002-07-16 21:54:17 +00:00
|
|
|
CMD_MAP_ENTRY(ID_VIEW_HEX, OnViewHex)
|
|
|
|
CMD_MAP_ENTRY(ID_VIEW_DECIMAL, OnViewDecimal)
|
|
|
|
CMD_MAP_ENTRY(ID_VIEW_OCTAL, OnViewOctal)
|
|
|
|
CMD_MAP_ENTRY(ID_VIEW_BINARY, OnViewBinary)
|
|
|
|
CMD_MAP_ENTRY(ID_VIEW_DEGREES, OnViewDegrees)
|
|
|
|
CMD_MAP_ENTRY(ID_VIEW_RADIANS, OnViewRadians)
|
|
|
|
CMD_MAP_ENTRY(ID_VIEW_GRADS, OnViewGrads)
|
2002-07-16 19:15:12 +00:00
|
|
|
CMD_MAP_ENTRY(ID_HELP_TOPICS, OnHelpTopics)
|
|
|
|
CMD_MAP_ENTRY(ID_HELP_ABOUT, OnHelpAbout)
|
2004-01-15 05:27:18 +00:00
|
|
|
}
|
|
|
|
//END_CMD_MAP(0)
|
2002-07-16 19:15:12 +00:00
|
|
|
break;
|
2002-07-16 21:54:17 +00:00
|
|
|
/*
|
|
|
|
case WM_KEYUP:
|
|
|
|
case WM_KEYDOWN:
|
|
|
|
{
|
|
|
|
MSG msg;
|
|
|
|
msg.hwnd = hDlg;
|
|
|
|
msg.message = message;
|
|
|
|
msg.wParam = wParam;
|
|
|
|
msg.lParam = lParam;
|
|
|
|
// msg.time;
|
|
|
|
// msg.pt;
|
|
|
|
if (TranslateAccelerator(hDlg, hAccel, &msg)) return 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
*/
|
2002-07-16 19:15:12 +00:00
|
|
|
case WM_NOTIFY:
|
|
|
|
{
|
|
|
|
int idctrl;
|
|
|
|
LPNMHDR pnmh;
|
|
|
|
idctrl = (int)wParam;
|
|
|
|
pnmh = (LPNMHDR)lParam;
|
|
|
|
/*
|
|
|
|
if ((pnmh->hwndFrom == hTabWnd) &&
|
|
|
|
(pnmh->idFrom == IDC_TAB) &&
|
|
|
|
(pnmh->code == TCN_SELCHANGE))
|
|
|
|
{
|
|
|
|
_OnTabWndSelChange();
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WM_DESTROY:
|
|
|
|
WinHelp(hDlgWnd, _T("regedit"), HELP_QUIT, 0);
|
|
|
|
return DefWindowProc(hDlg, message, wParam, lParam);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int APIENTRY WinMain(HINSTANCE hInstance,
|
|
|
|
HINSTANCE hPrevInstance,
|
|
|
|
LPSTR lpCmdLine,
|
|
|
|
int nCmdShow)
|
|
|
|
{
|
|
|
|
CALC_TYPES CurrentCalcType;
|
|
|
|
|
|
|
|
// Initialize global variables
|
|
|
|
hInst = hInstance;
|
2002-07-16 21:54:17 +00:00
|
|
|
LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
|
2002-07-16 19:15:12 +00:00
|
|
|
|
|
|
|
// Load our settings from the registry
|
|
|
|
LoadSettings();
|
|
|
|
|
2002-07-16 21:54:17 +00:00
|
|
|
hAccel = LoadAccelerators(hInstance, (LPCTSTR)IDR_ACCELERATOR);
|
|
|
|
|
2002-07-16 19:15:12 +00:00
|
|
|
do {
|
|
|
|
CurrentCalcType = CalcType;
|
|
|
|
switch (CalcType) {
|
|
|
|
case HP42S:
|
|
|
|
break;
|
|
|
|
case SCIENTIFIC:
|
|
|
|
DialogBox(hInst, (LPCTSTR)IDD_SCIENTIFIC, NULL, (DLGPROC)CalcWndProc);
|
|
|
|
break;
|
|
|
|
case STANDARD:
|
|
|
|
default:
|
|
|
|
DialogBox(hInst, (LPCTSTR)IDD_STANDARD, NULL, (DLGPROC)CalcWndProc);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} while (CalcType != CurrentCalcType);
|
|
|
|
|
|
|
|
// Save our settings to the registry
|
|
|
|
SaveSettings();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|