📄 calc.c
字号:
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 );
}
//////////////////////////////////////////////////
//
// EverythingResettingNumberSetup
//
//////////////////////////////////////////////////
void EverythingResettingNumberSetup()
{
int i;
// Initialize the decimal input code.
CIO_vClear( &gcio );
gbRecord = TRUE;
NumObjAssign( &ghnoNum, HNO_ZERO );
NumObjAssign( &ghnoLastNum, HNO_ZERO );
// REVIEW: is it just me, or do we speew major memory wheneven this method
// executes?
// array used to handle ( and )
for( i = 0; i < ARRAYSIZE(ghnoParNum); i++ )
ghnoParNum[i] = NULL;
// array used to handle order of operations
for( i = 0; i < ARRAYSIZE(ghnoPrecNum); i++ )
ghnoPrecNum[i] = NULL;
gpszNum = (LPTSTR)NumObjAllocMem( sizeof(szInitNum) );
lstrcpy( gpszNum, szInitNum );
}
//////////////////////////////////////////////////
//
// InitSciCalc
//
//////////////////////////////////////////////////
VOID APIENTRY InitSciCalc(BOOL bViewChange)
{
TCHAR chLastDec;
TCHAR chLastSep;
int nLastSepLen;
HMENU hMenu;
BOOL bRepaint=FALSE;
RECT rect = {0,0,0,0};
EverythingResettingNumberSetup();
// when we switch modes, we need to remind the ui that we are no longer
// inputing the number we were inputting before we switched modes.
gbRecord = FALSE; // REVIEW: This should not be needed with the new initialization
chLastDec = szDec[0];
chLastSep = gszSep[0];
GetProfileString(TEXT("intl"), TEXT("sDecimal"), TEXT("."),
szDec, CharSizeOf(szDec));
GetProfileString(TEXT("intl"), TEXT("sThousand"), TEXT(","),
gszSep, CharSizeOf(gszSep));
// if the thousands symbol has changed we always do the following things
if ( gszSep[0] != chLastSep )
{
chLastSep = gszSep[0];
bRepaint = TRUE;
}
// if the decimal symbol has changed we always do the following things
if ( szDec[0] != chLastDec )
{
chLastDec = szDec[0];
// Re-initialize input string's decimal point.
CIO_vUpdateDecimalSymbol(&gcio, chLastDec);
// put the new decimal symbol into the table used to draw the decimal
// key
*(rgpsz[IDS_DECIMAL]) = chLastDec;
// we need to redraw to update the decimal point button
bRepaint = TRUE;
}
if ( bViewChange )
{
BOOL bUseOldPos = FALSE;
// if we are changing views we destory the old window and create
// a new window
if ( g_hwndDlg )
{
SetMenu(g_hwndDlg, g_hDecMenu);
bUseOldPos = TRUE;
GetWindowRect( g_hwndDlg, &rect );
DestroyWindow( g_hwndDlg );
DestroyMenu(g_hHexMenu);
g_hHexMenu=NULL;
}
// create the correct window for the mode we're currently in
if ( nCalc )
{
// switch to standard mode
g_hwndDlg = CreateDialog(hInst, MAKEINTRESOURCE(IDD_STANDARD), 0,
NULL);
g_hDecMenu=GetMenu(g_hwndDlg);
#ifdef USE_MIRRORING
if (g_fLayoutRTL)
{
SetWindowLong(g_hwndDlg,
GWL_EXSTYLE,
GetWindowLong(g_hwndDlg,GWL_EXSTYLE) | \
WS_EX_LAYOUTRTL | WS_EX_NOINHERITLAYOUT);
}
#endif
}
else
{
// switch to scientific mode
g_hwndDlg = CreateDialog(hInst, MAKEINTRESOURCE(IDD_SCIENTIFIC),
0, NULL);
g_hDecMenu=GetMenu(g_hwndDlg);
g_hHexMenu=LoadMenu(hInst, MAKEINTRESOURCE(IDM_HEXCALCMENU));
#ifdef USE_MIRRORING
if (g_fLayoutRTL)
{
SetWindowLong(g_hwndDlg,
GWL_EXSTYLE,
GetWindowLong(g_hwndDlg,GWL_EXSTYLE) | WS_EX_LAYOUTRTL | WS_EX_NOINHERITLAYOUT);
}
#endif
// Stat box is initially off, disable stat buttons.
for ( int iID = IDC_AVE; iID <= IDC_DATA; iID++ )
EnableWindow( GetDlgItem( g_hwndDlg, iID ), FALSE );
SwitchModes(10, nDecMode, nHexMode);
// If precision won't fit in display, then resize it
if (nPrecision > 32)
{
HWND hwndDisplay;
RECT rc, rcMain;
hwndDisplay=GetDlgItem( g_hwndDlg, IDC_DISPLAY );
GetWindowRect( hwndDisplay, &rc );
GetClientRect( g_hwndDlg, &rcMain );
MapWindowPoints( g_hwndDlg, NULL, (LPPOINT)&rcMain, 2);
rc.left = rcMain.left + (rcMain.right - rc.right);
OffsetRect( &rc, -(rcMain.left), -(rcMain.top) );
SetWindowPos(hwndDisplay, NULL,
rc.left, rc.top,
rc.right - rc.left, rc.bottom - rc.top,
SWP_NOACTIVATE | SWP_NOZORDER );
}
}
// keep calc in the same place it was before
if ( bUseOldPos )
{
SetWindowPos( g_hwndDlg, NULL, rect.left, rect.top, 0,0,
SWP_NOZORDER | SWP_NOSIZE );
}
// ensure the menu items for Scientific and Standard are set correctly
CheckMenuRadioItem(g_hDecMenu, IDM_SC, IDM_SSC,
(nCalc == 0 ? IDM_SC : IDM_SSC), MF_BYCOMMAND);
CheckMenuItem(g_hDecMenu, IDM_USE_SEPARATOR,
MF_BYCOMMAND | (gbUseSep ? MF_CHECKED : MF_UNCHECKED));
if (g_hHexMenu)
{
CheckMenuRadioItem(g_hHexMenu, IDM_SC, IDM_SSC,
(nCalc == 0 ? IDM_SC : IDM_SSC), MF_BYCOMMAND);
CheckMenuItem(g_hHexMenu, IDM_USE_SEPARATOR,
MF_BYCOMMAND | (gbUseSep ? MF_CHECKED:MF_UNCHECKED));
}
// To ensure that the call to SetRadix correctly update the active
// state of the buttons on
// SciCalc we must tell it to forget the previous Radix
{
extern long oldRadix;
oldRadix = (unsigned)-1;
}
// this will set the correct buttons on the UI
SetRadix(10);
SetDlgItemText(g_hwndDlg, IDC_MEMTEXT,
NumObjIsZero(ghnoMem) ? (szBlank) : (TEXT(" M")) );
ShowWindow( g_hwndDlg, SW_SHOW );
UpdateWindow(g_hwndDlg);
} // END if ( bViewChanged )
else if ( bRepaint )
{
// no need to repaint if we just changed views
InvalidateRect( g_hwndDlg, NULL, TRUE );
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -