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.

814 lines
21 KiB

  1. #include "sol.h"
  2. #include <shellapi.h> // To pick up ShellAbout()
  3. #include <htmlhelp.h>
  4. #include <commctrl.h> // for fusion classes.
  5. VSZASSERT
  6. #define rgbGreen RGB(0x00,0x80,0x00)
  7. #define rgbWhite RGB(0xff,0xff,0xff)
  8. PT ptNil = {0x7fff, 0x7fff};
  9. TCHAR szAppName[10]; // name of this app: 'solitaire'
  10. TCHAR szScore[50]; // 'score:' for internationalization
  11. /* Instance info */
  12. static HANDLE hAccel; // accelerators handle
  13. HWND hwndApp; // window handle to this app
  14. HANDLE hinstApp; // instance handle to this app
  15. BOOL fBW=FALSE; // true if on true monochrome video! (never true on NT)
  16. HBRUSH hbrTable; // brush for background of table top
  17. LONG rgbTable; // RGB value of table top
  18. BOOL fIconic = fFalse; // true if app is 'iconic'
  19. INT dyChar; // tmHeight of font in hdc
  20. INT dxChar; // tmMaxCharWidth of font in hdc
  21. #define modeNil -1
  22. INT modeFaceDown = modeNil; // back of cards ID
  23. GM *pgmCur = NULL; // current game
  24. /* card extent info */
  25. DEL delCrd;
  26. DEL delScreen;
  27. RC rcClient; // client rectangle
  28. INT igmCur; /* the current game #, srand seeded with this */
  29. #ifdef DEBUG
  30. BOOL fScreenShots = fFalse;
  31. #endif
  32. /* window messages for external app drawing */
  33. static UINT wmCardDraw;
  34. HDC hdcCur = NULL; // current hdc to draw on
  35. INT usehdcCur = 0; // hdcCur use count
  36. X xOrgCur = 0;
  37. Y yOrgCur = 0;
  38. static TCHAR szClass[] = TEXT("Solitaire");
  39. TCHAR szOOM[50];
  40. // BUG: some of these should go in gm struct
  41. //
  42. BOOL fStatusBar = fTrue;
  43. BOOL fTimedGame = fTrue;
  44. BOOL fKeepScore = fFalse;
  45. SMD smd = smdStandard; /* Score MoDe */
  46. INT ccrdDeal = 3;
  47. BOOL fOutlineDrag = fFalse;
  48. BOOL fHalfCards = fFalse;
  49. INT xCardMargin;
  50. #define MIN_MARGIN (dxCrd / 8 + 3)
  51. /******************** Internal Functions ****************/
  52. BOOL FSolInit( HANDLE, HANDLE, LPTSTR, INT );
  53. VOID GetIniFlags( BOOL * );
  54. VOID APIENTRY cdtTerm( VOID );
  55. VOID DoHelp( INT );
  56. LRESULT APIENTRY SolWndProc(HWND, UINT, WPARAM, LPARAM);
  57. // International stuff
  58. //
  59. INT iCurrency;
  60. TCHAR szCurrency[5];
  61. /******************************************************************************
  62. * WINMAIN/ENTRY POINT
  63. * This is the main entry-point for the application. It uses the porting
  64. * macro MMain() since it was ported from 16bit Windows.
  65. *
  66. * The accelerator-table was added from demo-purposes.
  67. *
  68. *
  69. *****************************************************************************/
  70. MMain( hinst, hinstPrev, lpstrCmdLine, sw )
  71. MSG msg;
  72. LPTSTR lpszCmdLine = GetCommandLine();
  73. // Initialize the application.
  74. //
  75. if (!FSolInit(hinst, hinstPrev, lpszCmdLine, sw))
  76. return(0);
  77. // Message-Polling loop.
  78. //
  79. msg.wParam = 1;
  80. while (GetMessage((LPMSG)&msg, NULL, 0, 0))
  81. {
  82. if( !TranslateAccelerator( hwndApp, hAccel, &msg ))
  83. {
  84. TranslateMessage((LPMSG)&msg);
  85. DispatchMessage((LPMSG)&msg);
  86. }
  87. }
  88. return ((int)(msg.wParam ? 1 : 0));
  89. // Eliminate unreferenced-variable warnings from
  90. // porting macro.
  91. //
  92. (void)_argv;
  93. (void)_argc;
  94. }
  95. /******************************************************************************
  96. * FSolInit
  97. *
  98. * Main program initialization.
  99. *
  100. * Arguments:
  101. * hinst - instance of this task
  102. * hinstPrev - previous instance, or NULL if this is the
  103. * first instance
  104. * lpszCmdLine - command line argument string
  105. * sw - show window command
  106. *
  107. * Returns:
  108. * fFalse on failure.
  109. *
  110. *****************************************************************************/
  111. BOOL FSolInit(HANDLE hinst, HANDLE hinstPrev, LPTSTR lpszCmdLine, INT sw)
  112. {
  113. WNDCLASSEX cls;
  114. HDC hdc;
  115. TEXTMETRIC tm;
  116. HANDLE hcrsArrow;
  117. BOOL fStartIconic;
  118. TCHAR FAR *lpch;
  119. BOOL fOutline;
  120. TCHAR szT[20];
  121. RECT rect;
  122. INITCOMMONCONTROLSEX icc; // common control registration.
  123. WORD APIENTRY TimerProc(HWND, UINT, UINT_PTR, DWORD);
  124. hinstApp = hinst;
  125. /* create stock objects */
  126. CchString(szOOM, idsOOM, ARRAYSIZE(szOOM));
  127. if(!cdtInit((INT FAR *)&dxCrd, (INT FAR *)&dyCrd))
  128. {
  129. goto OOMError;
  130. }
  131. hcrsArrow = LoadCursor(NULL, IDC_ARROW);
  132. hdc = GetDC(NULL);
  133. if(hdc == NULL)
  134. {
  135. OOMError:
  136. OOM();
  137. return fFalse;
  138. }
  139. GetTextMetrics(hdc, (LPTEXTMETRIC)&tm);
  140. dyChar = tm.tmHeight;
  141. dxChar = tm.tmMaxCharWidth;
  142. if (GetDeviceCaps(hdc, NUMCOLORS) == 2)
  143. fBW = fTrue;
  144. /* BUG: if HORZRES not big enough, have to call cdtDrawExt & shrink dxCrd */
  145. /* BUG: Need to check VERTRES and divide dxCrd by 2 (esp w/ lores ega) */
  146. dxScreen = GetDeviceCaps(hdc, HORZRES);
  147. dyScreen = GetDeviceCaps(hdc, VERTRES);
  148. if(fHalfCards = dyScreen < 300)
  149. dyCrd /= 2;
  150. ReleaseDC(NULL, hdc);
  151. rgbTable = fBW ? rgbWhite : rgbGreen;
  152. hbrTable = CreateSolidBrush(rgbTable);
  153. srand((WORD) time(NULL));
  154. /* load strings */
  155. CchString(szAppName, idsAppName, ARRAYSIZE(szAppName));
  156. CchString(szScore, idsScore, ARRAYSIZE(szScore));
  157. CchString(szT, idsCardDraw, ARRAYSIZE(szT));
  158. wmCardDraw = RegisterWindowMessage(szT);
  159. /* scan cmd line to see if should come up iconic */
  160. /* this may be unnecessary with win3.0 (function may be provided to */
  161. /* do it automatically */
  162. fStartIconic = fFalse;
  163. for(lpch = lpszCmdLine; *lpch != TEXT('\000'); lpch++)
  164. {
  165. if(*lpch == TEXT('/') && *(lpch+1) == TEXT('I'))
  166. {
  167. fStartIconic = fTrue;
  168. break;
  169. }
  170. }
  171. // Register the common controls.
  172. icc.dwSize = sizeof(INITCOMMONCONTROLSEX);
  173. icc.dwICC = ICC_ANIMATE_CLASS | ICC_BAR_CLASSES | ICC_COOL_CLASSES | ICC_HOTKEY_CLASS | ICC_LISTVIEW_CLASSES |
  174. ICC_PAGESCROLLER_CLASS | ICC_PROGRESS_CLASS | ICC_TAB_CLASSES | ICC_UPDOWN_CLASS | ICC_USEREX_CLASSES;
  175. InitCommonControlsEx(&icc);
  176. /* Load the solitaire icon */
  177. hIconMain = LoadIcon(hinstApp, MAKEINTRESOURCE(ID_ICON_MAIN));
  178. /* Load the solitaire icon image */
  179. hImageMain = LoadImage(hinstApp, MAKEINTRESOURCE(ID_ICON_MAIN),
  180. IMAGE_ICON, 16, 16, LR_DEFAULTCOLOR);
  181. /* register window classes */
  182. if (hinstPrev == NULL)
  183. {
  184. ZeroMemory( &cls, sizeof(cls) );
  185. cls.cbSize= sizeof(cls);
  186. cls.style = CS_BYTEALIGNWINDOW | CS_DBLCLKS,
  187. cls.lpfnWndProc = SolWndProc;
  188. cls.hInstance = hinstApp;
  189. cls.hIcon = hIconMain;
  190. cls.hIconSm= hImageMain;
  191. cls.hCursor = hcrsArrow;
  192. cls.hbrBackground = hbrTable;
  193. cls.lpszMenuName = MAKEINTRESOURCE(idmSol);
  194. cls.lpszClassName = (LPTSTR)szClass;
  195. if (!RegisterClassEx(&cls))
  196. {
  197. goto OOMError;
  198. }
  199. }
  200. /* Determine the proper starting size for the window */
  201. /* Card margin is just a little bigger than 1/8 of a card */
  202. xCardMargin = MIN_MARGIN;
  203. /* We need 7 card widths and 8 margins */
  204. rect.right = dxCrd * 7 + 8 * xCardMargin;
  205. /* Compute the window size we need for a client area this big */
  206. rect.bottom = dyCrd * 4;
  207. rect.left = rect.top = 0;
  208. AdjustWindowRect(&rect, WS_OVERLAPPEDWINDOW, TRUE);
  209. rect.right -= rect.left;
  210. rect.bottom -= rect.top;
  211. /* Make sure it's not too big */
  212. if (rect.bottom > dyScreen)
  213. rect.bottom = dyScreen;
  214. /* create our windows */
  215. if (!
  216. (hwndApp = CreateWindow( (LPTSTR)szClass, (LPTSTR)szAppName,
  217. fStartIconic ? WS_OVERLAPPEDWINDOW | WS_MINIMIZE | WS_CLIPCHILDREN:
  218. WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN,
  219. CW_USEDEFAULT, 0,
  220. rect.right, rect.bottom,
  221. (HWND)NULL, (HMENU)NULL, hinstApp, (LPTSTR)NULL)))
  222. {
  223. goto OOMError;
  224. }
  225. GetIniFlags(&fOutline);
  226. if(SetTimer(hwndApp, 666, 250, TimerProc) == 0)
  227. {
  228. goto OOMError;
  229. }
  230. FInitGm();
  231. FSetDrag(fOutline);
  232. ShowWindow(hwndApp, sw);
  233. UpdateWindow(hwndApp);
  234. hAccel = LoadAccelerators( hinst, TEXT("HiddenAccel") );
  235. FRegisterStat(hinstPrev == NULL);
  236. if(fStatusBar)
  237. FCreateStat();
  238. Assert(pgmCur != NULL);
  239. if(sw != SW_SHOWMINNOACTIVE && sw != SW_MINIMIZE)
  240. PostMessage(hwndApp, WM_COMMAND, idsInitiate, 0L);
  241. return(fTrue);
  242. }
  243. VOID DoPaint(HWND hwnd)
  244. {
  245. PAINTSTRUCT paint;
  246. BeginPaint(hwnd, (LPPAINTSTRUCT) &paint);
  247. if(pgmCur)
  248. SendGmMsg(pgmCur, msggPaint, (INT_PTR) &paint, 0);
  249. EndPaint(hwnd, (LPPAINTSTRUCT) &paint);
  250. }
  251. /* SolWndProc
  252. *
  253. * Window procedure for main Sol window.
  254. *
  255. * Arguments:
  256. * hwnd - window handle receiving the message - should
  257. * be hwndSol
  258. * wm - window message
  259. * wParam, lParam - more info as required by wm
  260. *
  261. * Returns:
  262. * depends on the message
  263. */
  264. LRESULT APIENTRY SolWndProc(HWND hwnd, UINT wm, WPARAM wParam, LPARAM lParam)
  265. {
  266. HMENU hmenu;
  267. PT pt;
  268. INT msgg;
  269. VOID NewGame();
  270. VOID StatString();
  271. switch (wm)
  272. {
  273. default:
  274. if(wm == wmCardDraw)
  275. {
  276. switch(wParam)
  277. {
  278. case drwInit:
  279. return MAKELONG(dxCrd, dyCrd);
  280. case drwDrawCard:
  281. #define lpcddr ((CDDR FAR *)lParam)
  282. return cdtDraw(lpcddr->hdc, lpcddr->x, lpcddr->y, lpcddr->cd, lpcddr->mode, lpcddr->rgbBgnd);
  283. #undef lpcddr
  284. case drwClose:
  285. PostMessage(hwndApp, WM_SYSCOMMAND, SC_CLOSE, 0L);
  286. return fTrue;
  287. }
  288. }
  289. break;
  290. case WM_HELP:
  291. DoHelp( idsHelpIndex );
  292. break;
  293. case WM_DESTROY:
  294. KillTimer(hwndApp, 666);
  295. SendGmMsg(pgmCur, msggEnd, 0, 0);
  296. FSetDrag(fTrue); /* Free up screen bitmaps if we made em */
  297. cdtTerm();
  298. DeleteObject(hbrTable);
  299. PostQuitMessage(0);
  300. break;
  301. case WM_ACTIVATE:
  302. if( GET_WM_ACTIVATE_STATE(wParam, lParam) &&
  303. !GET_WM_ACTIVATE_FMINIMIZED(wParam, lParam) )
  304. DoPaint(hwnd);
  305. break;
  306. case WM_KILLFOCUS:
  307. if(pgmCur->fButtonDown)
  308. SendGmMsg(pgmCur, msggMouseUp, 0, fTrue);
  309. /* Fall through. */
  310. case WM_SETFOCUS:
  311. ShowCursor(wm == WM_SETFOCUS);
  312. break;
  313. case WM_SIZE:
  314. {
  315. int nNewMargin;
  316. int nMinMargin;
  317. fIconic = IsIconic(hwnd);
  318. GetClientRect(hwnd, (LPRECT) &rcClient);
  319. /* Compute the new margin size if any and if necessary, redraw */
  320. nNewMargin = ((short)lParam - 7 * (short)dxCrd) / 8;
  321. nMinMargin = MIN_MARGIN;
  322. if (nNewMargin < nMinMargin && xCardMargin != nMinMargin)
  323. nNewMargin = nMinMargin;
  324. if (nNewMargin >= nMinMargin)
  325. {
  326. xCardMargin = nNewMargin;
  327. PositionCols();
  328. InvalidateRect(hwnd, NULL, TRUE);
  329. }
  330. /* Code always falls through here */
  331. }
  332. case WM_MOVE:
  333. StatMove();
  334. break;
  335. case WM_MENUSELECT:
  336. // Don't send in garbage if not a menu item
  337. if( GET_WM_MENUSELECT_FLAGS( wParam, lParam ) & MF_POPUP ||
  338. GET_WM_MENUSELECT_FLAGS( wParam, lParam ) & MF_SYSMENU ||
  339. GET_WM_MENUSELECT_FLAGS( wParam, lParam ) & MF_SEPARATOR ) {
  340. StatString(idsNil);
  341. }
  342. else {
  343. StatString( GET_WM_MENUSELECT_CMD( wParam, lParam ));
  344. }
  345. break;
  346. case WM_KEYDOWN:
  347. Assert(pgmCur);
  348. SendGmMsg(pgmCur, msggKeyHit, wParam, 0);
  349. break;
  350. case WM_LBUTTONDOWN:
  351. /* ProfStart(); */
  352. SetCapture(hwnd);
  353. if(pgmCur->fButtonDown)
  354. break;
  355. msgg = msggMouseDown;
  356. goto DoMouse;
  357. case WM_LBUTTONDBLCLK:
  358. msgg = msggMouseDblClk;
  359. if(pgmCur->fButtonDown)
  360. break;
  361. goto DoMouse;
  362. case WM_RBUTTONDOWN:
  363. // If the left mousebutton is down, ignore the right click.
  364. if (GetCapture())
  365. break;
  366. msgg = msggMouseRightClk;
  367. goto DoMouse;
  368. case WM_LBUTTONUP:
  369. /* ProfStop(); */
  370. ReleaseCapture();
  371. msgg = msggMouseUp;
  372. if(!pgmCur->fButtonDown)
  373. break;
  374. goto DoMouse;
  375. case WM_MOUSEMOVE:
  376. msgg = msggMouseMove;
  377. if(!pgmCur->fButtonDown)
  378. break;
  379. DoMouse:
  380. Assert(pgmCur != NULL);
  381. LONG2POINT( lParam, pt );
  382. Assert(pgmCur);
  383. SendGmMsg(pgmCur, msgg, (INT_PTR) &pt, 0);
  384. break;
  385. case WM_COMMAND:
  386. switch( GET_WM_COMMAND_ID( wParam, lParam ))
  387. {
  388. /* Game menu */
  389. case idsInitiate:
  390. NewGame(fTrue, fFalse);
  391. break;
  392. case idsUndo:
  393. Assert(pgmCur);
  394. SendGmMsg(pgmCur, msggUndo, 0, 0);
  395. break;
  396. case idsBacks:
  397. DoBacks();
  398. break;
  399. case idsOptions:
  400. DoOptions();
  401. break;
  402. case idsExit:
  403. PostMessage(hwnd, WM_SYSCOMMAND, SC_CLOSE, 0L);
  404. break;
  405. /* Help Menu */
  406. case (WORD)idsHelpIndex:
  407. case (WORD)idsHelpSearch:
  408. case (WORD)idsHelpUsing:
  409. DoHelp( (INT)(SHORT)GET_WM_COMMAND_ID( wParam, lParam ));
  410. break;
  411. case idsAbout:
  412. {
  413. TCHAR szExtraInfo[100];
  414. CchString(szExtraInfo, idsExtraInfo, ARRAYSIZE(szExtraInfo));
  415. #ifndef _GAMBIT_
  416. ShellAbout(hwnd, szAppName, szExtraInfo, hIconMain);
  417. #endif
  418. break;
  419. }
  420. case idsForceWin:
  421. SendGmMsg(pgmCur, msggForceWin, 0, 0);
  422. break;
  423. #ifdef DEBUG
  424. case idsGameNo:
  425. if(FSetGameNo())
  426. NewGame(fFalse, fFalse);
  427. break;
  428. case idsCardMacs:
  429. PrintCardMacs(pgmCur);
  430. break;
  431. case idsAssertFail:
  432. Assert(fFalse);
  433. break;
  434. case idsMarquee:
  435. break;
  436. case idsScreenShots:
  437. fScreenShots ^= 1;
  438. CheckMenuItem(GetMenu(hwnd), idsScreenShots, fScreenShots ? MF_CHECKED|MF_BYCOMMAND : MF_UNCHECKED|MF_BYCOMMAND);
  439. InvalidateRect(hwndStat, NULL, fTrue);
  440. if(fScreenShots)
  441. InvalidateRect(hwnd, NULL, fTrue);
  442. break;
  443. #endif
  444. default:
  445. break;
  446. }
  447. break;
  448. case WM_INITMENU:
  449. hmenu = GetMenu(hwnd);
  450. Assert(pgmCur);
  451. EnableMenuItem(hmenu, idsUndo,
  452. pgmCur->udr.fAvail && !FSelOfGm(pgmCur) ? MF_ENABLED : MF_DISABLED|MF_GRAYED);
  453. EnableMenuItem(hmenu, idsInitiate, FSelOfGm(pgmCur) ? MF_DISABLED|MF_GRAYED : MF_ENABLED);
  454. EnableMenuItem(hmenu, idsBacks, FSelOfGm(pgmCur) ? MF_DISABLED|MF_GRAYED : MF_ENABLED);
  455. EnableMenuItem(hmenu, idsAbout, FSelOfGm(pgmCur) ? MF_DISABLED|MF_GRAYED : MF_ENABLED);
  456. break;
  457. case WM_PAINT:
  458. if(!fIconic)
  459. {
  460. DoPaint(hwnd);
  461. return(0L);
  462. }
  463. break;
  464. }
  465. return(DefWindowProc(hwnd, wm, wParam, lParam));
  466. }
  467. HDC HdcSet(HDC hdc, X xOrg, Y yOrg)
  468. {
  469. HDC hdcT = hdcCur;
  470. hdcCur = hdc;
  471. xOrgCur = xOrg;
  472. yOrgCur = yOrg;
  473. return hdcT;
  474. }
  475. BOOL FGetHdc()
  476. {
  477. HDC hdc;
  478. Assert(hwndApp);
  479. if(hdcCur != NULL)
  480. {
  481. usehdcCur++;
  482. return fTrue;
  483. }
  484. hdc = GetDC(hwndApp);
  485. if(hdc == NULL)
  486. return fFalse;
  487. HdcSet(hdc, 0, 0);
  488. usehdcCur = 1;
  489. return fTrue;
  490. }
  491. VOID ReleaseHdc()
  492. {
  493. if(hdcCur == NULL)
  494. return;
  495. if(--usehdcCur == 0)
  496. {
  497. ReleaseDC(hwndApp, hdcCur);
  498. hdcCur = NULL;
  499. }
  500. }
  501. WORD APIENTRY TimerProc(HWND hwnd, UINT wm, UINT_PTR id, DWORD dwTime)
  502. {
  503. if(pgmCur != NULL)
  504. SendGmMsg(pgmCur, msggTimer, 0, 0);
  505. return fTrue;
  506. }
  507. VOID ChangeBack(INT mode)
  508. {
  509. if(mode == modeFaceDown)
  510. return;
  511. modeFaceDown = mode;
  512. InvalidateRect(hwndApp, NULL, fTrue);
  513. }
  514. VOID NewGame(BOOL fNewSeed, BOOL fZeroScore)
  515. {
  516. #ifdef DEBUG
  517. InitDebug();
  518. #endif
  519. if(fNewSeed)
  520. {
  521. static INT lastrnd= -1; // previous rand() value
  522. INT rnd1; // trial rand() value
  523. INT Param;
  524. // It was reported that games never changed.
  525. // We could not repro it so see if it happens
  526. // and output a message to the debugger.
  527. //
  528. Param= (INT) time(NULL);
  529. srand( igmCur = ((WORD) Param) & 0x7fff);
  530. #ifdef DEBUG
  531. rnd1= rand();
  532. if( lastrnd == rnd1 )
  533. {
  534. TCHAR szText[100];
  535. wsprintf(szText,TEXT("Games repeat: time= %d GetLastError= %d\n"),
  536. Param, GetLastError());
  537. OutputDebugString(szText);
  538. }
  539. lastrnd= rnd1;
  540. #endif
  541. }
  542. #ifdef DEBUG
  543. SendGmMsg(pgmCur, msggChangeScore, 0, 0);
  544. #endif
  545. SendGmMsg(pgmCur, msggDeal, fZeroScore, 0);
  546. }
  547. INT_PTR APIENTRY About(HWND hdlg, UINT iMessage, WPARAM wParam, LPARAM lParam)
  548. {
  549. if (iMessage == WM_COMMAND)
  550. {
  551. EndDialog(hdlg,fTrue);
  552. return fTrue;
  553. }
  554. else if (iMessage == WM_INITDIALOG)
  555. return fTrue;
  556. else
  557. return fFalse;
  558. }
  559. VOID DoHelp(INT idContext)
  560. {
  561. CHAR sz[100];
  562. HWND hwndResult;
  563. LoadStringA(hinstApp, (WORD)idsHelpFile, (LPSTR)sz, 100);
  564. #ifndef _GAMBIT_
  565. switch(idContext)
  566. {
  567. case idsHelpUsing:
  568. hwndResult = HtmlHelpA(GetDesktopWindow(), "NTHelp.chm", HH_DISPLAY_TOPIC, 0);
  569. break;
  570. case idsHelpIndex:
  571. hwndResult = HtmlHelpA(GetDesktopWindow(), sz, HH_DISPLAY_TOPIC, 0);
  572. break;
  573. case idsHelpSearch:
  574. hwndResult = HtmlHelpA(GetDesktopWindow(), sz, HH_DISPLAY_INDEX, 0);
  575. break;
  576. }
  577. if(!hwndResult)
  578. ErrorIds(idsNoHelp);
  579. #endif
  580. }
  581. VOID GetIniFlags(BOOL *pfOutline)
  582. {
  583. INI ini;
  584. INT mode;
  585. TCHAR szDefCurrency[5];
  586. INT iDefCurrency;
  587. ini.w = 0;
  588. ini.grbit.fStatusBar = fStatusBar;
  589. ini.grbit.fTimedGame = fTimedGame;
  590. ini.grbit.fOutlineDrag = fOutlineDrag;
  591. ini.grbit.fDrawThree = ccrdDeal == 3;
  592. ini.grbit.fKeepScore = fKeepScore;
  593. ini.grbit.fSMD = 0;
  594. ini.w = GetIniInt(idsAppName, idsOpts, ini.w);
  595. fStatusBar = ini.grbit.fStatusBar ? 1 : 0;
  596. fTimedGame = ini.grbit.fTimedGame ? 1 : 0;
  597. *pfOutline = ini.grbit.fOutlineDrag ? 1 : 0;
  598. ccrdDeal = ini.grbit.fDrawThree ? 3 : 1;
  599. fKeepScore = ini.grbit.fKeepScore ? 1 : 0;
  600. switch(ini.grbit.fSMD)
  601. {
  602. default:
  603. smd = smdStandard;
  604. break;
  605. case 1:
  606. smd = smdVegas;
  607. break;
  608. case 2:
  609. smd = smdNone;
  610. break;
  611. }
  612. mode = GetIniInt(idsAppName, idsBack, rand() % cIDFACEDOWN) + IDFACEDOWNFIRST-1;
  613. ChangeBack(PegRange(mode, IDFACEDOWNFIRST, IDFACEDOWN12));
  614. // get the default user currency.
  615. if (GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SCURRENCY, szDefCurrency, sizeof(szDefCurrency)/sizeof(TCHAR)) == 0)
  616. lstrcpy(szDefCurrency, TEXT("$"));
  617. if (GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_ICURRENCY, (LPTSTR) &iDefCurrency, sizeof(iDefCurrency)) == 0)
  618. iDefCurrency = 0;
  619. iCurrency = GetIniInt(idsIntl, idsiCurrency, iDefCurrency);
  620. FGetIniString(idsIntl, idssCurrency, szCurrency, szDefCurrency, sizeof(szCurrency));
  621. }
  622. VOID WriteIniFlags(INT wif)
  623. {
  624. INI ini;
  625. if(wif & wifOpts)
  626. {
  627. ini.w = 0;
  628. ini.grbit.fStatusBar = fStatusBar;
  629. ini.grbit.fTimedGame = fTimedGame;
  630. ini.grbit.fOutlineDrag = fOutlineDrag;
  631. ini.grbit.fDrawThree = ccrdDeal == 3;
  632. ini.grbit.fKeepScore = fKeepScore;
  633. switch(smd)
  634. {
  635. default:
  636. Assert(fFalse);
  637. break;
  638. case smdStandard:
  639. ini.grbit.fSMD = 0;
  640. break;
  641. case smdVegas:
  642. ini.grbit.fSMD = 1;
  643. break;
  644. case smdNone:
  645. ini.grbit.fSMD = 2;
  646. break;
  647. }
  648. FWriteIniInt(idsAppName, idsOpts, ini.w);
  649. }
  650. if(wif & wifBack)
  651. FWriteIniInt(idsAppName, idsBack, modeFaceDown-IDFACEDOWNFIRST+1);
  652. }