Leaked source code of windows server 2003
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.

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