ReactOS  0.4.11-dev-946-g431643b
main.c File Reference
#include "main.h"
#include <winbase.h>
#include <winreg.h>
#include <wingdi.h>
#include <time.h>
#include <stdlib.h>
#include <shellapi.h>
#include <wine/debug.h>
Include dependency graph for main.c:

Go to the source code of this file.

Functions

 WINE_DEFAULT_DEBUG_CHANNEL (winemine)
 
void CheckLevel (BOARD *p_board)
 
static void LoadBoard (BOARD *p_board)
 
static void InitBoard (BOARD *p_board)
 
static void SaveBoard (BOARD *p_board)
 
static void DestroyBoard (BOARD *p_board)
 
static void SetDifficulty (BOARD *p_board, DIFFICULTY difficulty)
 
static void ShiftBetween (LONG *x, LONG *y, LONG a, LONG b)
 
static void MoveOnScreen (RECT *rect)
 
static void CreateBoard (BOARD *p_board)
 
static void PlaceMines (BOARD *p_board, int selected_col, int selected_row)
 
static void DrawMine (HDC hdc, HDC hMemDC, BOARD *p_board, unsigned col, unsigned row, BOOL IsPressed)
 
static void DrawMines (HDC hdc, HDC hMemDC, BOARD *p_board)
 
static void DrawLeds (HDC hdc, HDC hMemDC, BOARD *p_board, int number, int x, int y)
 
static void DrawFace (HDC hdc, HDC hMemDC, BOARD *p_board)
 
static void DrawBoard (HDC hdc, HDC hMemDC, PAINTSTRUCT *ps, BOARD *p_board)
 
static void AddFlag (BOARD *p_board, unsigned col, unsigned row)
 
static void UnpressBox (BOARD *p_board, unsigned col, unsigned row)
 
static void UnpressBoxes (BOARD *p_board, unsigned col, unsigned row)
 
static void PressBox (BOARD *p_board, unsigned col, unsigned row)
 
static void PressBoxes (BOARD *p_board, unsigned col, unsigned row)
 
static void CompleteBox (BOARD *p_board, unsigned col, unsigned row)
 
static void CompleteBoxes (BOARD *p_board, unsigned col, unsigned row)
 
static void TestMines (BOARD *p_board, POINT pt, int msg)
 
static void TestFace (BOARD *p_board, POINT pt, int msg)
 
static void TestBoard (HWND hWnd, BOARD *p_board, int x, int y, int msg)
 
