关于API的一些问题新手求教
下面是一个扫雷的程序 为什么会出现下面问题 WIN7系统VC++6.0开发的#include <assert.h>
#include <windowsx.h>
#include "resource.h"
#include "WinMine.h"
// the only global variable
extern BOARD board;
void TranslateMouseMsg(UINT* puMsg, WPARAM wParam)
{
if (*puMsg == WM_LBUTTONDOWN)
SetCapture(board.hWnd);
else if (*puMsg == WM_LBUTTONUP)
ReleaseCapture();
else if ((*puMsg == WM_MOUSEMOVE) && (wParam & MK_LBUTTON))
{
*puMsg = WM_LBUTTONDOWN;
}
}
void ProcessMouseMsg(UINT uMsg, LPARAM lParam)
{
POINT pt;
int row, col;
pt.x = GET_X_LPARAM(lParam);
pt.y = GET_Y_LPARAM(lParam);
if (PtInRect(&board.FaceRect, pt))
{
if (uMsg == WM_LBUTTONDOWN)
{
DisplayFace(FACE_DOWN);
}
else if (uMsg == WM_LBUTTONUP)
{
NewGame();
}
return;
}
if (board.GameState == GAMEWON)
{
DisplayFace(FACE_WIN);
return;
}
else if (board.GameState == GAMELOST)
{
DisplayFace(FACE_LOSE);
return;
}
Pt2RowCol(pt, &row, &col);
if (uMsg == WM_LBUTTONDOWN)
{
DisplayFace(FACE_CAUTION);
if (row != board.rowPressed || col != board.colPressed)
{
UnPressBox();
PressBox(row, col);
}
}
else
{
UnPressBox();
if (row < 0)
{
// row<0 means we clicked outside the grid
DisplayFace(FACE_HAPPY);
return;
}
if (uMsg == WM_LBUTTONUP)
{
if (board.GameState == WAITING)
{
LayMines(row, col);
board.GameState = PLAYING;
}
if (StepBox(row, col))
{
if (board.uSteps == board.uMaxSteps)
GameWon();
else
DisplayFace(FACE_HAPPY);
}
else
GameLost();
}
else if (uMsg == WM_RBUTTONUP && board.GameState != WAITING)
{
if (board.Box[row][col].State == BS_DICEY)
{
SetAndDispBoxState(row, col, BS_INITIAL);
}
else if (board.Box[row][col].State == BS_FLAG)
{
SetAndDispBoxState(row, col, board.bMark? BS_DICEY : BS_INITIAL);
IncMinesLeft();
}
else if (board.Box[row][col].State == BS_INITIAL
&& (board.uMinesLeft != 0))
{
SetAndDispBoxState(row, col, BS_FLAG);
DecMinesLeft();
}
}
}
}
void Pt2RowCol(POINT pt, int *prow, int *pcol)
{
if (PtInRect(&board.GridRect, pt))
{
*prow = (pt.y - board.GridRect.top) / BOX_HEIGHT;
*pcol = (pt.x - board.GridRect.left) / BOX_WIDTH;
}
else
{
*prow = -1;
*pcol = -1;
}
}
void PressBox(int row, int col)
{
if ( (row >= 0) &&
(board.Box[row][col].State == BS_INITIAL ||
board.Box[row][col].State == BS_DICEY))
{
assert(col >= 0);
board.rowPressed = row;
board.colPressed = col;
SetAndDispBoxState(row, col,
(board.Box[row][col].State == BS_INITIAL)? BS_DOWN: BS_DICEY_DOWN);
}
}
void UnPressBox()
{
if (board.rowPressed >= 0)
{
BOX_STATE state = board.Box[board.rowPressed][board.colPressed].State;
assert(state == BS_DOWN || state == BS_DICEY_DOWN);
SetAndDispBoxState(board.rowPressed, board.colPressed,
(state == BS_DOWN)? BS_INITIAL : BS_DICEY);
board.rowPressed = -1;
board.colPressed = -1;
}
}
void LayMines(int row, int col)
{
UINT cMines = 0;
UINT r, c;
// temporarily mark this box as mine
board.Box[row][col].fMine = TRUE;
srand(GetTickCount());
while (cMines < board.uMines)
{
r = ((UINT) rand()) % board.uRows;
c = ((UINT) rand()) % board.uCols;
if (!board.Box[r][c].fMine)
{
board.Box[r][c].fMine = TRUE;
cMines++;
}
}
// remove the mine attribute of the box
board.Box[row][col].fMine = FALSE;
}
void GameWon()
{
UINT r, c;
board.GameState = GAMEWON;
ZeroMinesLeft();
DisplayFace(FACE_WIN);
for (r = 0; r < board.uRows; r++)
for (c = 0; c < board.uCols; c++)
{
if (board.Box[r][c].fMine && board.Box[r][c].State != BS_FLAG)
{
SetAndDispBoxState(r, c, BS_FLAG);
}
}
}
void GameLost()
{
UINT r, c;
board.GameState = GAMELOST;
DisplayFace(FACE_LOSE);
for (r = 0; r < board.uRows; r++)
for (c = 0; c < board.uCols; c++)
{
if (board.Box[r][c].fMine && board.Box[r][c].State != BS_BLAST)
{
SetAndDispBoxState(r, c, BS_MINE);
}
else if (board.Box[r][c].State == BS_FLAG)
{
SetAndDispBoxState(r, c, BS_WRONG);
}
}
}
#define WITHIN_GRID(r, c) \
( (UINT) r < board.uRows && (UINT) c < board.uCols )
// Count the mines surrounding the box
UINT CountMines(int row, int col)
{
UINT cMines = 0;
int r, c;
for (r = row-1; r <= row+1; r++)
for (c = col-1; c <= col+1; c++)
{
if (WITHIN_GRID(r, c) && (r != row || c != col) &&
board.Box[r][c].fMine)
{
cMines++;
}
}
return cMines;
}
// steps on this box, return value indicates if it is safe
BOOL StepBox(int row, int col)
{
UINT cMinesSurround;
if (board.Box[row][col].State != BS_INITIAL &&
board.Box[row][col].State != BS_DICEY)
{
// previously stepped, must be safe, and no need to step second time
return TRUE;
}
if (board.Box[row][col].fMine)
{
// stepped on a mine!
SetAndDispBoxState(row, col, BS_BLAST);
return FALSE;
}
board.uSteps++;
cMinesSurround = CountMines(row, col);
SetAndDispBoxState(row, col, BS_DOWN - cMinesSurround);
if (cMinesSurround == 0)
{
int r, c;
for (r = row-1; r <= row+1; r++)
for (c = col-1; c <= col+1; c++)
{
if (WITHIN_GRID(r, c) && (r != row || c != col))
{
StepBox(r, c);
}
}
}
return TRUE;
}
该程序是没有语法问题的 但是在编译的时候会出现下面错误而无法连接
--------------------Configuration: MineGame - Win32 Debug--------------------
Linking...
MineGame.obj : error LNK2001: unresolved external symbol _board
MineGame.obj : error LNK2001: unresolved external symbol _DecMinesLeft
MineGame.obj : error LNK2001: unresolved external symbol _IncMinesLeft
MineGame.obj : error LNK2001: unresolved external symbol _SetAndDispBoxState
MineGame.obj : error LNK2001: unresolved external symbol _NewGame
MineGame.obj : error LNK2001: unresolved external symbol _DisplayFace
MineGame.obj : error LNK2001: unresolved external symbol _ZeroMinesLeft
LIBCD.lib(crt0.obj) : error LNK2001: unresolved external symbol _main
Debug/MineGame.exe : fatal error LNK1120: 8 unresolved externals
Error executing link.exe.
MineGame.exe - 9 error(s), 0 warning(s)
}