关于Window2000上面的自带的计算器写法

zhang20084 2005-08-05 11:57:57
请大家告诉小弟弟我一点东西。我刚刚到公司就叫我做这个。我是新手,都不知道在没下手,我以前学习JAVA的。现在JAVA中我还知道怎么写。可是VC中我不知道要调用什么函数。谢谢JJGG
...全文
222 16 打赏 收藏 转发到动态 举报
写回复
用AI写文章
16 条回复
切换为时间正序
请发表友善的回复…
发表回复
啥啥也不是 2005-08-14
  • 打赏
  • 举报
回复
可以给我的邮箱发一份吗?

sunshinekillermj@163.com
zhang20084 2005-08-13
  • 打赏
  • 举报
回复
微软那个是C写的吧.我现在需要VC写的代码。还有我VC刚刚用.连几个组件使用还不是怎么会.我师傅又忙没有时间教我。这不一个星期写个和微软一样的计算器.又给了我一个星期拉。我这个郁闷呀。
zhang20084 2005-08-09
  • 打赏
  • 举报
回复
恩。你可以把计算器上面需要到的科学型 用到的函数告诉我一下呀
shxng 2005-08-09
  • 打赏
  • 举报
回复
给我发一份吧shxng@163.com
xiao_xiao_zi 2005-08-09
  • 打赏
  • 举报
回复
这些是微软释放出来的部分源码
微软也就只会释放这些无关紧要的代码,呵呵
dfbtf 2005-08-08
  • 打赏
  • 举报
回复
/**************************************************************************\
*
* Command Line processing routines
*
* History
* 22-Nov-1996 JonPa Wrote it
*
\**************************************************************************/

#define IsWhiteSpace( ch ) ((ch) == TEXT(' ') || (ch) == TEXT('\t'))
#define IsDigit( ch ) ((ch) >= TEXT('0') && (ch) <= TEXT('9'))

LPTSTR TtoL( LPTSTR psz, LONG *pl ) {
LONG l = 0;

while( IsDigit( *psz ) ) {
l = l * 10 + (*psz - TEXT('0'));
psz = CharNext( psz );
}

*pl = l;
return psz;
}

void ParseCmdLine( LPSTR pszCmdA ) {
BOOL fInQuote;
LPTSTR pszCmdT = GetCommandLine();

// parse cmd line
// usage: -p:## -r:## -w:## -e -x -i
// -e, -x, and -i currently do nothing.

// Skip app name
while( *pszCmdT && IsWhiteSpace( *pszCmdT )) {
pszCmdT = CharNext( pszCmdT );
}

fInQuote = FALSE;
while( *pszCmdT && (fInQuote || !IsWhiteSpace(*pszCmdT)) ) {
if (*pszCmdT == TEXT('\"'))
fInQuote = !fInQuote;
pszCmdT = CharNext( pszCmdT );
}

while( *pszCmdT )
{
switch( *pszCmdT )
{
case TEXT('p'):
case TEXT('P'):
// -p:## precision
pszCmdT = CharNext(pszCmdT);

// Skip ':' and white space
while( *pszCmdT && (*pszCmdT == TEXT(':') || IsWhiteSpace(*pszCmdT)) ) {
pszCmdT = CharNext(pszCmdT);
}

pszCmdT = TtoL( pszCmdT, &nPrecision );

// a percision > C_NUM_MAX_DIGITS will allow a string too long for it's buffer
if ( nPrecision > C_NUM_MAX_DIGITS)
{
ASSERT( nPrecision <= C_NUM_MAX_DIGITS );
nPrecision = C_NUM_MAX_DIGITS;
}

// NOTE: this code assumes there MUST be a space after the number
break;

case TEXT('r'):
case TEXT('R'):
// -r:## Radix
pszCmdT = CharNext(pszCmdT);

// Skip ':' and white space
while( *pszCmdT && (*pszCmdT == TEXT(':') || IsWhiteSpace(*pszCmdT)) ) {
pszCmdT = CharNext(pszCmdT);
}

pszCmdT = TtoL( pszCmdT, &nRadix );

// since the UI only has 16 keys for digit input, we only allow upto base 16
if (nRadix > 16)
{
ASSERT( nRadix <= 16 );
nRadix = 16;
}
else if (nRadix < 2) // you know some fool would try for base zero if you let them
{
ASSERT( nRadix >= 2 );
nRadix = 2;
}

// NOTE: this code assumes there MUST be a space after the number
break;

case TEXT('e'):
case TEXT('E'):
// -e extended mode
break;

case TEXT('w'):
case TEXT('W'):
// -w:## Word size in bits
pszCmdT = CharNext(pszCmdT);

// Skip ':' and white space
while( *pszCmdT && (*pszCmdT == TEXT(':') || IsWhiteSpace(*pszCmdT)) ) {
pszCmdT = CharNext(pszCmdT);
}

// Set bit count
pszCmdT = TtoL( pszCmdT, &dwWordBitWidth );

// NOTE: this code assumes there MUST be a space after the number
break;
}

pszCmdT = CharNext( pszCmdT );
}
}

