Added DestroyBoard function to delete bitmap handles.

Moved SelectObject outside of DrawMine.
Selected old object's back into hMemDC.
This commit is contained in:
Joshua Thielen 2000-04-04 18:55:55 +00:00 committed by Alexandre Julliard
parent 21c04b9d9a
commit 0872f30af7
2 changed files with 28 additions and 7 deletions

View File

@ -111,6 +111,7 @@ LRESULT WINAPI MainProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
case WM_DESTROY: case WM_DESTROY:
SaveBoard( &board ); SaveBoard( &board );
DestroyBoard( &board );
PostQuitMessage( 0 ); PostQuitMessage( 0 );
return 0; return 0;
@ -418,6 +419,13 @@ void SaveBoard( BOARD *p_board )
RegCloseKey( hkey ); RegCloseKey( hkey );
} }
void DestroyBoard( BOARD *p_board )
{
DeleteObject( p_board->hFacesBMP );
DeleteObject( p_board->hLedsBMP );
DeleteObject( p_board->hMinesBMP );
}
void SetDifficulty( BOARD *p_board, DIFFICULTY difficulty ) void SetDifficulty( BOARD *p_board, DIFFICULTY difficulty )
{ {
HMENU hMenu = GetMenu( p_board->hWnd ); HMENU hMenu = GetMenu( p_board->hWnd );
@ -588,14 +596,16 @@ void CreateBoxes( BOARD *p_board )
void DrawMines ( HDC hdc, HDC hMemDC, BOARD *p_board ) void DrawMines ( HDC hdc, HDC hMemDC, BOARD *p_board )
{ {
HGDIOBJ hOldObj;
unsigned col, row; unsigned col, row;
hOldObj = SelectObject (hMemDC, p_board->hMinesBMP);
for( row = 1; row <= p_board->rows; row++ ) { for( row = 1; row <= p_board->rows; row++ ) {
for( col = 1; col <= p_board->cols; col++ ) { for( col = 1; col <= p_board->cols; col++ ) {
DrawMine( hdc, hMemDC, p_board, col, row, FALSE ); DrawMine( hdc, hMemDC, p_board, col, row, FALSE );
} }
} }
SelectObject( hMemDC, hOldObj );
} }
void DrawMine( HDC hdc, HDC hMemDC, BOARD *p_board, unsigned col, unsigned row, BOOL IsPressed ) void DrawMine( HDC hdc, HDC hMemDC, BOARD *p_board, unsigned col, unsigned row, BOOL IsPressed )
@ -666,19 +676,16 @@ void DrawMine( HDC hdc, HDC hMemDC, BOARD *p_board, unsigned col, unsigned row,
&& !p_board->box[col][row].IsMine ) && !p_board->box[col][row].IsMine )
offset = (MINEBMP_OFFSET) p_board->box[col][row].NumMines; offset = (MINEBMP_OFFSET) p_board->box[col][row].NumMines;
SelectObject (hMemDC, p_board->hMinesBMP);
BitBlt( hdc, BitBlt( hdc,
(col - 1) * MINE_WIDTH + p_board->mines_rect.left, (col - 1) * MINE_WIDTH + p_board->mines_rect.left,
(row - 1) * MINE_HEIGHT + p_board->mines_rect.top, (row - 1) * MINE_HEIGHT + p_board->mines_rect.top,
MINE_WIDTH, MINE_HEIGHT, MINE_WIDTH, MINE_HEIGHT,
hMemDC, 0, offset * MINE_HEIGHT, SRCCOPY ); hMemDC, 0, offset * MINE_HEIGHT, SRCCOPY );
} }
void DrawLeds( HDC hdc, HDC hMemDC, BOARD *p_board, int number, int x, int y ) void DrawLeds( HDC hdc, HDC hMemDC, BOARD *p_board, int number, int x, int y )
{ {
HGDIOBJ hOldObj;
unsigned led[3], i; unsigned led[3], i;
int count; int count;
@ -706,7 +713,7 @@ void DrawLeds( HDC hdc, HDC hMemDC, BOARD *p_board, int number, int x, int y )
for( i = 0; i < 3; i++ ) for( i = 0; i < 3; i++ )
led[i] = 11; led[i] = 11;
SelectObject (hMemDC, p_board->hLedsBMP); hOldObj = SelectObject (hMemDC, p_board->hLedsBMP);
for( i = 0; i < 3; i++ ) { for( i = 0; i < 3; i++ ) {
BitBlt( hdc, BitBlt( hdc,
@ -719,12 +726,16 @@ void DrawLeds( HDC hdc, HDC hMemDC, BOARD *p_board, int number, int x, int y )
led[i] * LED_HEIGHT, led[i] * LED_HEIGHT,
SRCCOPY); SRCCOPY);
} }
SelectObject( hMemDC, hOldObj );
} }
void DrawFace( HDC hdc, HDC hMemDC, BOARD *p_board ) void DrawFace( HDC hdc, HDC hMemDC, BOARD *p_board )
{ {
SelectObject (hMemDC, p_board->hFacesBMP); HGDIOBJ hOldObj;
hOldObj = SelectObject (hMemDC, p_board->hFacesBMP);
BitBlt( hdc, BitBlt( hdc,
p_board->face_rect.left, p_board->face_rect.left,
@ -732,6 +743,8 @@ void DrawFace( HDC hdc, HDC hMemDC, BOARD *p_board )
FACE_WIDTH, FACE_WIDTH,
FACE_HEIGHT, FACE_HEIGHT,
hMemDC, 0, p_board->face_bmp * FACE_HEIGHT, SRCCOPY); hMemDC, 0, p_board->face_bmp * FACE_HEIGHT, SRCCOPY);
SelectObject( hMemDC, hOldObj );
} }
@ -956,13 +969,16 @@ void AddFlag( BOARD *p_board, unsigned col, unsigned row )
void PressBox( BOARD *p_board, unsigned col, unsigned row ) void PressBox( BOARD *p_board, unsigned col, unsigned row )
{ {
HDC hdc; HDC hdc;
HGDIOBJ hOldObj;
HDC hMemDC; HDC hMemDC;
hdc = GetDC( p_board->hWnd ); hdc = GetDC( p_board->hWnd );
hMemDC = CreateCompatibleDC( hdc ); hMemDC = CreateCompatibleDC( hdc );
hOldObj = SelectObject (hMemDC, p_board->hMinesBMP);
DrawMine( hdc, hMemDC, p_board, col, row, TRUE ); DrawMine( hdc, hMemDC, p_board, col, row, TRUE );
SelectObject( hMemDC, hOldObj );
DeleteDC( hMemDC ); DeleteDC( hMemDC );
ReleaseDC( p_board->hWnd, hdc ); ReleaseDC( p_board->hWnd, hdc );
} }
@ -998,13 +1014,16 @@ void PressBoxes( BOARD *p_board, unsigned col, unsigned row )
void UnpressBox( BOARD *p_board, unsigned col, unsigned row ) void UnpressBox( BOARD *p_board, unsigned col, unsigned row )
{ {
HDC hdc; HDC hdc;
HGDIOBJ hOldObj;
HDC hMemDC; HDC hMemDC;
hdc = GetDC( p_board->hWnd ); hdc = GetDC( p_board->hWnd );
hMemDC = CreateCompatibleDC( hdc ); hMemDC = CreateCompatibleDC( hdc );
hOldObj = SelectObject( hMemDC, p_board->hMinesBMP );
DrawMine( hdc, hMemDC, p_board, col, row, FALSE ); DrawMine( hdc, hMemDC, p_board, col, row, FALSE );
SelectObject( hMemDC, hOldObj );
DeleteDC( hMemDC ); DeleteDC( hMemDC );
ReleaseDC( p_board->hWnd, hdc ); ReleaseDC( p_board->hWnd, hdc );
} }

View File

@ -108,6 +108,8 @@ void LoadBoard( BOARD *p_board );
void SaveBoard( BOARD *p_board ); void SaveBoard( BOARD *p_board );
void DestroyBoard( BOARD *p_board );
void SetDifficulty( BOARD *p_board, DIFFICULTY difficulty ); void SetDifficulty( BOARD *p_board, DIFFICULTY difficulty );
void CheckLevel( BOARD *p_board ); void CheckLevel( BOARD *p_board );