#include "solitaire.h"
-const int yBorder = 20;
-const int xBorder = 20;
-const int yRowStacks = yBorder + 128;
-
CardRegion *pDeck;
CardRegion *pPile;
CardRegion *pSuitStack[4];
extern CardStack activepile;
HBITMAP hbmBitmap;
-HDC hdcBitmap;
+HDC hdcBitmap;
void CreateSol()
{
activepile.Clear();
- pDeck = SolWnd.CreateRegion(DECK_ID, true, xBorder, yBorder, 2, 1);
+ pDeck = SolWnd.CreateRegion(DECK_ID, true, X_BORDER, Y_BORDER, 2, 1);
pDeck->SetEmptyImage(CS_EI_SUNK);
pDeck->SetThreedCount(6);
pDeck->SetDragRule(CS_DRAG_NONE, 0);
pDeck->SetDblClickProc(DeckClickProc);
pDeck->SetFaceDirection(CS_FACE_DOWN, 0);
- pPile = SolWnd.CreateRegion(PILE_ID, true, 110, yBorder, CS_DEFXOFF, 1);
+ pPile = SolWnd.CreateRegion(PILE_ID, true, X_BORDER + __cardwidth + X_PILE_BORDER, Y_BORDER, CS_DEFXOFF, 1);
pPile->SetEmptyImage(CS_EI_NONE);
pPile->SetDragRule(CS_DRAG_TOP, 0);
pPile->SetDropRule(CS_DROP_NONE, 0);
//
for(i = 0; i < 4; i++)
{
- pSuitStack[i] = SolWnd.CreateRegion(SUIT_ID+i, true, 0, yBorder, 0, 0);
+ pSuitStack[i] = SolWnd.CreateRegion(SUIT_ID+i, true, 0, Y_BORDER, 0, 0);
pSuitStack[i]->SetEmptyImage(CS_EI_SUNK);
- //pSuitStack[i]->SetPlacement(CS_XJUST_RIGHT, 0, -i * (__cardwidth + 4) - xBorder, 0);
- pSuitStack[i]->SetPlacement(CS_XJUST_CENTER, 0, i * (__cardwidth + 10) , 0);
+ pSuitStack[i]->SetPlacement(CS_XJUST_CENTER, 0, i * (__cardwidth + X_SUITSTACK_BORDER) , 0);
pSuitStack[i]->SetDropRule(CS_DROP_CALLBACK, SuitStackDropProc);
pSuitStack[i]->SetDragRule(CS_DRAG_TOP);
//
for(i = 0; i < NUM_ROW_STACKS; i++)
{
- pRowStack[i] = SolWnd.CreateRegion(ROW_ID+i, true, 0, yRowStacks, 0, 14);
+ pRowStack[i] = SolWnd.CreateRegion(ROW_ID+i, true, 0, Y_BORDER + __cardheight + Y_ROWSTACK_BORDER, 0, Y_ROWSTACK_CARDOFFSET);
pRowStack[i]->SetEmptyImage(CS_EI_SUNK);
pRowStack[i]->SetFaceDirection(CS_FACE_DOWNUP, i);
pRowStack[i]->SetPlacement(CS_XJUST_CENTER, 0,
- (i - NUM_ROW_STACKS/2) * (__cardwidth + 10), 0);
+ (i - NUM_ROW_STACKS/2) * (__cardwidth + X_ROWSTACK_BORDER), 0);
pRowStack[i]->SetEmptyImage(CS_EI_NONE);
,//|WS_CLIPCHILDREN, // window style
CW_USEDEFAULT, // initial x position
CW_USEDEFAULT, // initial y position
- 600, // initial x size
- 450, // initial y size
+ 0, // The real size will be computed in WndProc through WM_GETMINMAXINFO
+ 0, // The real size will be computed in WndProc through WM_GETMINMAXINFO
NULL, // parent window handle
NULL, // use window class menu
hInst, // program instance handle
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
{
//-----------------------------------------------------------------------------
LRESULT CALLBACK WndProc (HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam)
{
- static int nWidth, nHeight;
- int parts[] = { 100, -1 };
- int ret;
- RECT rc;
- int nStatusHeight = 0;
-
- MINMAXINFO *mmi;
+ static int nWidth, nHeight, nStatusHeight;
switch(iMsg)
{
- case WM_CREATE:
- hwndStatus = CreateStatusWindow(WS_CHILD | WS_VISIBLE | CCS_BOTTOM | SBARS_SIZEGRIP, _T("Ready"), hwnd, 0);
-
- //SendMessage(hwndStatus, SB_SIMPLE, (WPARAM)TRUE, 0);
-
- SendMessage(hwndStatus, SB_SETPARTS, 2, (LPARAM)parts);
- SendMessage(hwndStatus, SB_SETTEXT, 0 | SBT_NOBORDERS, (LPARAM)"");
-
- SolWnd.Create(hwnd, WS_EX_CLIENTEDGE, WS_CHILD|WS_VISIBLE, 0, 0, 0, 0);
-
- CreateSol();
-
- NewGame();
+ case WM_CREATE:
+ {
+ int parts[] = { 100, -1 };
+ RECT rcStatus;
- dwAppStartTime = GetTickCount();
+ hwndStatus = CreateStatusWindow(WS_CHILD | WS_VISIBLE | CCS_BOTTOM | SBARS_SIZEGRIP, _T("Ready"), hwnd, 0);
- return 0;
+ //SendMessage(hwndStatus, SB_SIMPLE, (WPARAM)TRUE, 0);
- case WM_DESTROY:
- PostQuitMessage(0);
- return 0;
+ SendMessage(hwndStatus, SB_SETPARTS, 2, (LPARAM)parts);
+ SendMessage(hwndStatus, SB_SETTEXT, 0 | SBT_NOBORDERS, (LPARAM)"");
- case WM_SIZE:
- nWidth = LOWORD(lParam);
- nHeight = HIWORD(lParam);
+ // The status bar height is fixed and needed later in WM_SIZE and WM_GETMINMAXINFO
+ // Force the window to process WM_GETMINMAXINFO again
+ GetWindowRect(hwndStatus, &rcStatus);
+ nStatusHeight = rcStatus.bottom - rcStatus.top;
+ SetWindowPos(hwnd, NULL, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOZORDER);
- if (dwOptions & OPTION_SHOW_STATUS)
- {
- GetWindowRect(hwndStatus, &rc);
- nStatusHeight = rc.bottom - rc.top;
- MoveWindow(SolWnd, 0, 0, nWidth, nHeight-nStatusHeight, TRUE);
- MoveWindow(hwndStatus, 0, nHeight-nStatusHeight, nWidth, nHeight, TRUE);
- }
- else
- {
- MoveWindow(SolWnd, 0, 0, nWidth, nHeight, TRUE);
- }
- //parts[0] = nWidth - 256;
- //SendMessage(hwndStatus, SB_SETPARTS, 2, (LPARAM)parts);
- return 0;
+ SolWnd.Create(hwnd, WS_EX_CLIENTEDGE, WS_CHILD|WS_VISIBLE, 0, 0, 0, 0);
- case WM_GETMINMAXINFO:
- mmi = (MINMAXINFO *)lParam;
- mmi->ptMinTrackSize.x = 600;
- mmi->ptMinTrackSize.y = 400;
- return 0;
+ CreateSol();
- case WM_COMMAND:
- switch(LOWORD(wParam))
- {
- case IDM_GAME_NEW:
- //simulate a button click on the new button..
NewGame();
- return 0;
- case IDM_GAME_DECK:
- ShowDeckOptionsDlg(hwnd);
- return 0;
+ dwAppStartTime = GetTickCount();
- case IDM_GAME_OPTIONS:
- ShowGameOptionsDlg(hwnd);
return 0;
+ }
- case IDM_HELP_CONTENTS:
- WinHelp(hwnd, szHelpPath, HELP_CONTENTS, 0);//HELP_KEY, (DWORD)"How to play");
+ case WM_DESTROY:
+ PostQuitMessage(0);
return 0;
- case IDM_HELP_ABOUT:
- MessageBox(hwnd, MsgAbout, szAppName, MB_OK|MB_ICONINFORMATION);
+ case WM_SIZE:
+ nWidth = LOWORD(lParam);
+ nHeight = HIWORD(lParam);
+
+ if (dwOptions & OPTION_SHOW_STATUS)
+ {
+ MoveWindow(SolWnd, 0, 0, nWidth, nHeight - nStatusHeight, TRUE);
+ MoveWindow(hwndStatus, 0, nHeight - nStatusHeight, nWidth, nHeight, TRUE);
+ }
+ else
+ {
+ MoveWindow(SolWnd, 0, 0, nWidth, nHeight, TRUE);
+ }
+ //parts[0] = nWidth - 256;
+ //SendMessage(hwndStatus, SB_SETPARTS, 2, (LPARAM)parts);
return 0;
- case IDM_GAME_EXIT:
- PostMessage(hwnd, WM_CLOSE, 0, 0);
+ case WM_GETMINMAXINFO:
+ {
+ MINMAXINFO *mmi;
+
+ mmi = (MINMAXINFO *)lParam;
+ mmi->ptMinTrackSize.x = X_BORDER + NUM_ROW_STACKS * (__cardwidth + X_ROWSTACK_BORDER) + X_BORDER;
+ mmi->ptMinTrackSize.y = GetSystemMetrics(SM_CYCAPTION) +
+ GetSystemMetrics(SM_CYMENU) +
+ Y_BORDER +
+ __cardheight +
+ Y_ROWSTACK_BORDER +
+ 6 * Y_ROWSTACK_CARDOFFSET +
+ __cardheight +
+ Y_BORDER +
+ (dwOptions & OPTION_SHOW_STATUS ? nStatusHeight : 0);
return 0;
}
- return 0;
+ case WM_COMMAND:
+ switch(LOWORD(wParam))
+ {
+ case IDM_GAME_NEW:
+ //simulate a button click on the new button..
+ NewGame();
+ return 0;
+
+ case IDM_GAME_DECK:
+ ShowDeckOptionsDlg(hwnd);
+ return 0;
+
+ case IDM_GAME_OPTIONS:
+ ShowGameOptionsDlg(hwnd);
+ return 0;
+
+ case IDM_HELP_CONTENTS:
+ WinHelp(hwnd, szHelpPath, HELP_CONTENTS, 0);//HELP_KEY, (DWORD)"How to play");
+ return 0;
+
+ case IDM_HELP_ABOUT:
+ MessageBox(hwnd, MsgAbout, szAppName, MB_OK|MB_ICONINFORMATION);
+ return 0;
+
+ case IDM_GAME_EXIT:
+ PostMessage(hwnd, WM_CLOSE, 0, 0);
+ return 0;
+ }
- case WM_CLOSE:
- if (fGameStarted == false)
- {
- DestroyWindow(hwnd);
return 0;
- }
- else
- {
- ret = MessageBox(hwnd, MsgQuit, szAppName, MB_OKCANCEL|MB_ICONQUESTION);
- if (ret == IDOK)
+
+ case WM_CLOSE:
+ if (fGameStarted == false)
{
- WinHelp(hwnd, szHelpPath, HELP_QUIT, 0);
DestroyWindow(hwnd);
+ return 0;
}
- }
- return 0;
+ else
+ {
+ int ret;
+
+ ret = MessageBox(hwnd, MsgQuit, szAppName, MB_OKCANCEL|MB_ICONQUESTION);
+ if (ret == IDOK)
+ {
+ WinHelp(hwnd, szHelpPath, HELP_QUIT, 0);
+ DestroyWindow(hwnd);
+ }
+ }
+ return 0;
}
return DefWindowProc (hwnd, iMsg, wParam, lParam);