Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

735 lines
24 KiB

  1. /**************************************************************************\
  2. *** SCICALC Scientific Calculator for Windows 3.00.12
  3. *** By Kraig Brockschmidt, Microsoft Co-op, Contractor, 1988-1989
  4. *** (c)1989 Microsoft Corporation. All Rights Reserved.
  5. ***
  6. *** scimain.c
  7. ***
  8. *** Definitions of all globals, WinMain procedure
  9. ***
  10. *** Last modification
  11. *** Fri 22-Nov-1996
  12. ***
  13. *** -by- Jonathan Parati. [jonpa] 22-Nov-1996
  14. *** Converted Calc from floating point to infinite precision.
  15. *** The new math engine is in ..\ratpak
  16. ***
  17. ***
  18. *** -by- Amit Chatterjee. [amitc] 05-Jan-1990.
  19. *** Calc did not have a floating point exception signal handler. This
  20. *** would cause CALC to be forced to exit on a FP exception as that's
  21. *** the default.
  22. *** The signal handler is defined in SCIFUNC.C, in WinMain we hook the
  23. *** the signal.
  24. \**************************************************************************/
  25. #include "scicalc.h"
  26. #include "calchelp.h"
  27. #include "signal.h"
  28. #include "unifunc.h"
  29. #include "input.h"
  30. #include "scidisp.h"
  31. #define BOOLIFY(x) ((x)?1:0)
  32. /**************************************************************************/
  33. /*** Global variable declarations and initializations ***/
  34. /**************************************************************************/
  35. int nCalc=0; /* 0=Scientific, 1=Simple. */
  36. BOOL gbUseSep=FALSE; /* display the number with a separator */
  37. ANGLE_TYPE nDecMode=ANGLE_DEG; /* Holder for last used Deg/Rad/Grad mode. */
  38. UINT gnDecGrouping=0x03; /* Holds the decimal digit grouping number */
  39. int nHexMode=0; /* Holder for last used Dword/Word/Byte mode. */
  40. int nTempCom=0, /* Holding place for the last command. */
  41. nParNum=0, /* Number of parenthases. */
  42. nOpCode=0, /* ID value of operation. */
  43. nOp[25], /* Holding array for parenthasis operations. */
  44. nPrecOp[25], /* Holding array for precedence operations. */
  45. nPrecNum=0, /* Current number of precedence ops in holding. */
  46. gcIntDigits; /* Number of digits allowed in the current base */
  47. eNUMOBJ_FMT nFE = FMT_FLOAT; /* Scientific notation conversion flag. */
  48. HWND g_hwndDlg=0, /* Global handle to main window. */
  49. hEdit=0, /* Handle to Clibboard I/O edit control */
  50. hStatBox=0, /* Global handle to statistics box. */
  51. hListBox=0; /* Global handle for statistics list box. */
  52. HMENU g_hHexMenu=NULL; // Global handle for hex menu
  53. HMENU g_hDecMenu=NULL; // Global handle for dec menu
  54. HANDLE hAccel; // Accelerator handle.
  55. HINSTANCE hInst; // Global instance.
  56. BOOL bHyp=FALSE, // Hyperbolic on/off flag.
  57. bInv=FALSE, // Inverse on/off flag.
  58. bError=FALSE, // Error flag.
  59. bColor=TRUE; // Flag indicating if color is available.
  60. HNUMOBJ ghnoNum=NULL, // Currently displayed number used everywhere.
  61. ghnoParNum[25], // Holding array for parenthasis values.
  62. ghnoPrecNum[25], // Holding array for precedence values.
  63. ghnoMem=NULL, // Current memory value.
  64. ghnoLastNum = NULL; // Number before operation (left operand).
  65. LONG nPrecision = 32, // number of digits to use in decimal mode
  66. nDecimalPlaces = 10, // number of decimal places to show
  67. nRadix=10, // the current base (2, 8, 10, or 16)
  68. dwWordBitWidth = 64; // # of bits in currently selected word size
  69. BOOL g_fHighContrast = FALSE; // Are we in High Contrast mode?
  70. HNUMOBJ g_ahnoChopNumbers[4]; // word size inforcement
  71. BOOL bFarEast; // true if we need to use Far East localization
  72. #ifdef USE_MIRRORING
  73. BOOL g_fLayoutRTL = FALSE;
  74. #endif
  75. extern CALCINPUTOBJ gcio;
  76. extern BOOL gbRecord;
  77. /* DO NOT LOCALIZE THESE STRINGS. */
  78. TCHAR szAppName[10]=TEXT("SciCalc"), /* Application name. */
  79. szDec[5]=TEXT("."), /* Default decimal character */
  80. gszSep[5]=TEXT(","), /* Default thousand seperator */
  81. szBlank[6]=TEXT(""); /* Blank space. */
  82. LPTSTR gpszNum = NULL;
  83. static TCHAR szInitNum[] = TEXT("0"); // text to init gpszNum with
  84. /* END WARNING */
  85. /* rgpsz[] is an array of pointers to strings in a locally allocated */
  86. /* memory block. This block is fixed such that LocalLock does not need */
  87. /* to be called to use a string. */
  88. TCHAR *rgpsz[CSTRINGS];
  89. RECT rcDeg[6];
  90. void ParseCmdLine( LPSTR pszCmdA );
  91. BOOL InitializeWindowClass( HINSTANCE hPrevInstance );
  92. void InitialOneTimeOnlySetup();
  93. void EverythingResettingNumberSetup();
  94. extern WNDPROC fpOrgDispEditProc;
  95. LRESULT CALLBACK SubDispEditProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
  96. /**************************************************************************/
  97. /*** Main Window Procedure. ***/
  98. /*** ***/
  99. /*** Important functions: ***/
  100. /*** 1) Gets text dimensions and sets conversion units correctly. ***/
  101. /*** ***/
  102. /*** 2) Checks the display device driver for color capability. ***/
  103. /*** If only 2 colors are available (mono, cga), bColor is ***/
  104. /*** set to FALSE, and the background brush is gray. If ***/
  105. /*** color is available, the background brush colors are read ***/
  106. /*** from WIN.INI and the brush is created. ***/
  107. /*** ***/
  108. /*** 3) Window and hidden edit control are created. ***/
  109. /*** ***/
  110. /*** 4) Contains message loop and deletes the brushes used. ***/
  111. /*** ***/
  112. /**************************************************************************/
  113. int APIENTRY WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,
  114. LPSTR lpCmdLine,
  115. int nCmdShow)
  116. {
  117. MSG msg;
  118. INT nx;
  119. LPTSTR psz;
  120. int cch = 0, cchTotal = 0;
  121. TCHAR szTempString[100] = {0};
  122. #ifdef USE_MIRRORING
  123. DWORD dwLayout;
  124. #endif
  125. // A bunch of sanity checks to ensure nobody is violating any of the
  126. // bazillion
  127. // assumptions calc makes about the order of controls. Of course these
  128. // asserts
  129. // wouldn't prevent a really dedicated person from messing things up but they
  130. // should help guide a rational person who might not be aware of calc's
  131. // idiosyncrasies.
  132. // Anyone who modifies the resource file should hit these asserts which
  133. // will then
  134. // alert them to the consequences of their actions.
  135. // IDC_0 to IDC_F must be in sequential increasing order
  136. ASSERT( 15 == (IDC_F - IDC_0) );
  137. // Binary operators IDC_AND through IDC_PWR must be in order
  138. ASSERT( (95-86) == (IDC_PWR - IDC_AND) );
  139. // Unary operators IDC_CHOP through IDC_EQU must be in order
  140. ASSERT( (112-96) == (IDC_EQU - IDC_CHOP) );
  141. // menu item id's must be in order
  142. ASSERT( 5 == (IDM_LASTMENU - IDM_FIRSTMENU) );
  143. #ifdef USE_MIRRORING
  144. if (GetProcessDefaultLayout(&dwLayout) && (dwLayout & LAYOUT_RTL))
  145. {
  146. SetProcessDefaultLayout(dwLayout & ~LAYOUT_RTL);
  147. g_fLayoutRTL = TRUE;
  148. }
  149. #endif
  150. ParseCmdLine( lpCmdLine );
  151. hInst = hInstance;
  152. if ( !InitializeWindowClass( hPrevInstance ) )
  153. return FALSE;
  154. // Read strings for keys, errors, trig types, etc.
  155. // These will be copied from the resources to local memory. A larger
  156. // than needed block is allocated first and then reallocated once we
  157. // know how much is actually used.
  158. try
  159. {
  160. psz = (LPTSTR) LocalAlloc(LPTR, ByteCountOf(CCHSTRINGSMAX));
  161. if (!psz)
  162. throw;
  163. int cchResourceBuffer = CCHSTRINGSMAX, cchLeftInBuffer;
  164. // build up an offset array in rgpsz
  165. for (nx = 0; nx <= CSTRINGS; nx++)
  166. {
  167. INT_PTR iOffset;
  168. Retry:
  169. cchLeftInBuffer = cchResourceBuffer - cchTotal;
  170. cch = 1 + LoadString(hInstance, (UINT)(IDS_FIRSTKEY + nx), psz + cchTotal, cchLeftInBuffer);
  171. if (cch == (cchResourceBuffer - cchTotal)) // woops: buffer was too small
  172. {
  173. LPTSTR pszTmp = (LPTSTR)LocalReAlloc(psz, ByteCountOf(cchResourceBuffer + CCHSTRINGSMAX), LMEM_MOVEABLE);
  174. if (!pszTmp)
  175. throw;
  176. psz = pszTmp;
  177. cchResourceBuffer += CCHSTRINGSMAX;
  178. goto Retry;
  179. }
  180. iOffset = (INT_PTR)cchTotal;
  181. rgpsz[nx] = (LPTSTR)iOffset; // first pass is offset array
  182. cchTotal += cch;
  183. }
  184. LPTSTR pszTmp = (LPTSTR)LocalReAlloc(psz, ByteCountOf(cchTotal), LMEM_MOVEABLE);
  185. if (!pszTmp)
  186. throw;
  187. psz = pszTmp;
  188. // convert the array of offsets into an array of pointers
  189. for (nx = 0 ; nx <= CSTRINGS ; nx++)
  190. rgpsz[nx] = psz + (INT_PTR)rgpsz[nx];
  191. }
  192. catch ( ... )
  193. {
  194. if (psz)
  195. LocalFree(psz);
  196. if (LoadString(hInst, IDS_NOMEM, szTempString, CharSizeOf(szTempString)))
  197. {
  198. MessageBox((HWND) NULL, szTempString, NULL, MB_OK | MB_ICONHAND);
  199. }
  200. return FALSE;
  201. }
  202. // The display in calc isn't really an edit control so we use this edit
  203. // control to simplify cutting to the clipboard
  204. hEdit = CreateWindow( TEXT("EDIT"), TEXT("CalcMsgPumpWnd"),
  205. WS_OVERLAPPED | WS_VISIBLE,
  206. CW_USEDEFAULT,0,CW_USEDEFAULT,0,
  207. NULL, NULL, hInst, NULL );
  208. // This initializes things that only need to be set up once, including a
  209. // call to ratpak so that ratpak can create any constants it needs
  210. InitialOneTimeOnlySetup();
  211. // we store in the win.ini file our desired display mode, Scientific
  212. // or Standard
  213. nCalc = (INT)GetProfileInt(szAppName, TEXT("layout"), 1);
  214. gbUseSep = (INT)GetProfileInt(szAppName, TEXT("UseSep"), 0);
  215. // InitSciCalc creates a dialog based on what the value of nCalc is.
  216. // A handle to the window that is created is stored in g_hwndDlg
  217. InitSciCalc(TRUE);
  218. hAccel = LoadAccelerators(hInst, MAKEINTRESOURCE(IDA_ACCELTABLE));
  219. while (GetMessage(&msg, NULL, 0, 0))
  220. {
  221. if (!hStatBox || !IsDialogMessage(hStatBox, &msg))
  222. {
  223. if ( ((msg.hwnd == g_hwndDlg)||IsChild(g_hwndDlg, msg.hwnd)) && TranslateAccelerator (g_hwndDlg, (HACCEL)hAccel, &msg))
  224. continue;
  225. TranslateMessage(&msg);
  226. DispatchMessage(&msg);
  227. }
  228. }
  229. LocalFree(psz);
  230. return (DWORD)msg.wParam;
  231. }
  232. /**************************************************************************\
  233. *
  234. * Command Line processing routines
  235. *
  236. * History
  237. * 22-Nov-1996 JonPa Wrote it
  238. *
  239. \**************************************************************************/
  240. #define IsWhiteSpace( ch ) ((ch) == TEXT(' ') || (ch) == TEXT('\t'))
  241. #define IsDigit( ch ) ((ch) >= TEXT('0') && (ch) <= TEXT('9'))
  242. LPTSTR TtoL( LPTSTR psz, LONG *pl ) {
  243. LONG l = 0;
  244. while( IsDigit( *psz ) ) {
  245. l = l * 10 + (*psz - TEXT('0'));
  246. psz = CharNext( psz );
  247. }
  248. *pl = l;
  249. return psz;
  250. }
  251. void ParseCmdLine( LPSTR pszCmdA ) {
  252. BOOL fInQuote;
  253. LPTSTR pszCmdT = GetCommandLine();
  254. // parse cmd line
  255. // usage: -p:## -r:## -w:## -e -x -i
  256. // -e, -x, and -i currently do nothing.
  257. // Skip app name
  258. while( *pszCmdT && IsWhiteSpace( *pszCmdT )) {
  259. pszCmdT = CharNext( pszCmdT );
  260. }
  261. fInQuote = FALSE;
  262. while( *pszCmdT && (fInQuote || !IsWhiteSpace(*pszCmdT)) ) {
  263. if (*pszCmdT == TEXT('\"'))
  264. fInQuote = !fInQuote;
  265. pszCmdT = CharNext( pszCmdT );
  266. }
  267. while( *pszCmdT )
  268. {
  269. switch( *pszCmdT )
  270. {
  271. case TEXT('p'):
  272. case TEXT('P'):
  273. // -p:## precision
  274. pszCmdT = CharNext(pszCmdT);
  275. // Skip ':' and white space
  276. while( *pszCmdT && (*pszCmdT == TEXT(':') || IsWhiteSpace(*pszCmdT)) ) {
  277. pszCmdT = CharNext(pszCmdT);
  278. }
  279. pszCmdT = TtoL( pszCmdT, &nPrecision );
  280. // a percision > C_NUM_MAX_DIGITS will allow a string too long for it's buffer
  281. if ( nPrecision > C_NUM_MAX_DIGITS)
  282. {
  283. ASSERT( nPrecision <= C_NUM_MAX_DIGITS );
  284. nPrecision = C_NUM_MAX_DIGITS;
  285. }
  286. // NOTE: this code assumes there MUST be a space after the number
  287. break;
  288. case TEXT('r'):
  289. case TEXT('R'):
  290. // -r:## Radix
  291. pszCmdT = CharNext(pszCmdT);
  292. // Skip ':' and white space
  293. while( *pszCmdT && (*pszCmdT == TEXT(':') || IsWhiteSpace(*pszCmdT)) ) {
  294. pszCmdT = CharNext(pszCmdT);
  295. }
  296. pszCmdT = TtoL( pszCmdT, &nRadix );
  297. // since the UI only has 16 keys for digit input, we only allow upto base 16
  298. if (nRadix > 16)
  299. {
  300. ASSERT( nRadix <= 16 );
  301. nRadix = 16;
  302. }
  303. else if (nRadix < 2) // you know some fool would try for base zero if you let them
  304. {
  305. ASSERT( nRadix >= 2 );
  306. nRadix = 2;
  307. }
  308. // NOTE: this code assumes there MUST be a space after the number
  309. break;
  310. case TEXT('e'):
  311. case TEXT('E'):
  312. // -e extended mode
  313. break;
  314. case TEXT('w'):
  315. case TEXT('W'):
  316. // -w:## Word size in bits
  317. pszCmdT = CharNext(pszCmdT);
  318. // Skip ':' and white space
  319. while( *pszCmdT && (*pszCmdT == TEXT(':') || IsWhiteSpace(*pszCmdT)) ) {
  320. pszCmdT = CharNext(pszCmdT);
  321. }
  322. // Set bit count
  323. pszCmdT = TtoL( pszCmdT, &dwWordBitWidth );
  324. // NOTE: this code assumes there MUST be a space after the number
  325. break;
  326. }
  327. pszCmdT = CharNext( pszCmdT );
  328. }
  329. }
  330. //////////////////////////////////////////////////
  331. //
  332. // InitalizeWindowClass
  333. //
  334. //////////////////////////////////////////////////
  335. BOOL InitializeWindowClass( HINSTANCE hPrevInstance )
  336. {
  337. WNDCLASSEX wndclass;
  338. if (!hPrevInstance)
  339. {
  340. wndclass.cbSize = sizeof(wndclass);
  341. wndclass.style = 0;
  342. wndclass.lpfnWndProc = CalcWndProc;
  343. wndclass.cbClsExtra = 0;
  344. wndclass.cbWndExtra = DLGWINDOWEXTRA;
  345. wndclass.hInstance = hInst;
  346. wndclass.hIcon = LoadIcon(hInst, TEXT("SC"));
  347. wndclass.hCursor = LoadCursor (NULL, IDC_ARROW);
  348. wndclass.hbrBackground = GetSysColorBrush(COLOR_3DFACE);
  349. wndclass.lpszMenuName = MAKEINTRESOURCE(IDM_CALCMENU);
  350. wndclass.lpszClassName = szAppName;
  351. wndclass.hIconSm = NULL;
  352. if (!RegisterClassEx(&wndclass))
  353. return FALSE;
  354. }
  355. return TRUE;
  356. }
  357. //////////////////////////////////////////////////
  358. //
  359. // InitialOneTimeOnlyNumberSetup
  360. //
  361. //////////////////////////////////////////////////
  362. void InitialOneTimeOnlySetup()
  363. {
  364. // Initialize the decimal input code. This ends up getting called twice
  365. // but it's quick so that shouldn't be a problem. Needs to be done before
  366. // SetRadix is called.
  367. CIO_vClear( &gcio );
  368. gbRecord = TRUE;
  369. // we must now setup all the ratpak constants and our arrayed pointers
  370. // to these constants.
  371. BaseOrPrecisionChanged();
  372. // these rat numbers are set only once and then never change regardless of
  373. // base or precision changes
  374. g_ahnoChopNumbers[0] = rat_qword;
  375. g_ahnoChopNumbers[1] = rat_dword;
  376. g_ahnoChopNumbers[2] = rat_word;
  377. g_ahnoChopNumbers[3] = rat_byte;
  378. // we can't call this until after we have set the radix (and thus called
  379. // ChangeConstants) so we do it last.
  380. EverythingResettingNumberSetup();
  381. NumObjAssign( &ghnoMem, HNO_ZERO );
  382. }
  383. //////////////////////////////////////////////////
  384. //
  385. // EverythingResettingNumberSetup
  386. //
  387. //////////////////////////////////////////////////
  388. void EverythingResettingNumberSetup()
  389. {
  390. int i;
  391. // Initialize the decimal input code.
  392. CIO_vClear( &gcio );
  393. gbRecord = TRUE;
  394. NumObjAssign( &ghnoNum, HNO_ZERO );
  395. NumObjAssign( &ghnoLastNum, HNO_ZERO );
  396. // REVIEW: is it just me, or do we speew major memory wheneven this method
  397. // executes?
  398. // array used to handle ( and )
  399. for( i = 0; i < ARRAYSIZE(ghnoParNum); i++ )
  400. ghnoParNum[i] = NULL;
  401. // array used to handle order of operations
  402. for( i = 0; i < ARRAYSIZE(ghnoPrecNum); i++ )
  403. ghnoPrecNum[i] = NULL;
  404. gpszNum = (LPTSTR)NumObjAllocMem( sizeof(szInitNum) );
  405. if (gpszNum)
  406. {
  407. lstrcpy( gpszNum, szInitNum );
  408. }
  409. }
  410. //////////////////////////////////////////////////
  411. //
  412. // InitSciCalc
  413. //
  414. //////////////////////////////////////////////////
  415. VOID APIENTRY InitSciCalc(BOOL bViewChange)
  416. {
  417. TCHAR chLastDec;
  418. TCHAR chLastSep;
  419. int nLastSepLen;
  420. UINT nLastDecGrouping;
  421. HMENU hMenu;
  422. HWND hDispEdit;
  423. BOOL bRepaint=FALSE;
  424. RECT rect = {0,0,0,0};
  425. TCHAR szGrouping[32];
  426. EverythingResettingNumberSetup();
  427. // when we switch modes, we need to remind the ui that we are no longer
  428. // inputing the number we were inputting before we switched modes.
  429. gbRecord = FALSE; // REVIEW: This should not be needed with the new initialization
  430. chLastDec = szDec[0];
  431. chLastSep = gszSep[0];
  432. nLastDecGrouping=gnDecGrouping;
  433. GetProfileString(TEXT("intl"), TEXT("sDecimal"), TEXT("."),
  434. szDec, CharSizeOf(szDec));
  435. GetProfileString(TEXT("intl"), TEXT("sThousand"), TEXT(","),
  436. gszSep, CharSizeOf(gszSep));
  437. ZeroMemory(szGrouping,sizeof(szGrouping));
  438. GetProfileString(TEXT("intl"), TEXT("sGrouping"), TEXT("3;0"),
  439. szGrouping, CharSizeOf(szGrouping));
  440. gnDecGrouping=DigitGroupingStringToGroupingNum(szGrouping);
  441. // if the grouping pattern changed we always do the following things
  442. if (gnDecGrouping != nLastDecGrouping)
  443. {
  444. nLastDecGrouping=gnDecGrouping;
  445. bRepaint=TRUE;
  446. }
  447. // if the thousands symbol has changed we always do the following things
  448. if ( gszSep[0] != chLastSep )
  449. {
  450. chLastSep = gszSep[0];
  451. bRepaint = TRUE;
  452. }
  453. // if the decimal symbol has changed we always do the following things
  454. if ( szDec[0] != chLastDec )
  455. {
  456. chLastDec = szDec[0];
  457. // Re-initialize input string's decimal point.
  458. CIO_vUpdateDecimalSymbol(&gcio, chLastDec);
  459. // put the new decimal symbol into the table used to draw the decimal
  460. // key
  461. *(rgpsz[IDS_DECIMAL]) = chLastDec;
  462. // we need to redraw to update the decimal point button
  463. bRepaint = TRUE;
  464. }
  465. {
  466. HIGHCONTRAST hc;
  467. hc.cbSize = sizeof(hc);
  468. if ( SystemParametersInfo(SPI_GETHIGHCONTRAST, sizeof(hc), &hc, 0) )
  469. {
  470. if ( BOOLIFY(hc.dwFlags & HCF_HIGHCONTRASTON) != g_fHighContrast )
  471. {
  472. g_fHighContrast = BOOLIFY(hc.dwFlags & HCF_HIGHCONTRASTON);
  473. bRepaint = TRUE;
  474. }
  475. }
  476. }
  477. if ( bViewChange )
  478. {
  479. BOOL bUseOldPos = FALSE;
  480. // if we are changing views we destory the old window and create
  481. // a new window
  482. if ( g_hwndDlg )
  483. {
  484. SetMenu(g_hwndDlg, g_hDecMenu);
  485. bUseOldPos = TRUE;
  486. GetWindowRect( g_hwndDlg, &rect );
  487. DestroyWindow( g_hwndDlg );
  488. DestroyMenu(g_hHexMenu);
  489. g_hHexMenu=NULL;
  490. }
  491. // create the correct window for the mode we're currently in
  492. if ( nCalc )
  493. {
  494. // switch to standard mode
  495. g_hwndDlg = CreateDialog(hInst, MAKEINTRESOURCE(IDD_STANDARD), 0,
  496. NULL);
  497. g_hDecMenu=GetMenu(g_hwndDlg);
  498. #ifdef USE_MIRRORING
  499. if (g_fLayoutRTL)
  500. {
  501. SetWindowLong(g_hwndDlg,
  502. GWL_EXSTYLE,
  503. GetWindowLong(g_hwndDlg,GWL_EXSTYLE) | \
  504. WS_EX_LAYOUTRTL | WS_EX_NOINHERITLAYOUT);
  505. }
  506. #endif
  507. }
  508. else
  509. {
  510. // switch to scientific mode
  511. g_hwndDlg = CreateDialog(hInst, MAKEINTRESOURCE(IDD_SCIENTIFIC),
  512. 0, NULL);
  513. g_hDecMenu=GetMenu(g_hwndDlg);
  514. g_hHexMenu=LoadMenu(hInst, MAKEINTRESOURCE(IDM_HEXCALCMENU));
  515. #ifdef USE_MIRRORING
  516. if (g_fLayoutRTL)
  517. {
  518. SetWindowLong(g_hwndDlg,
  519. GWL_EXSTYLE,
  520. GetWindowLong(g_hwndDlg,GWL_EXSTYLE) | WS_EX_LAYOUTRTL | WS_EX_NOINHERITLAYOUT);
  521. }
  522. #endif
  523. // Stat box is initially off, disable stat buttons.
  524. for ( int iID = IDC_AVE; iID <= IDC_DATA; iID++ )
  525. EnableWindow( GetDlgItem( g_hwndDlg, iID ), FALSE );
  526. SwitchModes(10, nDecMode, nHexMode);
  527. // If precision won't fit in display, then resize it
  528. if (nPrecision > 32)
  529. {
  530. HWND hwndDisplay;
  531. RECT rc, rcMain;
  532. hwndDisplay=GetDlgItem( g_hwndDlg, IDC_DISPLAY );
  533. GetWindowRect( hwndDisplay, &rc );
  534. GetClientRect( g_hwndDlg, &rcMain );
  535. MapWindowPoints( g_hwndDlg, NULL, (LPPOINT)&rcMain, 2);
  536. rc.left = rcMain.left + (rcMain.right - rc.right);
  537. OffsetRect( &rc, -(rcMain.left), -(rcMain.top) );
  538. SetWindowPos(hwndDisplay, NULL,
  539. rc.left, rc.top,
  540. rc.right - rc.left, rc.bottom - rc.top,
  541. SWP_NOACTIVATE | SWP_NOZORDER );
  542. }
  543. }
  544. if (hDispEdit = GetDlgItem(g_hwndDlg, IDC_DISPLAY))
  545. {
  546. // subclass the Edit Control hide caret and filter out mouse msg
  547. fpOrgDispEditProc = (WNDPROC)GetWindowLongPtr(hDispEdit, GWLP_WNDPROC);
  548. if (fpOrgDispEditProc)
  549. SetWindowLongPtr(hDispEdit, GWLP_WNDPROC, (LONG_PTR)(WNDPROC)SubDispEditProc);
  550. }
  551. // keep calc in the same place it was before
  552. if ( bUseOldPos )
  553. {
  554. SetWindowPos( g_hwndDlg, NULL, rect.left, rect.top, 0,0,
  555. SWP_NOZORDER | SWP_NOSIZE );
  556. }
  557. // ensure the menu items for Scientific and Standard are set correctly
  558. CheckMenuRadioItem(g_hDecMenu, IDM_SC, IDM_SSC,
  559. (nCalc == 0 ? IDM_SC : IDM_SSC), MF_BYCOMMAND);
  560. CheckMenuItem(g_hDecMenu, IDM_USE_SEPARATOR,
  561. MF_BYCOMMAND | (gbUseSep ? MF_CHECKED : MF_UNCHECKED));
  562. if (g_hHexMenu)
  563. {
  564. CheckMenuRadioItem(g_hHexMenu, IDM_SC, IDM_SSC,
  565. (nCalc == 0 ? IDM_SC : IDM_SSC), MF_BYCOMMAND);
  566. CheckMenuItem(g_hHexMenu, IDM_USE_SEPARATOR,
  567. MF_BYCOMMAND | (gbUseSep ? MF_CHECKED:MF_UNCHECKED));
  568. }
  569. // To ensure that the call to SetRadix correctly update the active
  570. // state of the buttons on
  571. // SciCalc we must tell it to forget the previous Radix
  572. {
  573. extern long oldRadix;
  574. oldRadix = (unsigned)-1;
  575. }
  576. // this will set the correct buttons on the UI
  577. SetRadix(10);
  578. SetDlgItemText(g_hwndDlg, IDC_MEMTEXT,
  579. NumObjIsZero(ghnoMem) ? (szBlank) : (TEXT(" M")) );
  580. SendMessage(g_hwndDlg, WM_CHANGEUISTATE, MAKEWPARAM(UIS_INITIALIZE, 0), 0);
  581. ShowWindow( g_hwndDlg, SW_SHOW );
  582. UpdateWindow(g_hwndDlg);
  583. } // END if ( bViewChanged )
  584. else if ( bRepaint )
  585. {
  586. // no need to repaint if we just changed views
  587. InvalidateRect( g_hwndDlg, NULL, TRUE );
  588. }
  589. }