//////////////////////////////////////////////////
//
// InitalizeWindowClass
//
//////////////////////////////////////////////////
BOOL InitializeWindowClass( HINSTANCE hPrevInstance )
{
WNDCLASSEX wndclass;

if (!hPrevInstance)
{
wndclass.cbSize = sizeof(wndclass);
wndclass.style = 0;
wndclass.lpfnWndProc = CalcWndProc;
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = DLGWINDOWEXTRA;
wndclass.hInstance = hInst;
wndclass.hIcon = LoadIcon(hInst, TEXT("SC"));
wndclass.hCursor = LoadCursor (NULL, IDC_ARROW);
wndclass.hbrBackground = GetSysColorBrush(COLOR_3DFACE);
wndclass.lpszMenuName = MAKEINTRESOURCE(IDM_CALCMENU);
wndclass.lpszClassName = szAppName;
wndclass.hIconSm = NULL;

if (!RegisterClassEx(&wndclass))
return FALSE;
}
return TRUE;
}

//////////////////////////////////////////////////
//
// InitialOneTimeOnlyNumberSetup
//
//////////////////////////////////////////////////
void InitialOneTimeOnlySetup()
{
// Initialize the decimal input code. This ends up getting called twice
// but it's quick so that shouldn't be a problem. Needs to be done before
// SetRadix is called.

CIO_vClear( &gcio );
gbRecord = TRUE;

// we must now setup all the ratpak constants and our arrayed pointers
// to these constants.
BaseOrPrecisionChanged();

// these rat numbers are set only once and then never change regardless of
// base or precision changes
g_ahnoChopNumbers[0] = rat_qword;
g_ahnoChopNumbers[1] = rat_dword;
g_ahnoChopNumbers[2] = rat_word;
g_ahnoChopNumbers[3] = rat_byte;

// we can't call this until after we have set the radix (and thus called
// ChangeConstants) so we do it last.

EverythingResettingNumberSetup();

NumObjAssign( &ghnoMem, HNO_ZERO );
}
dfbtf 2005-08-08
  • 打赏
  • 举报
回复
// A bunch of sanity checks to ensure nobody is violating any of the
// bazillion
// assumptions calc makes about the order of controls. Of course these
// asserts
// wouldn't prevent a really dedicated idiot from messing things up but they
// should help guide a rational person who might not be aware of calc's
// idiosyncrasies.
// Anyone who modifies the resource file should hit these asserts which
// will then
// alert them to the consequences of their actions.

// IDC_0 to IDC_F must be in sequential increasing order
ASSERT( 15 == (IDC_F - IDC_0) );
// Binary operators IDC_AND through IDC_PWR must be in order
ASSERT( (95-86) == (IDC_PWR - IDC_AND) );
// Unary operators IDC_CHOP through IDC_EQU must be in order
ASSERT( (112-96) == (IDC_EQU - IDC_CHOP) );
// menu item id's must be in order
ASSERT( 5 == (IDM_LASTMENU - IDM_FIRSTMENU) );

#ifdef USE_MIRRORING
GetProcessDefaultLayout(&dwLayout);
if (dwLayout & LAYOUT_RTL)
{
SetProcessDefaultLayout(dwLayout & ~LAYOUT_RTL);
g_fLayoutRTL = TRUE;
}
#endif

ParseCmdLine( lpCmdLine );

hInst = hInstance;

if ( !InitializeWindowClass( hPrevInstance ) )
return FALSE;

// Read strings for keys, errors, trig types, etc.
// These will be copied from the resources to local memory. A larger
// than needed block is allocated first and then reallocated once we
// know how much is actually used.

try
{
hMem = LocalAlloc(LPTR, ByteCountOf(CCHSTRINGSMAX));
if (!hMem)
throw;

psz = (TCHAR *)hMem;

for (nx = 0; nx <= CSTRINGS; nx++)
{
ASSERT( (CCHSTRINGSMAX-cchTotal) > LoadString(hInstance, (WORD) IDS_FIRSTKEY + nx, NULL, 0) );
cch = (WORD)(1 + LoadString(hInstance, (WORD) IDS_FIRSTKEY + nx, psz, (int) (CCHSTRINGSMAX-cchTotal)));
cchTotal += cch;
rgpsz[nx] = psz;
psz += cch;
}

if (!LocalReAlloc(hMem, ByteCountOf(cchTotal), LMEM_FIXED))
throw;
}
catch ( ... )
{
if (!LoadString(hInst, IDS_NOMEM, szTempString, CharSizeOf(szTempString)))
{
// only do this if LoadString Fails, means system is really hosed!
lstrcpy(szTempString, TEXT("<Main> Not enough memory."));
}
MessageBox((HWND) NULL, szTempString, NULL, MB_OK | MB_ICONHAND);
return FALSE;
}

// The display in calc isn't really an edit control so we use this edit
// control to simplify cutting to the clipboard

hEdit = CreateWindow( TEXT("EDIT"), TEXT("CalcMsgPumpWnd"),
WS_OVERLAPPED | WS_VISIBLE,
CW_USEDEFAULT,0,CW_USEDEFAULT,0,
NULL, NULL, hInst, NULL );

// This initializes things that only need to be set up once, including a
// call to ratpak so that ratpak can create any constants it needs

InitialOneTimeOnlySetup();

// we store in the win.ini file our desired display mode, Scientific
// or Standard

nCalc = (INT)GetProfileInt(szAppName, TEXT("layout"), 1);

gbUseSep = (INT)GetProfileInt(szAppName, TEXT("UseSep"), 0);

// InitSciCalc creates a dialog based on what the value of nCalc is.
// A handle to the window that is created is stored in g_hwndDlg

InitSciCalc(TRUE);

hAccel = LoadAccelerators(hInst, MAKEINTRESOURCE(IDA_ACCELTABLE));


while (GetMessage(&msg, NULL, 0, 0))
{
if (!hStatBox || !IsDialogMessage(hStatBox, &msg))
{
if ( ((msg.hwnd == g_hwndDlg)||IsChild(g_hwndDlg, msg.hwnd)) && TranslateAccelerator (g_hwndDlg, (HACCEL)hAccel, &msg))
continue;

TranslateMessage(&msg);
DispatchMessage(&msg);
}
}

LocalFree(hMem);
return (DWORD)msg.wParam;
}
dfbtf 2005-08-08
  • 打赏
  • 举报
回复
我也有!calc.c 是这个吗?
/**************************************************************************\
*** SCICALC Scientific Calculator for Windows 3.00.12
*** By Kraig Brockschmidt, Microsoft Co-op, Contractor, 1988-1989
*** (c)1989 Microsoft Corporation. All Rights Reserved.
***
*** scimain.c
***
*** Definitions of all globals, WinMain procedure
***
*** Last modification
*** Fri 22-Nov-1996
***
*** -by- Jonathan Parati. [jonpa] 22-Nov-1996
*** Converted Calc from floating point to infinite precision.
*** The new math engine is in ..\ratpak
***
***
*** -by- Amit Chatterjee. [amitc] 05-Jan-1990.
*** Calc did not have a floating point exception signal handler. This
*** would cause CALC to be forced to exit on a FP exception as that's
*** the default.
*** The signal handler is defined in SCIFUNC.C, in WinMain we hook the
*** the signal.
\**************************************************************************/

#include "scicalc.h"
#include "calchelp.h"
#include "signal.h"
#include "unifunc.h"
#include "input.h"


/**************************************************************************/
/*** Global variable declarations and initializations ***/
/**************************************************************************/

int nCalc=0; /* 0=Scientific, 1=Simple. */
BOOL gbUseSep=FALSE; /* display the number with a separator */
ANGLE_TYPE nDecMode=ANGLE_DEG; /* Holder for last used Deg/Rad/Grad mode. */
int nHexMode=0; /* Holder for last used Dword/Word/Byte mode. */

int nTempCom=0, /* Holding place for the last command. */
nParNum=0, /* Number of parenthases. */
nOpCode=0, /* ID value of operation. */
nOp[25], /* Holding array for parenthasis operations. */
nPrecOp[25], /* Holding array for precedence operations. */
nPrecNum=0, /* Current number of precedence ops in holding. */
gcIntDigits; /* Number of digits allowed in the current base */

eNUMOBJ_FMT nFE = FMT_FLOAT; /* Scientific notation conversion flag. */

HWND g_hwndDlg=0, /* Global handle to main window. */
hEdit=0, /* Handle to Clibboard I/O edit control */
hStatBox=0, /* Global handle to statistics box. */
hListBox=0; /* Global handle for statistics list box. */


