Index: base/applications/games/solitaire/solitaire.cpp =================================================================== --- base/applications/games/solitaire/solitaire.cpp (revision 35201) +++ base/applications/games/solitaire/solitaire.cpp (working copy) @@ -19,7 +19,7 @@ TCHAR MsgQuit[128]; TCHAR MsgAbout[128]; TCHAR MsgWin[128]; -DWORD dwOptions = 8; +DWORD dwOptions = OPTION_THREE_CARDS; CardWindow SolWnd; @@ -32,6 +32,7 @@ BOOL bSelected; } CARDBACK, *PCARDBACK; +VOID ApplyOptions(IN DWORD dwOldOptions, IN DWORD dwNewOptions, IN BOOL fIgnoreOldOptions); LRESULT CALLBACK WndProc (HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam); void MakePath(TCHAR *szDest, UINT nDestLen, const TCHAR *szExt) @@ -181,6 +182,8 @@ ShowWindow(hwnd, iCmdShow); UpdateWindow(hwnd); + ApplyOptions(0, dwOptions, TRUE); + hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDR_ACCELERATOR1)); while(GetMessage(&msg, NULL,0,0)) @@ -198,6 +201,52 @@ } +VOID ApplyOptions(IN DWORD dwOldOptions, IN DWORD dwNewOptions, IN BOOL fIgnoreOldOptions) +{ + LONG dwMainWidth; + LONG dwMainHeight; + LONG dwStatusHeight; + RECT rcMainWindow; + RECT rcStatusWindow; + + // Reflect a possible three cards option change + if (fIgnoreOldOptions || ((dwOldOptions ^ dwNewOptions) & OPTION_THREE_CARDS)) + NewGame(); + + // Reflect a possible statusbar visibility option change + if (fIgnoreOldOptions || ((dwOldOptions ^ dwNewOptions) & OPTION_SHOW_STATUS)) + { + // Calculate the dimensions of the main window + GetClientRect(hwndMain, &rcMainWindow); + dwMainWidth = rcMainWindow.right - rcMainWindow.left; + dwMainHeight = rcMainWindow.bottom - rcMainWindow.top; + + if (dwNewOptions & OPTION_SHOW_STATUS) + { + // Show the status bar and calculate its height + ShowWindow(hwndStatus, SW_SHOW); + GetWindowRect(hwndStatus, &rcStatusWindow); + dwStatusHeight = rcStatusWindow.bottom - rcStatusWindow.top; + + // Move the solitaire window and the status bar to their places + MoveWindow(SolWnd, 0, 0, dwMainWidth, dwMainHeight - dwStatusHeight, TRUE); + MoveWindow(hwndStatus, 0, dwMainHeight - dwStatusHeight, dwMainWidth, dwStatusHeight, TRUE); + + // Force the main window to process WM_GETMINMAXINFO again + GetWindowRect(hwndMain, &rcMainWindow); + SetWindowPos(hwndMain, NULL, 0, 0, rcMainWindow.right - rcMainWindow.left, + rcMainWindow.bottom - rcMainWindow.top, SWP_NOMOVE | SWP_NOZORDER); + + } + else + { + // Hide the statusbar and move the solitaire window to its place + ShowWindow(hwndStatus, SW_HIDE); + MoveWindow(SolWnd, 0, 0, dwMainWidth, dwMainHeight, TRUE); + } + } +} + BOOL CALLBACK OptionsDlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) { switch (uMsg) @@ -239,41 +288,9 @@ VOID ShowGameOptionsDlg(HWND hwnd) { DWORD dwOldOptions = dwOptions; - RECT rcMain, rcStatus; - int nWidth, nHeight, nStatusHeight; if (DialogBox(hInstance, MAKEINTRESOURCE(IDD_OPTIONS), hwnd, OptionsDlgProc)) - { - if ((dwOldOptions & OPTION_THREE_CARDS) != (dwOptions & OPTION_THREE_CARDS)) - NewGame(); - - if ((dwOldOptions & OPTION_SHOW_STATUS) != (dwOptions & OPTION_SHOW_STATUS)) - { - GetClientRect(hwndMain, &rcMain); - nHeight = rcMain.bottom - rcMain.top; - nWidth = rcMain.right - rcMain.left; - - if (dwOptions & OPTION_SHOW_STATUS) - { - RECT rc; - - ShowWindow(hwndStatus, SW_SHOW); - GetWindowRect(hwndStatus, &rcStatus); - nStatusHeight = rcStatus.bottom - rcStatus.top; - MoveWindow(SolWnd, 0, 0, nWidth, nHeight-nStatusHeight, TRUE); - MoveWindow(hwndStatus, 0, nHeight-nStatusHeight, nWidth, nHeight, TRUE); - - // Force the window to process WM_GETMINMAXINFO again - GetWindowRect(hwndMain, &rc); - SetWindowPos(hwndMain, NULL, 0, 0, rc.right - rc.left, rc.bottom - rc.top, SWP_NOMOVE | SWP_NOZORDER); - } - else - { - ShowWindow(hwndStatus, SW_HIDE); - MoveWindow(SolWnd, 0, 0, nWidth, nHeight, TRUE); - } - } - } + ApplyOptions(dwOldOptions, dwOptions, FALSE); } @@ -477,8 +494,6 @@ nStatusHeight = rcStatus.bottom - rcStatus.top; SetWindowPos(hwnd, NULL, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOZORDER); - NewGame(); - dwAppStartTime = GetTickCount(); return 0; @@ -495,8 +510,7 @@ if (dwOptions & OPTION_SHOW_STATUS) { MoveWindow(SolWnd, 0, 0, nWidth, nHeight - nStatusHeight, TRUE); - MoveWindow(hwndStatus, 0, nHeight - nStatusHeight, nWidth, nHeight, TRUE); - SendMessage(hwndStatus, WM_SIZE, wParam, lParam); + MoveWindow(hwndStatus, 0, nHeight - nStatusHeight, nWidth, nStatusHeight, TRUE); } else {