static LRESULT WINAPI MainProc (HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
 
int WINAPI wWinMain (HINSTANCE hInst, HINSTANCE hPrevInst, LPWSTR cmdline, int cmdshow)
 

Variables

static const DWORD wnd_style = WS_OVERLAPPEDWINDOW & ~WS_THICKFRAME & ~WS_MAXIMIZEBOX
 
static const WCHAR registry_key []
 
static const WCHAR xposW [] = {'X','p','o','s',0}
 
static const WCHAR yposW [] = {'Y','p','o','s',0}
 
static const WCHAR heightW [] = {'H','e','i','g','h','t',0}
 
static const WCHAR widthW [] = {'W','i','d','t','h',0}
 
static const WCHAR minesW [] = {'M','i','n','e','s',0}
 
static const WCHAR difficultyW [] = {'D','i','f','f','i','c','u','l','t','y',0}
 
static const WCHAR markW [] = {'M','a','r','k',0}
 
static const WCHAR nameW [] = {'N','a','m','e','%','u',0}
 
static const WCHAR timeW [] = {'T','i','m','e','%','u',0}
 

Function Documentation

◆ AddFlag()

static void AddFlag ( BOARD p_board,
unsigned  col,
unsigned  row 
)
static

Definition at line 545 of file main.c.

Referenced by TestMines().

546 {
547  if( p_board->box[col][row].FlagType != COMPLETE ) {
548  switch( p_board->box[col][row].FlagType ) {
549  case FLAG:
550  if( p_board->IsMarkQ )
551  p_board->box[col][row].FlagType = QUESTION;
552  else
553  p_board->box[col][row].FlagType = NORMAL;
554  p_board->num_flags--;
555  break;
556 
557  case QUESTION:
558  p_board->box[col][row].FlagType = NORMAL;
559  break;
560 
561  default:
562  p_board->box[col][row].FlagType = FLAG;
563  p_board->num_flags++;
564  }
565  }
566 }
#define COMPLETE
Definition: main.h:128
BOOL IsMarkQ
Definition: main.h:73
Definition: cdmake.c:189
unsigned num_flags
Definition: main.h:90
#define QUESTION
Definition: main.h:126
Definition: inflate.c:14
struct png_info_def *typedef unsigned char **typedef struct png_info_def *typedef struct png_info_def *typedef struct png_info_def *typedef unsigned char ** row
Definition: typeof.h:76

◆ CheckLevel()

void CheckLevel ( BOARD p_board)

Definition at line 49 of file main.c.

Referenced by CustomDlgProc(), and InitBoard().

50 {
51  if( p_board->rows < BEGINNER_ROWS )
52  p_board->rows = BEGINNER_ROWS;
53 
54  if( p_board->rows > MAX_ROWS )
55  p_board->rows = MAX_ROWS;
56 
57  if( p_board->cols < BEGINNER_COLS )
58  p_board->cols = BEGINNER_COLS;
59 
60  if( p_board->cols > MAX_COLS )
61  p_board->cols = MAX_COLS;
62 
63  if( p_board->mines < BEGINNER_MINES )
64  p_board->mines = BEGINNER_MINES;
65 
66  if( p_board->mines > ( p_board->cols - 1 ) * ( p_board->rows - 1 ) )
67  p_board->mines = ( p_board->cols - 1 ) * ( p_board->rows - 1 );
68 }
#define BEGINNER_MINES
Definition: main.h:30
#define MAX_COLS
Definition: main.h:42
#define BEGINNER_COLS
Definition: main.h:31
unsigned mines
Definition: main.h:97
unsigned rows
Definition: main.h:95
unsigned cols
Definition: main.h:96
#define BEGINNER_ROWS
Definition: main.h:32
#define MAX_ROWS
Definition: map.c:17

◆ CompleteBox()

static void CompleteBox ( BOARD p_board,
unsigned  col,
unsigned  row 
)
static

Definition at line 643 of file main.c.

Referenced by CompleteBoxes(), and TestMines().

644 {
645  int i, j;
646 
647  if( p_board->box[col][row].FlagType != COMPLETE &&
648  p_board->box[col][row].FlagType != FLAG &&
649  col > 0 && col < p_board->cols + 1 &&
650  row > 0 && row < p_board->rows + 1 ) {
651  p_board->box[col][row].FlagType = COMPLETE;
652 
653  if( p_board->box[col][row].IsMine ) {
654  p_board->face_bmp = DEAD_BMP;
655  p_board->status = GAMEOVER;
656  }
657  else if( p_board->status != GAMEOVER )
658  p_board->boxes_left--;
659 
660  if( p_board->box[col][row].NumMines == 0 )
661  {
662  for( i = -1; i <= 1; i++ )
663  for( j = -1; j <= 1; j++ )
664  CompleteBox( p_board, col + i, row + j );
665  }
666  }
667 }
GLenum GLclampf GLint GLenum GLuint GLenum GLenum GLsizei GLenum const GLvoid GLfloat GLfloat GLfloat GLfloat GLclampd GLint GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean GLboolean GLboolean GLboolean GLint GLenum GLsizei const GLvoid GLenum GLint GLenum GLint GLint GLsizei GLint GLenum GLint GLint GLint GLint GLsizei GLenum GLsizei const GLuint GLboolean GLenum GLenum GLint GLsizei GLenum GLsizei GLenum const GLvoid GLboolean const GLboolean GLenum const GLdouble const GLfloat const GLdouble const GLfloat GLenum GLint GLint GLint GLint GLint GLint j
Definition: glfuncs.h:98
#define COMPLETE
Definition: main.h:128
FACE_BMP face_bmp
Definition: main.h:114
GLenum GLclampf GLint i
Definition: glfuncs.h:14
GAME_STATUS status
Definition: main.h:115
Definition: main.h:59
unsigned boxes_left
Definition: main.h:91
static void CompleteBox(BOARD *p_board, unsigned col, unsigned row)
Definition: main.c:643
Definition: main.h:61
Definition: inflate.c:14
struct png_info_def *typedef unsigned char **typedef struct png_info_def *typedef struct png_info_def *typedef struct png_info_def *typedef unsigned char ** row
Definition: typeof.h:76

◆ CompleteBoxes()

static void CompleteBoxes ( BOARD p_board,
unsigned  col,
unsigned  row 
)
static

Definition at line 670 of file main.c.

Referenced by TestMines().

671 {
672  unsigned numFlags = 0;
673  int i, j;
674 
675  if( p_board->box[col][row].FlagType == COMPLETE ) {
676  for( i = -1; i <= 1; i++ )
677  for( j = -1; j <= 1; j++ ) {
678  if( p_board->box[col+i][row+j].FlagType == FLAG )
679  numFlags++;
680  }
681 
682  if( numFlags == p_board->box[col][row].NumMines ) {
683  for( i = -1; i <= 1; i++ )
684  for( j = -1; j <= 1; j++ ) {
685  if( p_board->box[col+i][row+j].FlagType != FLAG )
686  CompleteBox( p_board, col+i, row+j );
687  }
688  }
689  }
690 }
GLenum GLclampf GLint GLenum GLuint GLenum GLenum GLsizei GLenum const GLvoid GLfloat GLfloat GLfloat GLfloat GLclampd GLint GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean GLboolean GLboolean GLboolean GLint GLenum GLsizei const GLvoid GLenum GLint GLenum GLint GLint GLsizei GLint GLenum GLint GLint GLint GLint GLsizei GLenum GLsizei const GLuint GLboolean GLenum GLenum GLint GLsizei GLenum GLsizei GLenum const GLvoid GLboolean const GLboolean GLenum const GLdouble const GLfloat const GLdouble const GLfloat GLenum GLint GLint GLint GLint GLint GLint j
Definition: glfuncs.h:98
#define COMPLETE
Definition: main.h:128
GLenum GLclampf GLint i
Definition: glfuncs.h:14
static void CompleteBox(BOARD *p_board, unsigned col, unsigned row)
Definition: main.c:643
Definition: inflate.c:14
struct png_info_def *typedef unsigned char **typedef struct png_info_def *typedef struct png_info_def *typedef struct png_info_def *typedef unsigned char ** row
Definition: typeof.h:76

◆ CreateBoard()

static void CreateBoard ( BOARD p_board)
static

Definition at line 256 of file main.c.

Referenced by MainProc(), and TestFace().

257 {
258  int left, top, bottom, right;
259  unsigned col, row;
260  RECT wnd_rect;
261 
262  p_board->mb = MB_NONE;
263  p_board->boxes_left = p_board->cols * p_board->rows - p_board->mines;
264  p_board->num_flags = 0;
265 
266  /* Create the boxes...
267  * We actually create them with an empty border,
268  * so special care doesn't have to be taken on the edges
269  */
270  for( col = 0; col <= p_board->cols + 1; col++ )
271  for( row = 0; row <= p_board->rows + 1; row++ ) {
272  p_board->box[col][row].IsPressed = FALSE;
273  p_board->box[col][row].IsMine = FALSE;
274  p_board->box[col][row].FlagType = NORMAL;
275  p_board->box[col][row].NumMines = 0;
276  }
277 
278  p_board->width = p_board->cols * MINE_WIDTH + BOARD_WMARGIN * 2;
279 
280  p_board->height = p_board->rows * MINE_HEIGHT + LED_HEIGHT
281  + BOARD_HMARGIN * 3;
282 
283  /* setting the mines rectangle boundary */
284  left = BOARD_WMARGIN;
285  top = BOARD_HMARGIN * 2 + LED_HEIGHT;
286  right = left + p_board->cols * MINE_WIDTH;
287  bottom = top + p_board->rows * MINE_HEIGHT;
288  SetRect( &p_board->mines_rect, left, top, right, bottom );
289 
290  /* setting the face rectangle boundary */
291  left = p_board->width / 2 - FACE_WIDTH / 2;
292  top = BOARD_HMARGIN;
293  right = left + FACE_WIDTH;
294  bottom = top + FACE_HEIGHT;
295  SetRect( &p_board->face_rect, left, top, right, bottom );
296 
297  /* setting the timer rectangle boundary */
298  left = BOARD_WMARGIN;
299  top = BOARD_HMARGIN;
300  right = left + LED_WIDTH * 3;
301  bottom = top + LED_HEIGHT;
302  SetRect( &p_board->timer_rect, left, top, right, bottom );
303 
304  /* setting the counter rectangle boundary */
305  left = p_board->width - BOARD_WMARGIN - LED_WIDTH * 3;
306  top = BOARD_HMARGIN;
307  right = p_board->width - BOARD_WMARGIN;
308  bottom = top + LED_HEIGHT;
309  SetRect( &p_board->counter_rect, left, top, right, bottom );
310 
311  p_board->status = WAITING;
312  p_board->face_bmp = SMILE_BMP;
313  p_board->time = 0;
314 
315  SetRect(&wnd_rect, p_board->pos.x, p_board->pos.y, p_board->pos.x + p_board->width,
316  p_board->pos.y + p_board->height);
317  AdjustWindowRect(&wnd_rect, wnd_style, TRUE);
318 
319  /* Make sure the window is completely on the screen */
320  MoveOnScreen(&wnd_rect);
321  MoveWindow( p_board->hWnd, wnd_rect.left, wnd_rect.top,
322  wnd_rect.right - wnd_rect.left,
323  wnd_rect.bottom - wnd_rect.top,
324  TRUE );
325  RedrawWindow( p_board->hWnd, NULL, 0,
327 }
#define FACE_HEIGHT
Definition: main.h:55
BOOL WINAPI RedrawWindow(_In_opt_ HWND, _In_opt_ LPCRECT, _In_opt_ HRGN, _In_ UINT)
#define TRUE
Definition: types.h:120
Definition: main.h:61
long y
Definition: polytest.cpp:48
#define LED_HEIGHT
Definition: main.h:53
long x
Definition: polytest.cpp:48
#define LED_WIDTH
Definition: main.h:52
LONG top
Definition: windef.h:297
POINT pos
Definition: main.h:87
unsigned mines
Definition: main.h:97
Definition: cdmake.c:189
LONG left
Definition: windef.h:296
unsigned time
Definition: main.h:89
LONG right
Definition: windef.h:298
RECT counter_rect
Definition: main.h:83
#define FACE_WIDTH
Definition: main.h:54
FACE_BMP face_bmp
Definition: main.h:114
BOOL WINAPI AdjustWindowRect(_Inout_ LPRECT, _In_ DWORD, _In_ BOOL)
unsigned mb
Definition: main.h:112
#define BOARD_WMARGIN
Definition: main.h:46
GAME_STATUS status
Definition: main.h:115
RECT timer_rect
Definition: main.h:82
smooth NULL
Definition: ftsmooth.c:416
GLint GLint bottom
Definition: glext.h:7726
static const DWORD wnd_style
Definition: main.c:34
#define MINE_WIDTH
Definition: main.h:50
#define RDW_ERASE
Definition: winuser.h:1197
#define MB_NONE
Definition: main.h:105
GLint left
Definition: glext.h:7726
unsigned rows
Definition: main.h:95
#define MINE_HEIGHT
Definition: main.h:51
GLdouble GLdouble right
Definition: glext.h:10859
RECT mines_rect
Definition: main.h:80
RECT face_rect
Definition: main.h:81
unsigned cols
Definition: main.h:96
unsigned boxes_left
Definition: main.h:91
BOOL WINAPI MoveWindow(_In_ HWND, _In_ int, _In_ int, _In_ int, _In_ int, _In_ BOOL)
BOOL WINAPI SetRect(_Out_ LPRECT, _In_ int, _In_ int, _In_ int, _In_ int)
unsigned num_flags
Definition: main.h:90
#define BOARD_HMARGIN
Definition: main.h:47
#define RDW_UPDATENOW
Definition: winuser.h:1206
static void MoveOnScreen(RECT *rect)
Definition: main.c:240
LONG bottom
Definition: windef.h:299
unsigned width
Definition: main.h:85
unsigned height
Definition: main.h:86
GLdouble GLdouble GLdouble GLdouble top
Definition: glext.h:10859
#define RDW_INVALIDATE
Definition: winuser.h:1200
Definition: main.h:59
struct png_info_def *typedef unsigned char **typedef struct png_info_def *typedef struct png_info_def *typedef struct png_info_def *typedef unsigned char ** row
Definition: typeof.h:76
HWND hWnd
Definition: main.h:76

◆ DestroyBoard()

static void DestroyBoard ( BOARD p_board)
static

Definition at line 182 of file main.c.

Referenced by MainProc().

183 {
184  DeleteObject( p_board->hFacesBMP );
185  DeleteObject( p_board->hLedsBMP );
186  DeleteObject( p_board->hMinesBMP );
187 }
BOOL WINAPI DeleteObject(_In_ HGDIOBJ)
HBITMAP hMinesBMP
Definition: main.h:77
HBITMAP hFacesBMP
Definition: main.h:78
HBITMAP hLedsBMP
Definition: main.h:79

◆ DrawBoard()

static void DrawBoard ( HDC  hdc,
HDC  hMemDC,
PAINTSTRUCT ps,
BOARD p_board 
)
static

Definition at line 523 of file main.c.

Referenced by MainProc().

524 {
525  RECT tmp_rect;
526 
527  if( IntersectRect( &tmp_rect, &ps->rcPaint, &p_board->counter_rect ) )
528  DrawLeds( hdc, hMemDC, p_board, p_board->mines - p_board->num_flags,
529  p_board->counter_rect.left,
530  p_board->counter_rect.top );
531 
532  if( IntersectRect( &tmp_rect, &ps->rcPaint, &p_board->timer_rect ) )
533  DrawLeds( hdc, hMemDC, p_board, p_board->time,
534  p_board->timer_rect.left,
535  p_board->timer_rect.top );
536 
537  if( IntersectRect( &tmp_rect, &ps->rcPaint, &p_board->face_rect ) )
538  DrawFace( hdc, hMemDC, p_board );
539 
540  if( IntersectRect( &tmp_rect, &ps->rcPaint, &p_board->mines_rect ) )
541  DrawMines( hdc, hMemDC, p_board );
542 }
static void DrawMines(HDC hdc, HDC hMemDC, BOARD *p_board)
Definition: main.c:449
LONG top
Definition: windef.h:297
unsigned mines
Definition: main.h:97
LONG left
Definition: windef.h:296
unsigned time
Definition: main.h:89
RECT counter_rect
Definition: main.h:83
RECT timer_rect
Definition: main.h:82
HDC hdc
Definition: msvc.h:53
static void DrawFace(HDC hdc, HDC hMemDC, BOARD *p_board)
Definition: main.c:506
RECT mines_rect
Definition: main.h:80
RECT face_rect
Definition: main.h:81
BOOL WINAPI IntersectRect(_Out_ LPRECT, _In_ LPCRECT, _In_ LPCRECT)
unsigned num_flags
Definition: main.h:90
static void DrawLeds(HDC hdc, HDC hMemDC, BOARD *p_board, int number, int x, int y)
Definition: main.c:463

◆ DrawFace()

static void DrawFace ( HDC  hdc,
HDC  hMemDC,
BOARD p_board 
)
static

Definition at line 506 of file main.c.

Referenced by DrawBoard().

507 {
508  HGDIOBJ hOldObj;
509 
510  hOldObj = SelectObject (hMemDC, p_board->hFacesBMP);
511 
512  BitBlt( hdc,
513  p_board->face_rect.left,
514  p_board->face_rect.top,
515  FACE_WIDTH,
516  FACE_HEIGHT,
517  hMemDC, 0, p_board->face_bmp * FACE_HEIGHT, SRCCOPY);
518 
519  SelectObject( hMemDC, hOldObj );
520 }
#define FACE_HEIGHT
Definition: main.h:55
LONG top
Definition: windef.h:297
HGDIOBJ WINAPI SelectObject(_In_ HDC, _In_ HGDIOBJ)
Definition: dc.c:1497
LONG left
Definition: windef.h:296
static VOID NTAPI BitBlt(IN ULONG Left, IN ULONG Top, IN ULONG Width, IN ULONG Height, IN PUCHAR Buffer, IN ULONG BitsPerPixel, IN ULONG Delta)
Definition: vga.c:416
#define FACE_WIDTH
Definition: main.h:54
FACE_BMP face_bmp
Definition: main.h:114
HDC hdc
Definition: msvc.h:53
RECT face_rect
Definition: main.h:81
HBITMAP hFacesBMP
Definition: main.h:78
#define SRCCOPY
Definition: wingdi.h:331

◆ DrawLeds()

static void DrawLeds ( HDC  hdc,
HDC  hMemDC,
BOARD p_board,
int  number,
int  x,
int  y 
)
static

Definition at line 463 of file main.c.

Referenced by DrawBoard().

464 {
465  HGDIOBJ hOldObj;
466  unsigned led[3], i;
467  int count;
468 
469  count = number;
470  if( count < 1000 ) {
471  if( count >= 0 ) {
472  led[0] = count / 100 ;
473  count -= led[0] * 100;
474  }
475  else {
476  led[0] = 10; /* negative sign */
477  count = -count;
478  }
479  led[1] = count / 10;
480  count -= led[1] * 10;
481  led[2] = count;
482  }
483  else {
484  for( i = 0; i < 3; i++ )
485  led[i] = 10;
486  }
487 
488  hOldObj = SelectObject (hMemDC, p_board->hLedsBMP);
489 
490  for( i = 0; i < 3; i++ ) {
491  BitBlt( hdc,
492  i * LED_WIDTH + x,
493  y,
494  LED_WIDTH,
495  LED_HEIGHT,
496  hMemDC,
497  0,
498  led[i] * LED_HEIGHT,
499  SRCCOPY);
500  }
501 
502  SelectObject( hMemDC, hOldObj );
503 }
#define LED_HEIGHT
Definition: main.h:53
#define LED_WIDTH
Definition: main.h:52
GLuint GLuint GLsizei count
Definition: gl.h:1545
HGDIOBJ WINAPI SelectObject(_In_ HDC, _In_ HGDIOBJ)
Definition: dc.c:1497
static VOID NTAPI BitBlt(IN ULONG Left, IN ULONG Top, IN ULONG Width, IN ULONG Height, IN PUCHAR Buffer, IN ULONG BitsPerPixel, IN ULONG Delta)
Definition: vga.c:416
INT INT y
Definition: msvc.h:62
GLenum GLclampf GLint i
Definition: glfuncs.h:14
static size_t double number
Definition: printf.c:64
HDC hdc
Definition: msvc.h:53
INT x
Definition: msvc.h:62
HBITMAP hLedsBMP
Definition: main.h:79
#define SRCCOPY
Definition: wingdi.h:331

◆ DrawMine()

static void DrawMine ( HDC  hdc,
HDC  hMemDC,
BOARD p_board,
unsigned  col,
unsigned  row,
BOOL  IsPressed 
)
static

Definition at line 372 of file main.c.

Referenced by DrawMines(), PressBox(), and UnpressBox().

373 {
375 
376  if( col == 0 || col > p_board->cols || row == 0 || row > p_board->rows )
377  return;
378 
379  if( p_board->status == GAMEOVER ) {
380  if( p_board->box[col][row].IsMine ) {
381  switch( p_board->box[col][row].FlagType ) {
382  case FLAG:
383  offset = FLAG_BMP;
384  break;
385  case COMPLETE:
386  offset = EXPLODE_BMP;
387  break;
388  case QUESTION:
389  /* fall through */
390  case NORMAL:
391  offset = MINE_BMP;
392  }
393  } else {
394  switch( p_board->box[col][row].FlagType ) {
395  case QUESTION:
396  offset = QUESTION_BMP;
397  break;
398  case FLAG:
399  offset = WRONG_BMP;
400  break;
401  case NORMAL:
402  offset = BOX_BMP;
403  break;
404  case COMPLETE:
405  /* Do nothing */
406  break;
407  default:
408  WINE_TRACE("Unknown FlagType during game over in DrawMine\n");
409  break;
410  }
411  }
412  } else { /* WAITING or PLAYING */
413  switch( p_board->box[col][row].FlagType ) {
414  case QUESTION:
415  if( !IsPressed )
416  offset = QUESTION_BMP;
417  else
418  offset = QPRESS_BMP;
419  break;
420  case FLAG:
421  offset = FLAG_BMP;
422  break;
423  case NORMAL:
424  if( !IsPressed )
425  offset = BOX_BMP;
426  else
427  offset = MPRESS_BMP;
428  break;
429  case COMPLETE:
430  /* Do nothing */
431  break;
432  default:
433  WINE_TRACE("Unknown FlagType while playing in DrawMine\n");
434  break;
435  }
436  }
437 
438  if( p_board->box[col][row].FlagType == COMPLETE
439  && !p_board->box[col][row].IsMine )
440  offset = (MINEBMP_OFFSET) p_board->box[col][row].NumMines;
441 
442  BitBlt( hdc,
443  (col - 1) * MINE_WIDTH + p_board->mines_rect.left,
444  (row - 1) * MINE_HEIGHT + p_board->mines_rect.top,
446  hMemDC, 0, offset * MINE_HEIGHT, SRCCOPY );
447 }
GLintptr offset
Definition: glext.h:5920
LONG top
Definition: windef.h:297
#define WINE_TRACE
Definition: debug.h:358
#define COMPLETE
Definition: main.h:128
Definition: cdmake.c:189
LONG left
Definition: windef.h:296
static VOID NTAPI BitBlt(IN ULONG Left, IN ULONG Top, IN ULONG Width, IN ULONG Height, IN PUCHAR Buffer, IN ULONG BitsPerPixel, IN ULONG Delta)
Definition: vga.c:416
Definition: main.h:66
Definition: main.h:66
GAME_STATUS status
Definition: main.h:115
MINEBMP_OFFSET
Definition: main.h:63
Definition: main.h:65
HDC hdc
Definition: msvc.h:53
#define MINE_WIDTH
Definition: main.h:50
unsigned rows
Definition: main.h:95
#define MINE_HEIGHT
Definition: main.h:51
RECT mines_rect
Definition: main.h:80
unsigned cols
Definition: main.h:96
Definition: main.h:61
#define QUESTION
Definition: main.h:126
Definition: inflate.c:14
#define SRCCOPY
Definition: wingdi.h:331
struct png_info_def *typedef unsigned char **typedef struct png_info_def *typedef struct png_info_def *typedef struct png_info_def *typedef unsigned char ** row
Definition: typeof.h:76
Definition: main.h:65

◆ DrawMines()

static void DrawMines ( HDC  hdc,
HDC  hMemDC,
BOARD p_board 
)
static

Definition at line 449 of file main.c.

Referenced by DrawBoard().

450 {
451  HGDIOBJ hOldObj;
452  unsigned col, row;
453  hOldObj = SelectObject (hMemDC, p_board->hMinesBMP);
454 
455  for( row = 1; row <= p_board->rows; row++ ) {
456  for( col = 1; col <= p_board->cols; col++ ) {
457  DrawMine( hdc, hMemDC, p_board, col, row, FALSE );
458  }
459  }
460  SelectObject( hMemDC, hOldObj );
461 }
static void DrawMine(HDC hdc, HDC hMemDC, BOARD *p_board, unsigned col, unsigned row, BOOL IsPressed)
Definition: main.c:372
HGDIOBJ WINAPI SelectObject(_In_ HDC, _In_ HGDIOBJ)
Definition: dc.c:1497
HDC hdc
Definition: msvc.h:53
unsigned rows
Definition: main.h:95
unsigned cols
Definition: main.h:96
HBITMAP hMinesBMP
Definition: main.h:77
struct png_info_def *typedef unsigned char **typedef struct png_info_def *typedef struct png_info_def *typedef struct png_info_def *typedef unsigned char ** row
Definition: typeof.h:76

◆ InitBoard()

static void InitBoard ( BOARD p_board)
static

Definition at line 128 of file main.c.

Referenced by MainProc().

129 {
130  HMENU hMenu;
131 
132  p_board->hMinesBMP = LoadBitmapW( p_board->hInst, MAKEINTRESOURCEW(IDI_MINES));
133  p_board->hFacesBMP = LoadBitmapW( p_board->hInst, MAKEINTRESOURCEW(IDI_FACES));
134  p_board->hLedsBMP = LoadBitmapW( p_board->hInst, MAKEINTRESOURCEW(IDI_LEDS));
135 
136  LoadBoard( p_board );
137 
138  hMenu = GetMenu( p_board->hWnd );
139  CheckMenuItem( hMenu, IDM_BEGINNER + (unsigned) p_board->difficulty,
140  MF_CHECKED );
141  if( p_board->IsMarkQ )
143  else
145  CheckLevel( p_board );
146 }
#define IDM_BEGINNER
Definition: resource.h:30
#define IDM_MARKQ
Definition: resource.h:34
BOOL IsMarkQ
Definition: main.h:73
void CheckLevel(BOARD *p_board)
Definition: main.c:49
static void LoadBoard(BOARD *p_board)
Definition: main.c:70
#define IDI_FACES
Definition: resource.h:58
#define IDI_MINES
Definition: resource.h:60
#define MF_CHECKED
Definition: winuser.h:132
DIFFICULTY difficulty
Definition: main.h:100
DWORD WINAPI CheckMenuItem(_In_ HMENU, _In_ UINT, _In_ UINT)
#define MF_UNCHECKED
Definition: winuser.h:204
HINSTANCE hInst
Definition: main.h:75
HBITMAP WINAPI LoadBitmapW(_In_opt_ HINSTANCE, _In_ LPCWSTR)
Definition: cursoricon.c:2132
#define IDI_LEDS
Definition: resource.h:59
#define MAKEINTRESOURCEW(i)
Definition: winuser.h:582
HBITMAP hMinesBMP
Definition: main.h:77
HBITMAP hFacesBMP
Definition: main.h:78
HBITMAP hLedsBMP
Definition: main.h:79
HMENU WINAPI GetMenu(_In_ HWND)
static const CLSID *static CLSID *static const GUID VARIANT VARIANT *static IServiceProvider DWORD *static HMENU
Definition: ordinal.c:60
HWND hWnd
Definition: main.h:76

◆ LoadBoard()

static void LoadBoard ( BOARD p_board)
static

Definition at line 70 of file main.c.

Referenced by InitBoard().

71 {
72  DWORD size;
73  DWORD type;
74  HKEY hkey;
76  WCHAR key_name[8];
77  unsigned i;
78 
80 
81  size = sizeof( p_board->pos.x );
82  if( RegQueryValueExW( hkey, xposW, NULL, &type, (BYTE*) &p_board->pos.x, &size ) )
83  p_board->pos.x = 0;
84 
85  size = sizeof( p_board->pos.y );
86  if( RegQueryValueExW( hkey, yposW, NULL, &type, (BYTE*) &p_board->pos.y, &size ) )
87  p_board->pos.y = 0;
88 
89  size = sizeof( p_board->rows );
90  if( RegQueryValueExW( hkey, heightW, NULL, &type, (BYTE*) &p_board->rows, &size ) )
91  p_board->rows = BEGINNER_ROWS;
92 
93  size = sizeof( p_board->cols );
94  if( RegQueryValueExW( hkey, widthW, NULL, &type, (BYTE*) &p_board->cols, &size ) )
95  p_board->cols = BEGINNER_COLS;
96 
97  size = sizeof( p_board->mines );
98  if( RegQueryValueExW( hkey, minesW, NULL, &type, (BYTE*) &p_board->mines, &size ) )
99  p_board->mines = BEGINNER_MINES;
100 
101  size = sizeof( p_board->difficulty );
102  if( RegQueryValueExW( hkey, difficultyW, NULL, &type, (BYTE*) &p_board->difficulty, &size ) )
103  p_board->difficulty = BEGINNER;
104 
105  size = sizeof( p_board->IsMarkQ );
106  if( RegQueryValueExW( hkey, markW, NULL, &type, (BYTE*) &p_board->IsMarkQ, &size ) )
107  p_board->IsMarkQ = TRUE;
108 
109  for( i = 0; i < 3; i++ ) {
110  wsprintfW( key_name, nameW, i+1 );
111  size = sizeof( data );
112  if( RegQueryValueExW( hkey, key_name, NULL, &type,
113  (LPBYTE) data, &size ) == ERROR_SUCCESS )
114  lstrcpynW( p_board->best_name[i], data, sizeof(p_board->best_name[i])/sizeof(WCHAR) );
115  else
116  LoadStringW( p_board->hInst, IDS_NOBODY, p_board->best_name[i], MAX_PLAYER_NAME_SIZE+1 );
117  }
118 
119  for( i = 0; i < 3; i++ ) {
120  wsprintfW( key_name, timeW, i+1 );
121  size = sizeof( p_board->best_time[i] );
122  if( RegQueryValueExW( hkey, key_name, NULL, &type, (BYTE*) &p_board->best_time[i], &size ) )
123  p_board->best_time[i] = 999;
124  }
125  RegCloseKey( hkey );
126 }
int WINAPIV wsprintfW(_Out_ LPWSTR, _In_ _Printf_format_string_ LPCWSTR,...)
#define BEGINNER_MINES
Definition: main.h:30
static const WCHAR markW[]
Definition: main.c:45
#define TRUE
Definition: types.h:120
long y
Definition: polytest.cpp:48
#define ERROR_SUCCESS
Definition: deptool.c:10
long x
Definition: polytest.cpp:48
#define MAX_PLAYER_NAME_SIZE
Definition: main.h:57
#define BEGINNER_COLS
Definition: main.h:31
__wchar_t WCHAR
Definition: xmlstorage.h:180
static const WCHAR yposW[]
Definition: main.c:40
#define HKEY_CURRENT_USER
Definition: winreg.h:11
#define IDS_NOBODY
Definition: resource.h:50
POINT pos
Definition: main.h:87
unsigned mines
Definition: main.h:97
BOOL IsMarkQ
Definition: main.h:73
WCHAR best_name[3][MAX_PLAYER_NAME_SIZE+1]
Definition: main.h:98
#define WCHAR
Definition: msvc.h:43
static const WCHAR xposW[]
Definition: main.c:39
int WINAPI LoadStringW(_In_opt_ HINSTANCE hInstance, _In_ UINT uID, _Out_writes_to_(cchBufferMax, return+1) LPWSTR lpBuffer, _In_ int cchBufferMax)
#define lstrcpynW
Definition: compat.h:397
GLenum GLclampf GLint i
Definition: glfuncs.h:14
LONG WINAPI RegCloseKey(HKEY hKey)
Definition: reg.c:423
unsigned char * LPBYTE
Definition: typedefs.h:52
static const WCHAR widthW[]
Definition: main.c:42
static const WCHAR difficultyW[]
Definition: main.c:44
smooth NULL
Definition: ftsmooth.c:416
DWORD best_time[3]
Definition: main.h:99
Definition: main.h:69
static const WCHAR minesW[]
Definition: main.c:43
static const WCHAR nameW[]
Definition: main.c:46
GLsizeiptr size
Definition: glext.h:5919
LONG WINAPI RegQueryValueExW(_In_ HKEY hkeyorg, _In_ LPCWSTR name, _In_ LPDWORD reserved, _In_ LPDWORD type, _In_ LPBYTE data, _In_ LPDWORD count)
Definition: reg.c:4134
DIFFICULTY difficulty
Definition: main.h:100
unsigned long DWORD
Definition: ntddk_ex.h:95
unsigned rows
Definition: main.h:95
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
unsigned cols
Definition: main.h:96
#define BEGINNER_ROWS
Definition: main.h:32
unsigned char BYTE
Definition: ntddk_ex.h:96
HINSTANCE hInst
Definition: main.h:75
int type
Definition: main.c:85
#define KEY_QUERY_VALUE
Definition: nt_native.h:1016
static const WCHAR heightW[]
Definition: main.c:41
LONG WINAPI RegOpenKeyExW(HKEY hKey, LPCWSTR lpSubKey, DWORD ulOptions, REGSAM samDesired, PHKEY phkResult)
Definition: reg.c:3381
static const WCHAR timeW[]
Definition: main.c:47

◆ MainProc()

static LRESULT WINAPI MainProc ( HWND  hWnd,
UINT  msg,
WPARAM  wParam,
LPARAM  lParam 
)
static

Definition at line 833 of file main.c.

Referenced by wWinMain().

834 {
835  HDC hdc;
836  PAINTSTRUCT ps;
837  HMENU hMenu;
838  static BOARD board;
839 
840  switch( msg ) {
841  case WM_CREATE:
842  board.hInst = ((LPCREATESTRUCTW) lParam)->hInstance;
843  board.hWnd = hWnd;
844  InitBoard( &board );
845  CreateBoard( &board );
846  return 0;
847 
848  case WM_PAINT:
849  {
850  HDC hMemDC;
851 
852  WINE_TRACE("WM_PAINT\n");
853  hdc = BeginPaint( hWnd, &ps );
854  hMemDC = CreateCompatibleDC( hdc );
855 
856  DrawBoard( hdc, hMemDC, &ps, &board );
857 
858  DeleteDC( hMemDC );
859  EndPaint( hWnd, &ps );
860 
861  return 0;
862  }
863 
864  case WM_MOVE:
865  WINE_TRACE("WM_MOVE\n");
866  board.pos.x = (short)LOWORD(lParam);
867  board.pos.y = (short)HIWORD(lParam);
868  return 0;
869 
870  case WM_DESTROY:
871  SaveBoard( &board );
872  DestroyBoard( &board );
873  PostQuitMessage( 0 );
874  return 0;
875 
876  case WM_TIMER:
877  if( board.status == PLAYING ) {
878  board.time++;
879  RedrawWindow( hWnd, &board.timer_rect, 0,
881  }
882  return 0;
883 
884  case WM_LBUTTONDOWN:
885  WINE_TRACE("WM_LBUTTONDOWN\n");
886  if( wParam & ( MK_RBUTTON | MK_SHIFT ) )
888  TestBoard( hWnd, &board, (short)LOWORD(lParam), (short)HIWORD(lParam), msg );
889  SetCapture( hWnd );
890  return 0;
891 
892  case WM_LBUTTONUP:
893  WINE_TRACE("WM_LBUTTONUP\n");
894  if( wParam & ( MK_RBUTTON | MK_SHIFT ) )
895  msg = WM_MBUTTONUP;
896  TestBoard( hWnd, &board, (short)LOWORD(lParam), (short)HIWORD(lParam), msg );
897  ReleaseCapture();
898  return 0;
899 
900  case WM_RBUTTONDOWN:
901  WINE_TRACE("WM_RBUTTONDOWN\n");
902  if( wParam & MK_LBUTTON ) {
903  board.press.x = 0;
904  board.press.y = 0;
906  }
907  TestBoard( hWnd, &board, (short)LOWORD(lParam), (short)HIWORD(lParam), msg );
908  return 0;
909 
910  case WM_RBUTTONUP:
911  WINE_TRACE("WM_RBUTTONUP\n");
912  if( wParam & MK_LBUTTON )
913  msg = WM_MBUTTONUP;
914  TestBoard( hWnd, &board, (short)LOWORD(lParam), (short)HIWORD(lParam), msg );
915  return 0;
916 
917  case WM_MBUTTONDOWN:
918  WINE_TRACE("WM_MBUTTONDOWN\n");
919  TestBoard( hWnd, &board, (short)LOWORD(lParam), (short)HIWORD(lParam), msg );
920  return 0;
921 
922  case WM_MBUTTONUP:
923  WINE_TRACE("WM_MBUTTONUP\n");
924  TestBoard( hWnd, &board, (short)LOWORD(lParam), (short)HIWORD(lParam), msg );
925  return 0;
926 
927  case WM_MOUSEMOVE:
928  {
929  if( ( wParam & MK_MBUTTON ) ||
930  ( ( wParam & MK_LBUTTON ) && ( wParam & MK_RBUTTON ) ) ) {
932  }
933  else if( wParam & MK_LBUTTON ) {
935  }
936  else {
937  return 0;
938  }
939 
940  TestBoard( hWnd, &board, (short)LOWORD(lParam), (short)HIWORD(lParam), msg );
941 
942  return 0;
943  }
944 
945  case WM_COMMAND:
946  switch(LOWORD(wParam)) {
947  case IDM_NEW:
948  CreateBoard( &board );
949  return 0;
950 
951  case IDM_MARKQ:
952  hMenu = GetMenu( hWnd );
953  board.IsMarkQ = !board.IsMarkQ;
954  if( board.IsMarkQ )
956  else
958  return 0;
959 
960  case IDM_BEGINNER:
961  SetDifficulty( &board, BEGINNER );
962  CreateBoard( &board );
963  return 0;
964 
965  case IDM_ADVANCED:
966  SetDifficulty( &board, ADVANCED );
967  CreateBoard( &board );
968  return 0;
969 
970  case IDM_EXPERT:
971  SetDifficulty( &board, EXPERT );
972  CreateBoard( &board );
973  return 0;
974 
975  case IDM_CUSTOM:
976  SetDifficulty( &board, CUSTOM );
977  CreateBoard( &board );
978  return 0;
979 
980  case IDM_EXIT:
981  SendMessageW( hWnd, WM_CLOSE, 0, 0);
982  return 0;
983 
984  case IDM_TIMES:
986  TimesDlgProc, (LPARAM) &board);
987  return 0;
988 
989  case IDM_ABOUT:
990  {
991  WCHAR appname[256], other[256];
992  LoadStringW( board.hInst, IDS_APPNAME, appname, sizeof(appname)/sizeof(WCHAR) );
993  LoadStringW( board.hInst, IDS_ABOUT, other, sizeof(other)/sizeof(WCHAR) );
994  ShellAboutW( hWnd, appname, other,
996  return 0;
997  }
998  default:
999  WINE_TRACE("Unknown WM_COMMAND command message received\n");
1000  break;
1001  }
1002  }
1003  return DefWindowProcW( hWnd, msg, wParam, lParam );
1004 }
#define WM_MBUTTONUP
Definition: winuser.h:1759
static void TestBoard(HWND hWnd, BOARD *p_board, int x, int y, int msg)
Definition: main.c:783
#define HDC
Definition: msvc.h:22
BOOL WINAPI RedrawWindow(_In_opt_ HWND, _In_opt_ LPCRECT, _In_opt_ HRGN, _In_ UINT)
Definition: main.h:69
#define LR_SHARED
Definition: winuser.h:1090
#define IMAGE_ICON
Definition: winuser.h:212
#define MK_SHIFT
Definition: winuser.h:2323
INT_PTR WINAPI DialogBoxParamW(_In_opt_ HINSTANCE, _In_ LPCWSTR, _In_opt_ HWND, _In_opt_ DLGPROC, _In_ LPARAM)
long y
Definition: polytest.cpp:48
#define WM_LBUTTONDOWN
Definition: winuser.h:1752
#define IDM_ABOUT
Definition: resource.h:29
#define IDM_BEGINNER
Definition: resource.h:30
#define MK_LBUTTON
Definition: winuser.h:2321
long x
Definition: polytest.cpp:48
#define IDM_MARKQ
Definition: resource.h:34
__wchar_t WCHAR
Definition: xmlstorage.h:180
Definition: main.h:69
#define MK_MBUTTON
Definition: winuser.h:2325
int other
Definition: msacm.c:1364
HWND hWnd
Definition: settings.c:17
POINT pos
Definition: main.h:87
#define WINE_TRACE
Definition: debug.h:358
#define WM_MOVE
Definition: winuser.h:1592
Definition: main.h:69
#define IDI_WINEMINE
Definition: resource.h:57
HDC WINAPI CreateCompatibleDC(_In_opt_ HDC hdc)
BOOL IsMarkQ
Definition: main.h:73
BOOL WINAPI EndPaint(_In_ HWND, _In_ const PAINTSTRUCT *)
unsigned time
Definition: main.h:89
#define DLG_TIMES
Definition: resource.h:62
int WINAPI LoadStringW(_In_opt_ HINSTANCE hInstance, _In_ UINT uID, _Out_writes_to_(cchBufferMax, return+1) LPWSTR lpBuffer, _In_ int cchBufferMax)
WPARAM wParam
Definition: combotst.c:138
LRESULT WINAPI DefWindowProcW(_In_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
#define IDS_ABOUT
Definition: resource.h:29
#define IDM_NEW
Definition: resource.h:26
unsigned short(__cdecl typeof(TIFFCurrentDirectory))(struct tiff *)
Definition: typeof.h:91
Definition: main.h:61
HANDLE WINAPI LoadImageW(_In_opt_ HINSTANCE, _In_ LPCWSTR, _In_ UINT, _In_ int, _In_ int, _In_ UINT)
Definition: cursoricon.c:2172
LONG_PTR LPARAM
Definition: windef.h:208
Definition: main.h:71
HDC WINAPI BeginPaint(_In_ HWND, _Out_ LPPAINTSTRUCT)
GAME_STATUS status
Definition: main.h:115
RECT timer_rect
Definition: main.h:82
UINT msg
Definition: msvc.h:92
Definition: main.h:69
INT_PTR CALLBACK TimesDlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
Definition: dialog.c:83
#define MK_RBUTTON
Definition: winuser.h:2322
static void DrawBoard(HDC hdc, HDC hMemDC, PAINTSTRUCT *ps, BOARD *p_board)
Definition: main.c:523
#define WM_DESTROY
Definition: winuser.h:1591
#define WM_RBUTTONDOWN
Definition: winuser.h:1755
#define MF_CHECKED
Definition: winuser.h:132
static void InitBoard(BOARD *p_board)
Definition: main.c:128
#define WM_TIMER
Definition: winuser.h:1718
#define WM_CLOSE
Definition: winuser.h:1603
DWORD WINAPI CheckMenuItem(_In_ HMENU, _In_ UINT, _In_ UINT)
#define IDM_CUSTOM
Definition: resource.h:33
#define WM_RBUTTONUP
Definition: winuser.h:1756
#define WM_PAINT
Definition: winuser.h:1602
#define IDM_ADVANCED
Definition: resource.h:31
static void SaveBoard(BOARD *p_board)
Definition: main.c:148
HDC hdc
Definition: main.c:9
BOOL WINAPI ShellAboutW(HWND hWnd, LPCWSTR szApp, LPCWSTR szOtherStuff, HICON hIcon)
#define WM_COMMAND
Definition: winuser.h:1716
#define MF_UNCHECKED
Definition: winuser.h:204
#define IDS_APPNAME
Definition: resource.h:49
HWND WINAPI SetCapture(_In_ HWND hWnd)
HINSTANCE hInst
Definition: main.h:75
BOOL WINAPI DeleteDC(_In_ HDC)
static void CreateBoard(BOARD *p_board)
Definition: main.c:256
LRESULT WINAPI SendMessageW(_In_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
#define WM_LBUTTONUP
Definition: winuser.h:1753
struct tagCREATESTRUCTW * LPCREATESTRUCTW
#define WM_MBUTTONDOWN
Definition: winuser.h:1758
#define WM_MOUSEMOVE
Definition: winuser.h:1751
static void DestroyBoard(BOARD *p_board)
Definition: main.c:182
#define IDM_EXIT
Definition: resource.h:27
#define RDW_UPDATENOW
Definition: winuser.h:1206
BOOL WINAPI ReleaseCapture(void)
Definition: message.c:2864
#define WM_CREATE
Definition: winuser.h:1590
#define HIWORD(l)
Definition: typedefs.h:246
#define IDM_EXPERT
Definition: resource.h:32
#define MAKEINTRESOURCEW(i)
Definition: winuser.h:582
#define IDM_TIMES
Definition: resource.h:28
POINT press
Definition: main.h:102
HMENU WINAPI GetMenu(_In_ HWND)
static const CLSID *static CLSID *static const GUID VARIANT VARIANT *static IServiceProvider DWORD *static HMENU
Definition: ordinal.c:60
LPARAM lParam
Definition: combotst.c:139
#define LOWORD(l)
Definition: pedump.c:82
__analysis_noreturn void WINAPI PostQuitMessage(_In_ int)
#define RDW_INVALIDATE
Definition: winuser.h:1200
HWND hWnd
Definition: main.h:76
static void SetDifficulty(BOARD *p_board, DIFFICULTY difficulty)
Definition: main.c:189

◆ MoveOnScreen()

static void MoveOnScreen ( RECT rect)
static

Definition at line 240 of file main.c.

Referenced by CreateBoard().

241 {
242  HMONITOR hMonitor;
243  MONITORINFO mi;
244 
245  /* find the nearest monitor ... */
246  hMonitor = MonitorFromRect(rect, MONITOR_DEFAULTTONEAREST);
247 
248  /* ... and move it into the work area (ie excluding task bar)*/
249  mi.cbSize = sizeof(mi);
250  GetMonitorInfoW(hMonitor, &mi);
251 
252  ShiftBetween(&rect->left, &rect->right, mi.rcWork.left, mi.rcWork.right);
253  ShiftBetween(&rect->top, &rect->bottom, mi.rcWork.top, mi.rcWork.bottom);
254 }
LONG top
Definition: windef.h:297
static MONITORINFO mi
Definition: win.c:7331
LONG left
Definition: windef.h:296
LONG right
Definition: windef.h:298
static void ShiftBetween(LONG *x, LONG *y, LONG a, LONG b)
Definition: main.c:228
BOOL WINAPI GetMonitorInfoW(_In_ HMONITOR, _Inout_ LPMONITORINFO)
DWORD cbSize
Definition: winuser.h:3726
HMONITOR WINAPI MonitorFromRect(LPCRECT, DWORD)
LONG bottom
Definition: windef.h:299

◆ PlaceMines()

static void PlaceMines ( BOARD p_board,
int  selected_col,
int  selected_row 
)
static

Definition at line 331 of file main.c.

Referenced by TestMines().

332 {
333  int i, j;
334  unsigned col, row;
335 
336  srand( (unsigned) time( NULL ) );
337 
338  /* Temporarily place a mine at the selected box until all the other
339  * mines are placed, this avoids checking in the mine creation loop. */
340  p_board->box[selected_col][selected_row].IsMine = TRUE;
341 
342  /* create mines */
343  i = 0;
344  while( (unsigned) i < p_board->mines ) {
345  col = rand() % p_board->cols + 1;
346  row = rand() % p_board->rows + 1;
347 
348  if( !p_board->box[col][row].IsMine ) {
349  i++;
350  p_board->box[col][row].IsMine = TRUE;
351  }
352  }
353 
354  /* Remove temporarily placed mine for selected box */
355  p_board->box[selected_col][selected_row].IsMine = FALSE;
356 
357  /*
358  * Now we label the remaining boxes with the
359  * number of mines surrounding them.
360  */
361  for( col = 1; col < p_board->cols + 1; col++ )
362  for( row = 1; row < p_board->rows + 1; row++ ) {
363  for( i = -1; i <= 1; i++ )
364  for( j = -1; j <= 1; j++ ) {
365  if( p_board->box[col + i][row + j].IsMine ) {
366  p_board->box[col][row].NumMines++ ;
367  }
368  }
369  }
370 }
GLenum GLclampf GLint GLenum GLuint GLenum GLenum GLsizei GLenum const GLvoid GLfloat GLfloat GLfloat GLfloat GLclampd GLint GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean GLboolean GLboolean GLboolean GLint GLenum GLsizei const GLvoid GLenum GLint GLenum GLint GLint GLsizei GLint GLenum GLint GLint GLint GLint GLsizei GLenum GLsizei const GLuint GLboolean GLenum GLenum GLint GLsizei GLenum GLsizei GLenum const GLvoid GLboolean const GLboolean GLenum const GLdouble const GLfloat const GLdouble const GLfloat GLenum GLint GLint GLint GLint GLint GLint j
Definition: glfuncs.h:98
#define TRUE
Definition: types.h:120
void __cdecl srand(_In_ unsigned int _Seed)
__u16 time
Definition: mkdosfs.c:366
GLenum GLclampf GLint i
Definition: glfuncs.h:14
_Check_return_ int __cdecl rand(void)
Definition: rand.c:10
smooth NULL
Definition: ftsmooth.c:416
unsigned rows
Definition: main.h:95
unsigned cols
Definition: main.h:96
struct png_info_def *typedef unsigned char **typedef struct png_info_def *typedef struct png_info_def *typedef struct png_info_def *typedef unsigned char ** row
Definition: typeof.h:76

◆ PressBox()

static void PressBox ( BOARD p_board,
unsigned  col,
unsigned  row 
)
static

Definition at line 598 of file main.c.

Referenced by PressBoxes(), and TestMines().

599 {
600  HDC hdc;
601  HGDIOBJ hOldObj;
602  HDC hMemDC;
603 
604  hdc = GetDC( p_board->hWnd );
605  hMemDC = CreateCompatibleDC( hdc );
606  hOldObj = SelectObject (hMemDC, p_board->hMinesBMP);
607 
608  DrawMine( hdc, hMemDC, p_board, col, row, TRUE );
609 
610  SelectObject( hMemDC, hOldObj );
611  DeleteDC( hMemDC );
612  ReleaseDC( p_board->hWnd, hdc );
613 }
static void DrawMine(HDC hdc, HDC hMemDC, BOARD *p_board, unsigned col, unsigned row, BOOL IsPressed)
Definition: main.c:372
#define HDC
Definition: msvc.h:22
#define TRUE
Definition: types.h:120
HDC WINAPI GetDC(_In_opt_ HWND)
HGDIOBJ WINAPI SelectObject(_In_ HDC, _In_ HGDIOBJ)
Definition: dc.c:1497
HDC WINAPI CreateCompatibleDC(_In_opt_ HDC hdc)
int WINAPI ReleaseDC(_In_opt_ HWND, _In_ HDC)
HDC hdc
Definition: main.c:9
BOOL WINAPI DeleteDC(_In_ HDC)
HBITMAP hMinesBMP
Definition: main.h:77
struct png_info_def *typedef unsigned char **typedef struct png_info_def *typedef struct png_info_def *typedef struct png_info_def *typedef unsigned char ** row
Definition: typeof.h:76
HWND hWnd
Definition: main.h:76

◆ PressBoxes()

static void PressBoxes ( BOARD p_board,
unsigned  col,
unsigned  row 
)
static

Definition at line 616 of file main.c.

Referenced by TestMines().

617 {
618  int i, j;
619 
620  for( i = -1; i <= 1; i++ )
621  for( j = -1; j <= 1; j++ ) {
622  p_board->box[col + i][row + j].IsPressed = TRUE;
623  PressBox( p_board, col + i, row + j );
624  }
625 
626  for( i = -1; i <= 1; i++ )
627  for( j = -1; j <= 1; j++ ) {
628  if( !p_board->box[p_board->press.x + i][p_board->press.y + j].IsPressed )
629  UnpressBox( p_board, p_board->press.x + i, p_board->press.y + j );
630  }
631 
632  for( i = -1; i <= 1; i++ )
633  for( j = -1; j <= 1; j++ ) {
634  p_board->box[col + i][row + j].IsPressed = FALSE;
635  PressBox( p_board, col + i, row + j );
636  }
637 
638  p_board->press.x = col;
639  p_board->press.y = row;
640 }
GLenum GLclampf GLint GLenum GLuint GLenum GLenum GLsizei GLenum const GLvoid GLfloat GLfloat GLfloat GLfloat GLclampd GLint GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean GLboolean GLboolean GLboolean GLint GLenum GLsizei const GLvoid GLenum GLint GLenum GLint GLint GLsizei GLint GLenum GLint GLint GLint GLint GLsizei GLenum GLsizei const GLuint GLboolean GLenum GLenum GLint GLsizei GLenum GLsizei GLenum const GLvoid GLboolean const GLboolean GLenum const GLdouble const GLfloat const GLdouble const GLfloat GLenum GLint GLint GLint GLint GLint GLint j
Definition: glfuncs.h:98
#define TRUE
Definition: types.h:120
long y
Definition: polytest.cpp:48
static void UnpressBox(BOARD *p_board, unsigned col, unsigned row)
Definition: main.c:569
long x
Definition: polytest.cpp:48
static void PressBox(BOARD *p_board, unsigned col, unsigned row)
Definition: main.c:598
GLenum GLclampf GLint i
Definition: glfuncs.h:14
POINT press
Definition: main.h:102
struct png_info_def *typedef unsigned char **typedef struct png_info_def *typedef struct png_info_def *typedef struct png_info_def *typedef unsigned char ** row
Definition: typeof.h:76

◆ SaveBoard()

static void SaveBoard ( BOARD p_board)
static

Definition at line 148 of file main.c.

Referenced by MainProc().

149 {
150  HKEY hkey;
151  unsigned i;
153  WCHAR key_name[8];
154 
156  0, NULL,
158  &hkey, NULL ) != ERROR_SUCCESS)
159  return;
160 
161  RegSetValueExW( hkey, xposW, 0, REG_DWORD, (LPBYTE) &p_board->pos.x, sizeof(p_board->pos.x) );
162  RegSetValueExW( hkey, yposW, 0, REG_DWORD, (LPBYTE) &p_board->pos.y, sizeof(p_board->pos.y) );
163  RegSetValueExW( hkey, difficultyW, 0, REG_DWORD, (LPBYTE) &p_board->difficulty, sizeof(p_board->difficulty) );
164  RegSetValueExW( hkey, heightW, 0, REG_DWORD, (LPBYTE) &p_board->rows, sizeof(p_board->rows) );
165  RegSetValueExW( hkey, widthW, 0, REG_DWORD, (LPBYTE) &p_board->cols, sizeof(p_board->cols) );
166  RegSetValueExW( hkey, minesW, 0, REG_DWORD, (LPBYTE) &p_board->mines, sizeof(p_board->mines) );
167  RegSetValueExW( hkey, markW, 0, REG_DWORD, (LPBYTE) &p_board->IsMarkQ, sizeof(p_board->IsMarkQ) );
168 
169  for( i = 0; i < 3; i++ ) {
170  wsprintfW( key_name, nameW, i+1 );
171  lstrcpynW( data, p_board->best_name[i], sizeof(data)/sizeof(WCHAR) );
172  RegSetValueExW( hkey, key_name, 0, REG_SZ, (LPBYTE) data, (lstrlenW(data)+1) * sizeof(WCHAR) );
173  }
174 
175  for( i = 0; i < 3; i++ ) {
176  wsprintfW( key_name, timeW, i+1 );
177  RegSetValueExW( hkey, key_name, 0, REG_DWORD, (LPBYTE) &p_board->best_time[i], sizeof(p_board->best_time[i]) );
178  }
179  RegCloseKey( hkey );
180 }
int WINAPIV wsprintfW(_Out_ LPWSTR, _In_ _Printf_format_string_ LPCWSTR,...)
static const WCHAR markW[]
Definition: main.c:45
long y
Definition: polytest.cpp:48
#define ERROR_SUCCESS
Definition: deptool.c:10
long x
Definition: polytest.cpp:48
#define MAX_PLAYER_NAME_SIZE
Definition: main.h:57
__wchar_t WCHAR
Definition: xmlstorage.h:180
static const WCHAR yposW[]
Definition: main.c:40
#define HKEY_CURRENT_USER
Definition: winreg.h:11
POINT pos
Definition: main.h:87
unsigned mines
Definition: main.h:97
BOOL IsMarkQ
Definition: main.h:73
WCHAR best_name[3][MAX_PLAYER_NAME_SIZE+1]
Definition: main.h:98
#define lstrlenW
Definition: compat.h:407
static const WCHAR xposW[]
Definition: main.c:39
LONG WINAPI RegCreateKeyExW(_In_ HKEY hKey, _In_ LPCWSTR lpSubKey, _In_ DWORD Reserved, _In_opt_ LPWSTR lpClass, _In_ DWORD dwOptions, _In_ REGSAM samDesired, _In_opt_ LPSECURITY_ATTRIBUTES lpSecurityAttributes, _Out_ PHKEY phkResult, _Out_opt_ LPDWORD lpdwDisposition)
Definition: reg.c:1094
#define lstrcpynW
Definition: compat.h:397
GLenum GLclampf GLint i
Definition: glfuncs.h:14
LONG WINAPI RegCloseKey(HKEY hKey)
Definition: reg.c:423
unsigned char * LPBYTE
Definition: typedefs.h:52
static const WCHAR widthW[]
Definition: main.c:42
static const WCHAR difficultyW[]
Definition: main.c:44
smooth NULL
Definition: ftsmooth.c:416
DWORD best_time[3]
Definition: main.h:99
static const WCHAR minesW[]
Definition: main.c:43
static const WCHAR nameW[]
Definition: main.c:46
#define REG_OPTION_NON_VOLATILE
Definition: nt_native.h:1057
#define KEY_WRITE
Definition: nt_native.h:1031
LONG WINAPI RegSetValueExW(_In_ HKEY hKey, _In_ LPCWSTR lpValueName, _In_ DWORD Reserved, _In_ DWORD dwType, _In_ CONST BYTE *lpData, _In_ DWORD cbData)
Definition: reg.c:4917
DIFFICULTY difficulty
Definition: main.h:100
unsigned rows
Definition: main.h:95
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
unsigned cols
Definition: main.h:96
static const WCHAR heightW[]
Definition: main.c:41
#define REG_DWORD
Definition: sdbapi.c:539
static const WCHAR timeW[]
Definition: main.c:47
#define REG_SZ
Definition: layer.c:22

◆ SetDifficulty()

static void SetDifficulty ( BOARD p_board,
DIFFICULTY  difficulty 
)
static

Definition at line 189 of file main.c.

Referenced by MainProc().

190 {
191  HMENU hMenu;
192 
193  if ( difficulty == CUSTOM )
194  if (DialogBoxParamW( p_board->hInst, MAKEINTRESOURCEW(DLG_CUSTOM), p_board->hWnd,
195  CustomDlgProc, (LPARAM) p_board) != 0)
196  return;
197 
198  hMenu = GetMenu( p_board->hWnd );
199  CheckMenuItem( hMenu, IDM_BEGINNER + p_board->difficulty, MF_UNCHECKED );
200  p_board->difficulty = difficulty;
201  CheckMenuItem( hMenu, IDM_BEGINNER + difficulty, MF_CHECKED );
202 
203  switch( difficulty ) {
204  case BEGINNER:
205  p_board->cols = BEGINNER_COLS;
206  p_board->rows = BEGINNER_ROWS;
207  p_board->mines = BEGINNER_MINES;
208  break;
209 
210  case ADVANCED:
211  p_board->cols = ADVANCED_COLS;
212  p_board->rows = ADVANCED_ROWS;
213  p_board->mines = ADVANCED_MINES;
214  break;
215 
216  case EXPERT:
217  p_board->cols = EXPERT_COLS;
218  p_board->rows = EXPERT_ROWS;
219 
220  p_board->mines = EXPERT_MINES;
221  break;
222 
223  case CUSTOM:
224  break;
225  }
226 }
#define BEGINNER_MINES
Definition: main.h:30
Definition: main.h:69
#define ADVANCED_ROWS
Definition: main.h:36
INT_PTR WINAPI DialogBoxParamW(_In_opt_ HINSTANCE, _In_ LPCWSTR, _In_opt_ HWND, _In_opt_ DLGPROC, _In_ LPARAM)
INT_PTR CALLBACK CustomDlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
Definition: dialog.c:23
#define IDM_BEGINNER
Definition: resource.h:30
#define BEGINNER_COLS
Definition: main.h:31
Definition: main.h:69
Definition: main.h:69
LONG_PTR LPARAM
Definition: windef.h:208
Definition: main.h:69
#define EXPERT_COLS
Definition: main.h:39
#define DLG_CUSTOM
Definition: resource.h:64
#define MF_CHECKED
Definition: winuser.h:132
#define EXPERT_ROWS
Definition: main.h:40
DWORD WINAPI CheckMenuItem(_In_ HMENU, _In_ UINT, _In_ UINT)
#define MF_UNCHECKED
Definition: winuser.h:204
#define BEGINNER_ROWS
Definition: main.h:32
#define ADVANCED_MINES
Definition: main.h:34
HINSTANCE hInst
Definition: main.h:75
#define EXPERT_MINES
Definition: main.h:38
#define MAKEINTRESOURCEW(i)
Definition: winuser.h:582
HMENU WINAPI GetMenu(_In_ HWND)
static const CLSID *static CLSID *static const GUID VARIANT VARIANT *static IServiceProvider DWORD *static HMENU
Definition: ordinal.c:60
#define ADVANCED_COLS
Definition: main.h:35
HWND hWnd
Definition: main.h:76

◆ ShiftBetween()

static void ShiftBetween ( LONG x,
LONG y,
LONG  a,
LONG  b 
)
static

Definition at line 228 of file main.c.

Referenced by MoveOnScreen().

229 {
230  if (*x < a) {
231  *y += a - *x;
232  *x = a;
233  }
234  else if (*y > b) {
235  *x -= *y - b;
236  *y = b;
237  }
238 }
INT INT y
Definition: msvc.h:62
#define a
Definition: ke_i.h:78
#define b
Definition: ke_i.h:79
GLboolean GLboolean GLboolean b
Definition: glext.h:6204
INT x
Definition: msvc.h:62
GLboolean GLboolean GLboolean GLboolean a
Definition: glext.h:6204

◆ TestBoard()

static void TestBoard ( HWND  hWnd,
BOARD p_board,
int  x,
int  y,
int  msg 
)
static

Definition at line 783 of file main.c.

Referenced by MainProc().

784 {
785  POINT pt;
786  unsigned col,row;
787 
788  pt.x = x;
789  pt.y = y;
790 
791  if( PtInRect( &p_board->mines_rect, pt ) && p_board->status != GAMEOVER
792  && p_board->status != WON )
793  TestMines( p_board, pt, msg );
794  else {
795  UnpressBoxes( p_board,
796  p_board->press.x,
797  p_board->press.y );
798  p_board->press.x = 0;
799  p_board->press.y = 0;
800  }
801 
802  if( p_board->boxes_left == 0 ) {
803  p_board->status = WON;
804 
805  if (p_board->num_flags < p_board->mines) {
806  for( row = 1; row <= p_board->rows; row++ ) {
807  for( col = 1; col <= p_board->cols; col++ ) {
808  if (p_board->box[col][row].IsMine && p_board->box[col][row].FlagType != FLAG)
809  p_board->box[col][row].FlagType = FLAG;
810  }
811  }
812 
813  p_board->num_flags = p_board->mines;
814 
815  RedrawWindow( p_board->hWnd, NULL, 0,
817  }
818 
819  if( p_board->difficulty != CUSTOM &&
820  p_board->time < p_board->best_time[p_board->difficulty] ) {
821  p_board->best_time[p_board->difficulty] = p_board->time;
822 
824  CongratsDlgProc, (LPARAM) p_board);
826  TimesDlgProc, (LPARAM) p_board);
827  }
828  }
829  TestFace( p_board, pt, msg );
830 }
BOOL WINAPI RedrawWindow(_In_opt_ HWND, _In_opt_ LPCRECT, _In_opt_ HRGN, _In_ UINT)
INT_PTR WINAPI DialogBoxParamW(_In_opt_ HINSTANCE, _In_ LPCWSTR, _In_opt_ HWND, _In_opt_ DLGPROC, _In_ LPARAM)
long y
Definition: polytest.cpp:48
long x
Definition: polytest.cpp:48
#define pt(x, y)
Definition: drawing.c:79
Definition: main.h:69
unsigned mines
Definition: main.h:97
#define DLG_CONGRATS
Definition: resource.h:63
unsigned time
Definition: main.h:89
#define DLG_TIMES
Definition: resource.h:62
INT INT y
Definition: msvc.h:62
LONG_PTR LPARAM
Definition: windef.h:208
GAME_STATUS status
Definition: main.h:115
static void TestFace(BOARD *p_board, POINT pt, int msg)
Definition: main.c:758
UINT msg
Definition: msvc.h:92
smooth NULL
Definition: ftsmooth.c:416
DWORD best_time[3]
Definition: main.h:99
INT_PTR CALLBACK TimesDlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
Definition: dialog.c:83
DIFFICULTY difficulty
Definition: main.h:100
Definition: main.h:61
unsigned rows
Definition: main.h:95
RECT mines_rect
Definition: main.h:80
unsigned cols
Definition: main.h:96
unsigned boxes_left
Definition: main.h:91
INT_PTR CALLBACK CongratsDlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
Definition: dialog.c:55
static void TestMines(BOARD *p_board, POINT pt, int msg)
Definition: main.c:693
HINSTANCE hInst
Definition: main.h:75
INT x
Definition: msvc.h:62
Definition: main.h:61
unsigned num_flags
Definition: main.h:90
BOOL WINAPI PtInRect(_In_ LPCRECT, _In_ POINT)
#define RDW_UPDATENOW
Definition: winuser.h:1206
Definition: inflate.c:14
#define MAKEINTRESOURCEW(i)
Definition: winuser.h:582
POINT press
Definition: main.h:102
#define RDW_INVALIDATE
Definition: winuser.h:1200
struct png_info_def *typedef unsigned char **typedef struct png_info_def *typedef struct png_info_def *typedef struct png_info_def *typedef unsigned char ** row
Definition: typeof.h:76
HWND hWnd
Definition: main.h:76
static void UnpressBoxes(BOARD *p_board, unsigned col, unsigned row)
Definition: main.c:587

◆ TestFace()

static void TestFace ( BOARD p_board,
POINT  pt,
int  msg 
)
static

Definition at line 758 of file main.c.

Referenced by TestBoard().

759 {
760  if( p_board->status == PLAYING || p_board->status == WAITING ) {
761  if( msg == WM_LBUTTONDOWN || msg == WM_MBUTTONDOWN )
762  p_board->face_bmp = OOH_BMP;
763  else p_board->face_bmp = SMILE_BMP;
764  }
765  else if( p_board->status == GAMEOVER )
766  p_board->face_bmp = DEAD_BMP;
767  else if( p_board->status == WON )
768  p_board->face_bmp = COOL_BMP;
769 
770  if( PtInRect( &p_board->face_rect, pt ) ) {
771  if( msg == WM_LBUTTONDOWN )
772  p_board->face_bmp = SPRESS_BMP;
773 
774  if( msg == WM_LBUTTONUP )
775  CreateBoard( p_board );
776  }
777 
778  RedrawWindow( p_board->hWnd, &p_board->face_rect, 0,
780 }
BOOL WINAPI RedrawWindow(_In_opt_ HWND, _In_opt_ LPCRECT, _In_opt_ HRGN, _In_ UINT)
Definition: main.h:61
#define WM_LBUTTONDOWN
Definition: winuser.h:1752
FACE_BMP face_bmp
Definition: main.h:114
Definition: main.h:59
Definition: main.h:61
GAME_STATUS status
Definition: main.h:115
UINT msg
Definition: msvc.h:92
Definition: main.h:59
Definition: main.h:61
RECT face_rect
Definition: main.h:81
Definition: main.h:59
static void CreateBoard(BOARD *p_board)
Definition: main.c:256
Definition: main.h:61
#define WM_LBUTTONUP
Definition: winuser.h:1753
#define WM_MBUTTONDOWN
Definition: winuser.h:1758
BOOL WINAPI PtInRect(_In_ LPCRECT, _In_ POINT)
#define RDW_UPDATENOW
Definition: winuser.h:1206
#define RDW_INVALIDATE
Definition: winuser.h:1200
Definition: main.h:59
HWND hWnd
Definition: main.h:76

◆ TestMines()

static void TestMines ( BOARD p_board,
POINT  pt,
int  msg 
)
static

Definition at line 693 of file main.c.

Referenced by TestBoard().

694 {
695  BOOL draw = TRUE;
696  int col, row;
697 
698  col = (pt.x - p_board->mines_rect.left) / MINE_WIDTH + 1;
699  row = (pt.y - p_board->mines_rect.top ) / MINE_HEIGHT + 1;
700 
701  switch ( msg ) {
702  case WM_LBUTTONDOWN:
703  if( p_board->press.x != col || p_board->press.y != row ) {
704  UnpressBox( p_board,
705  p_board->press.x, p_board->press.y );
706  p_board->press.x = col;
707  p_board->press.y = row;
708  PressBox( p_board, col, row );
709  }
710  draw = FALSE;
711  break;
712 
713  case WM_LBUTTONUP:
714  if( p_board->press.x != col || p_board->press.y != row )
715  UnpressBox( p_board,
716  p_board->press.x, p_board->press.y );
717  p_board->press.x = 0;
718  p_board->press.y = 0;
719  if( p_board->box[col][row].FlagType != FLAG
720  && p_board->status != PLAYING )
721  {
722  p_board->status = PLAYING;
723  PlaceMines( p_board, col, row );
724  }
725  CompleteBox( p_board, col, row );
726  break;
727 
728  case WM_MBUTTONDOWN:
729  PressBoxes( p_board, col, row );
730  draw = FALSE;
731  break;
732 
733  case WM_MBUTTONUP:
734  if( p_board->press.x != col || p_board->press.y != row )
735  UnpressBoxes( p_board,
736  p_board->press.x, p_board->press.y );
737  p_board->press.x = 0;
738  p_board->press.y = 0;
739  CompleteBoxes( p_board, col, row );
740  break;
741 
742  case WM_RBUTTONDOWN:
743  AddFlag( p_board, col, row );
744  break;
745  default:
746  WINE_TRACE("Unknown message type received in TestMines\n");
747  break;
748  }
749 
750  if( draw )
751  {
752  RedrawWindow( p_board->hWnd, NULL, 0,
754  }
755 }
#define WM_MBUTTONUP
Definition: winuser.h:1759
BOOL WINAPI RedrawWindow(_In_opt_ HWND, _In_opt_ LPCRECT, _In_opt_ HRGN, _In_ UINT)
#define TRUE
Definition: types.h:120
static void PlaceMines(BOARD *p_board, int selected_col, int selected_row)
Definition: main.c:331
long y
Definition: polytest.cpp:48
static void UnpressBox(BOARD *p_board, unsigned col, unsigned row)
Definition: main.c:569
#define WM_LBUTTONDOWN
Definition: winuser.h:1752
long x
Definition: polytest.cpp:48
LONG top
Definition: windef.h:297
#define WINE_TRACE
Definition: debug.h:358
LONG left
Definition: windef.h:296
static void PressBox(BOARD *p_board, unsigned col, unsigned row)
Definition: main.c:598
Definition: main.h:61
GAME_STATUS status
Definition: main.h:115
UINT msg
Definition: msvc.h:92
smooth NULL
Definition: ftsmooth.c:416
#define WM_RBUTTONDOWN
Definition: winuser.h:1755
#define MINE_WIDTH
Definition: main.h:50
unsigned int BOOL
Definition: ntddk_ex.h:94
static void AddFlag(BOARD *p_board, unsigned col, unsigned row)
Definition: main.c:545
static void CompleteBoxes(BOARD *p_board, unsigned col, unsigned row)
Definition: main.c:670
#define MINE_HEIGHT
Definition: main.h:51
RECT mines_rect
Definition: main.h:80
static void CompleteBox(BOARD *p_board, unsigned col, unsigned row)
Definition: main.c:643
#define WM_LBUTTONUP
Definition: winuser.h:1753
#define WM_MBUTTONDOWN
Definition: winuser.h:1758
static void PressBoxes(BOARD *p_board, unsigned col, unsigned row)
Definition: main.c:616
#define RDW_UPDATENOW
Definition: winuser.h:1206
Definition: inflate.c:14
POINT press
Definition: main.h:102
#define RDW_INVALIDATE
Definition: winuser.h:1200
struct png_info_def *typedef unsigned char **typedef struct png_info_def *typedef struct png_info_def *typedef struct png_info_def *typedef unsigned char ** row
Definition: typeof.h:76
HWND hWnd
Definition: main.h:76
static void UnpressBoxes(BOARD *p_board, unsigned col, unsigned row)
Definition: main.c:587

◆ UnpressBox()

static void UnpressBox ( BOARD p_board,
unsigned  col,
unsigned  row 
)
static

Definition at line 569 of file main.c.

Referenced by PressBoxes(), TestMines(), and UnpressBoxes().

570 {
571  HDC hdc;
572  HGDIOBJ hOldObj;
573  HDC hMemDC;
574 
575  hdc = GetDC( p_board->hWnd );
576  hMemDC = CreateCompatibleDC( hdc );
577  hOldObj = SelectObject( hMemDC, p_board->hMinesBMP );
578 
579  DrawMine( hdc, hMemDC, p_board, col, row, FALSE );
580 
581  SelectObject( hMemDC, hOldObj );
582  DeleteDC( hMemDC );
583  ReleaseDC( p_board->hWnd, hdc );
584 }
static void DrawMine(HDC hdc, HDC hMemDC, BOARD *p_board, unsigned col, unsigned row, BOOL IsPressed)
Definition: main.c:372
#define HDC
Definition: msvc.h:22
HDC WINAPI GetDC(_In_opt_ HWND)
HGDIOBJ WINAPI SelectObject(_In_ HDC, _In_ HGDIOBJ)
Definition: dc.c:1497
HDC WINAPI CreateCompatibleDC(_In_opt_ HDC hdc)
int WINAPI ReleaseDC(_In_opt_ HWND, _In_ HDC)
HDC hdc
Definition: main.c:9
BOOL WINAPI DeleteDC(_In_ HDC)
HBITMAP hMinesBMP
Definition: main.h:77
struct png_info_def *typedef unsigned char **typedef struct png_info_def *typedef struct png_info_def *typedef struct png_info_def *typedef unsigned char ** row
Definition: typeof.h:76
HWND hWnd
Definition: main.h:76

◆ UnpressBoxes()

static void UnpressBoxes ( BOARD p_board,
unsigned  col,
unsigned  row 
)
static

Definition at line 587 of file main.c.

Referenced by TestBoard(), and TestMines().

588 {
589  int i, j;
590 
591  for( i = -1; i <= 1; i++ )
592  for( j = -1; j <= 1; j++ ) {
593  UnpressBox( p_board, col + i, row + j );
594  }
595 }
GLenum GLclampf GLint GLenum GLuint GLenum GLenum GLsizei GLenum const GLvoid GLfloat GLfloat GLfloat GLfloat GLclampd GLint GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean GLboolean GLboolean GLboolean GLint GLenum GLsizei const GLvoid GLenum GLint GLenum GLint GLint GLsizei GLint GLenum GLint GLint GLint GLint GLsizei GLenum GLsizei const GLuint GLboolean GLenum GLenum GLint GLsizei GLenum GLsizei GLenum const GLvoid GLboolean const GLboolean GLenum const GLdouble const GLfloat const GLdouble const GLfloat GLenum GLint GLint GLint GLint GLint GLint j
Definition: glfuncs.h:98
static void UnpressBox(BOARD *p_board, unsigned col, unsigned row)
Definition: main.c:569
GLenum GLclampf GLint i
Definition: glfuncs.h:14
struct png_info_def *typedef unsigned char **typedef struct png_info_def *typedef struct png_info_def *typedef struct png_info_def *typedef unsigned char ** row
Definition: typeof.h:76

◆ WINE_DEFAULT_DEBUG_CHANNEL()

WINE_DEFAULT_DEBUG_CHANNEL ( winemine  )

◆ wWinMain()

int WINAPI wWinMain ( HINSTANCE  hInstance,
HINSTANCE  hPrevInstance,
LPWSTR  lpCmdLine,
int  nShowCmd 
)

This file has no copyright assigned and is placed in the Public Domain. This file is part of the w64 mingw-runtime package. No warranty is given; refer to the file DISCLAIMER.PD within this package.

Definition at line 1006 of file main.c.

1007 {
1008  MSG msg;
1009  WNDCLASSEXW wc;
1010  HWND hWnd;
1011  HACCEL haccel;
1012  WCHAR appname[20];
1013 
1014  LoadStringW( hInst, IDS_APPNAME, appname, sizeof(appname)/sizeof(WCHAR));
1015 
1016  wc.cbSize = sizeof(wc);
1017  wc.style = 0;
1018  wc.lpfnWndProc = MainProc;
1019  wc.cbClsExtra = 0;
1020  wc.cbWndExtra = 0;
1021  wc.hInstance = hInst;
1022  wc.hIcon = LoadIconW( hInst, MAKEINTRESOURCEW(IDI_WINEMINE) );
1024  wc.hbrBackground = GetSysColorBrush(COLOR_BTNFACE); //MOD for ROS
1026  wc.lpszClassName = appname;
1029 
1030  if (!RegisterClassExW(&wc)) ExitProcess(1);
1031  hWnd = CreateWindowW( appname, appname,
1032  wnd_style,
1034  0, 0, hInst, NULL );
1035 
1036  if (!hWnd) ExitProcess(1);
1037 
1038  ShowWindow( hWnd, cmdshow );
1039  UpdateWindow( hWnd );
1040 
1041  haccel = LoadAcceleratorsW( hInst, MAKEINTRESOURCEW(IDA_WINEMINE) );
1042  SetTimer( hWnd, ID_TIMER, 1000, NULL );
1043 
1044  while( GetMessageW(&msg, 0, 0, 0) ) {
1045  if (!TranslateAcceleratorW( hWnd, haccel, &msg ))
1046  TranslateMessage( &msg );
1047 
1048  DispatchMessageW( &msg );
1049  }
1050  return msg.wParam;
1051 }
BOOL WINAPI TranslateMessage(_In_ const MSG *)
#define LR_SHARED
Definition: winuser.h:1090
#define IMAGE_ICON
Definition: winuser.h:212
int cbWndExtra
Definition: winuser.h:3173
__wchar_t WCHAR
Definition: xmlstorage.h:180
TW_UINT32 TW_UINT16 TW_UINT16 MSG
Definition: twain.h:1827
BOOL WINAPI UpdateWindow(_In_ HWND)
HWND hWnd
Definition: settings.c:17
VOID WINAPI ExitProcess(IN UINT uExitCode)
Definition: proc.c:1517
#define SM_CYSMICON
Definition: winuser.h:1003
HICON hIcon
Definition: winuser.h:3175
#define IDI_WINEMINE
Definition: resource.h:57
#define IDI_APPLICATION
Definition: winuser.h:699
BOOL WINAPI ShowWindow(_In_ HWND, _In_ int)
int WINAPI LoadStringW(_In_opt_ HINSTANCE hInstance, _In_ UINT uID, _Out_writes_to_(cchBufferMax, return+1) LPWSTR lpBuffer, _In_ int cchBufferMax)
#define CreateWindowW(a, b, c, d, e, f, g, h, i, j, k)
Definition: winuser.h:4185
ATOM WINAPI RegisterClassExW(_In_ CONST WNDCLASSEXW *)
HINSTANCE hInst
Definition: main.c:29
LPCWSTR lpszMenuName
Definition: winuser.h:3178
LRESULT WINAPI DispatchMessageW(_In_ const MSG *)
HANDLE WINAPI LoadImageW(_In_opt_ HINSTANCE, _In_ LPCWSTR, _In_ UINT, _In_ int, _In_ int, _In_ UINT)
Definition: cursoricon.c:2172
#define CW_USEDEFAULT
Definition: winuser.h:225
HACCEL WINAPI LoadAcceleratorsW(_In_opt_ HINSTANCE, _In_ LPCWSTR)
smooth NULL
Definition: ftsmooth.c:416
int cbClsExtra
Definition: winuser.h:3172
UINT_PTR WINAPI SetTimer(_In_opt_ HWND, _In_ UINT_PTR, _In_ UINT, _In_opt_ TIMERPROC)
LPCWSTR lpszClassName
Definition: winuser.h:3179
static const DWORD wnd_style
Definition: main.c:34
HBRUSH hbrBackground
Definition: winuser.h:3177
UINT cbSize
Definition: winuser.h:3169
int WINAPI GetSystemMetrics(_In_ int)
static LRESULT WINAPI MainProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
Definition: main.c:833
HCURSOR WINAPI LoadCursorW(_In_opt_ HINSTANCE, _In_ LPCWSTR)
Definition: cursoricon.c:2074
HINSTANCE hInstance
Definition: winuser.h:3174
#define SM_CXSMICON
Definition: winuser.h:1002
int WINAPI TranslateAcceleratorW(_In_ HWND, _In_ HACCEL, _In_ LPMSG)
#define COLOR_BTNFACE
Definition: winuser.h:918
#define ID_TIMER
Definition: resource.h:23
HCURSOR hCursor
Definition: winuser.h:3176
UINT style
Definition: winuser.h:3170
WNDPROC lpfnWndProc
Definition: winuser.h:3171
#define IDS_APPNAME
Definition: resource.h:49
BOOL WINAPI GetMessageW(_Out_ LPMSG, _In_opt_ HWND, _In_ UINT, _In_ UINT)
HICON hIconSm
Definition: winuser.h:3180
#define msg(x)
Definition: auth_time.c:54
HICON WINAPI LoadIconW(_In_opt_ HINSTANCE, _In_ LPCWSTR)
Definition: cursoricon.c:2044
#define IDA_WINEMINE
Definition: resource.h:53
#define MAKEINTRESOURCEW(i)
Definition: winuser.h:582
WCHAR * LPWSTR
Definition: xmlstorage.h:184
HBRUSH WINAPI GetSysColorBrush(_In_ int)
#define IDM_WINEMINE
Definition: resource.h:55

Variable Documentation

◆ difficultyW

const WCHAR difficultyW[] = {'D','i','f','f','i','c','u','l','t','y',0}
static

Definition at line 44 of file main.c.

Referenced by LoadBoard(), and SaveBoard().

◆ heightW

const WCHAR heightW[] = {'H','e','i','g','h','t',0}
static

Definition at line 41 of file main.c.

Referenced by LoadBoard(), and SaveBoard().

◆ markW

const WCHAR markW[] = {'M','a','r','k',0}
static

Definition at line 45 of file main.c.

Referenced by LoadBoard(), and SaveBoard().

◆ minesW

const WCHAR minesW[] = {'M','i','n','e','s',0}
static

Definition at line 43 of file main.c.

Referenced by LoadBoard(), and SaveBoard().

◆ nameW

const WCHAR nameW[] = {'N','a','m','e','%','u',0}
static

Definition at line 46 of file main.c.

Referenced by _test_file_name(), AtlAxCreateDialogA(), COM_RegReadPath(), create_classes_key(), create_database(), create_database_wordcount(), create_file_test(), create_listview_controlW(), create_parent_window(), create_registry_key(), create_storage(), CredIsMarshaledCredentialA(), CryptAcquireContextW(), CryptGetDefaultProviderW(), CryptSetProviderExW(), delete_file_test(), DnsValidateName_A(), DnsValidateName_UTF8(), drive_get_FileSystem(), drive_get_VolumeName(), EditWndProc_common(), EnumResourceLanguagesA(), EnumResourceLanguagesW(), filedlg_collect_places_pidls(), fill_processor_information(), fill_props(), find_installed_ports(), find_resourceA(), find_resourceW(), find_string_index(), find_window_class(), get_assembly_name_attribute(), get_manifest_in_associated_manifest(), get_manifest_in_module(), get_registry_locale_info(), GetTextFaceA(), helper_createpackage(), HTMLFormElement_get_dispid(), HTMLMetaElement_get_name(), IntSetupDiSetDeviceRegistryPropertyAW(), is_elem_name(), lineGetCountryW(), LoadBoard(), lookup_assembly(), MCIWndProc(), MsiBeginTransactionA(), open_classes_key(), open_file_test(), parse_assembly(), parse_files(), PdhLookupPerfIndexByNameA(), query_typelib_path(), RegQueryValueExA(), RtlCreateActivationContext(), SaveBoard(), SetupDiGetDeviceRegistryPropertyW(), SetupGetFileCompressionInfoExA(), SetupOpenInfFileA(), SetUserGeoID(), SymAddSymbol(), symt_enum_locals_helper(), symt_enum_module(), symt_get_nameW(), tally_test_file(), test_actctx(), test_button_class(), test_ClosePort(), test_comctl32_class(), test_CreateTextFile(), test_CreateTypeLib(), test_DialogBoxParam(), test_dispatch(), test_ExtractIcon(), test_font_events_disp(), test_GetComputerName(), test_GetComputerNameExW(), test_interface_identifier_conversion(), test_junction_points(), test_legacy_filter(), test_mxwriter_dtd(), test_NtCreateFile(), test_OpenPort(), test_PathYetAnotherMakeUniqueName(), test_put_dataType(), test_query_attribute_information_file(), test_query_volume_information_file(), test_Read(), test_ReadAll(), test_readonly(), test_RtlDosPathNameToNtPathName_U_WithStatus(), test_SetDocString(), test_SetFuncAndParamNames(), test_SetVarHelpContext(), test_SHParseDisplayName(), test_sip(), test_Win32_Bios(), test_Win32_ComputerSystem(), test_Win32_ComputerSystemProduct(), test_Win32_OperatingSystem(), test_Win32_Processor(), test_Win32_SystemEnclosure(), test_WriteLine(), test_WTSEnumerateProcessesW(), testGetComputerObjectNameW(), testGetUserNameExW(), testTDA(), ValidateShim(), VBSAXAttributes_getLocalName(), wave_in_test_device(), and wave_out_test_device().

◆ registry_key

Initial value:
= {'S','o','f','t','w','a','r','e','\\',
'M','i','c','r','o','s','o','f','t','\\',
'W','i','n','M','i','n','e',0}

Definition at line 35 of file main.c.

◆ timeW

const WCHAR timeW[] = {'T','i','m','e','%','u',0}
static

Definition at line 47 of file main.c.

Referenced by LoadBoard(), and SaveBoard().

◆ widthW

const WCHAR widthW[] = {'W','i','d','t','h',0}
static

Definition at line 42 of file main.c.

Referenced by LoadBoard(), and SaveBoard().

◆ wnd_style

Definition at line 34 of file main.c.

Referenced by CreateBoard(), and wWinMain().

◆ xposW

const WCHAR xposW[] = {'X','p','o','s',0}
static

Definition at line 39 of file main.c.

Referenced by LoadBoard(), and SaveBoard().

◆ yposW

const WCHAR yposW[] = {'Y','p','o','s',0}
static

Definition at line 40 of file main.c.

Referenced by LoadBoard(), and SaveBoard().