HMENU g_hHexMenu=NULL; // Global handle for hex menu
HMENU g_hDecMenu=NULL; // Global handle for dec menu

HANDLE hAccel; // Accelerator handle.
HINSTANCE hInst; // Global instance.

BOOL bHyp=FALSE, // Hyperbolic on/off flag.
bInv=FALSE, // Inverse on/off flag.
bError=FALSE, // Error flag.
bColor=TRUE; // Flag indicating if color is available.

HNUMOBJ ghnoNum=NULL, // Currently displayed number used everywhere.
ghnoParNum[25], // Holding array for parenthasis values.
ghnoPrecNum[25], // Holding array for precedence values.
ghnoMem=NULL, // Current memory value.
ghnoLastNum = NULL; // Number before operation (left operand).

LONG nPrecision = 32, // number of digits to use in decimal mode
nDecimalPlaces = 10, // number of decimal places to show
nRadix=10, // the current base (2, 8, 10, or 16)
dwWordBitWidth = 64; // # of bits in currently selected word size

HNUMOBJ g_ahnoChopNumbers[4]; // word size inforcement

BOOL bFarEast; // true if we need to use Far East localization

#ifdef USE_MIRRORING
BOOL g_fLayoutRTL = FALSE;
#endif

extern CALCINPUTOBJ gcio;
extern BOOL gbRecord;

/* DO NOT LOCALIZE THESE STRINGS. */

TCHAR szAppName[10]=TEXT("SciCalc"), /* Application name. */
szDec[5]=TEXT("."), /* Default decimal character */
gszSep[5]=TEXT(","), /* Default thousand seperator */
szBlank[6]=TEXT(""); /* Blank space. */

LPTSTR gpszNum = NULL;
static TCHAR szInitNum[] = TEXT("0"); // text to init gpszNum with

/* END WARNING */


/* rgpsz[] is an array of pointers to strings in a locally allocated */
/* memory block. This block is fixed such that LocalLock does not need */
/* to be called to use a string. */

TCHAR *rgpsz[CSTRINGS];
RECT rcDeg[6];


void ParseCmdLine( LPSTR pszCmdA );
BOOL InitializeWindowClass( HINSTANCE hPrevInstance );
void InitialOneTimeOnlySetup();
void EverythingResettingNumberSetup();
/**************************************************************************/
/*** Main Window Procedure. ***/
/*** ***/
/*** Important functions: ***/
/*** 1) Gets text dimensions and sets conversion units correctly. ***/
/*** ***/
/*** 2) Checks the display device driver for color capability. ***/
/*** If only 2 colors are available (mono, cga), bColor is ***/
/*** set to FALSE, and the background brush is gray. If ***/
/*** color is available, the background brush colors are read ***/
/*** from WIN.INI and the brush is created. ***/
/*** ***/
/*** 3) Window and hidden edit control are created. ***/
/*** ***/
/*** 4) Contains message loop and deletes the brushes used. ***/
/*** ***/
/**************************************************************************/

int APIENTRY WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
MSG msg;
INT nx;
TCHAR *psz;
WORD cch = 0, cchTotal = 0;
HANDLE hMem;
TCHAR szTempString[100];
#ifdef USE_MIRRORING
DWORD dwLayout;
#endif
threenewbee 2005-08-08
  • 打赏
  • 举报
回复
上面的已经发了。
zhang20084 2005-08-07
  • 打赏
  • 举报
回复
兄弟,谢谢啊,我在网上找到http://www.firstarcicl.com.cn/download.asp里面Visual C++ 6.0 编程案例精解,里面有个计算器的

我的是 zhang20084@sina.com
魔芋 2005-08-06
  • 打赏
  • 举报
回复
有一个script的com可以做+-*/加入自定义函数
WecanHuang 2005-08-06
  • 打赏
  • 举报
回复
比价繁琐
因为除了+-*/之外
还有成方,开放,二进制,八进制,十进制,十六进制等等。。。
zq_killer 2005-08-06
  • 打赏
  • 举报
回复
还有正宗的微软源代码?
我也要一份。
douzhiq@sohu.com

谢谢
wallace2005 2005-08-06
  • 打赏
  • 举报
回复
顶一下!我也要源代码。
这是我的邮箱:
2005wallace@163.com
threenewbee 2005-08-06
  • 打赏
  • 举报
回复
给个邮箱,我把正宗微软的计算器源代码发给你。
zhang20084 2005-08-06
  • 打赏
  • 举报
回复
恩,我知道比较烦而且蛮烦的..请大哥讲的详细点,谢谢。

16,472

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