//======================================================================
// TicTac1 - Simple tic-tac-toe game
//
// Written for the book Programming Windows CE
// Copyright (C) 2007 Douglas Boling
//
//======================================================================
#include <windows.h> // For all that Windows stuff
#include <commctrl.h> // Command bar includes
#include "tictac1.h" // Program-specific stuff
//----------------------------------------------------------------------
// Global data
//
const TCHAR szAppName[] = TEXT ("TicTac1");
HINSTANCE hInst; // Program instance handle
// State data for game
RECT rectBoard = {0, 0, 0, 0}; // Used to place game board.
RECT rectPrompt; // Used to place prompt.
BYTE bBoard[9]; // Keeps track of X�s and O�s.
BYTE bTurn = 0; // Keeps track of the turn.
// Message dispatch table for MainWindowProc
const struct decodeUINT MainMessages[] = {
WM_SIZE, DoSizeMain,
WM_PAINT, DoPaintMain,
WM_LBUTTONUP, DoLButtonUpMain,
WM_DESTROY, DoDestroyMain,
};
//======================================================================
//
// Program entry point
//
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPWSTR lpCmdLine, int nCmdShow) {
MSG msg;
HWND hwndMain;
// Initialize this instance.
hwndMain = InitInstance (hInstance, lpCmdLine, nCmdShow);
if (hwndMain == 0)
return 0x10;
// Application message loop
while (GetMessage (&msg, NULL, 0, 0)) {
TranslateMessage (&msg);
DispatchMessage (&msg);
}
// Instance cleanup
return TermInstance (hInstance, msg.wParam);
}
//----------------------------------------------------------------------
// InitInstance - Instance initialization
//
HWND InitInstance (HINSTANCE hInstance, LPWSTR lpCmdLine, int nCmdShow) {
WNDCLASS wc;
HWND hWnd;
// Save program instance handle in global variable.
hInst = hInstance;
#if defined(WIN32_PLATFORM_PSPC) || defined(WIN32_PLATFORM_WFSP)
// If Windows Mobile, allow only one instance of the application.
hWnd = FindWindow (szAppName, NULL);
if (hWnd) {
SetForegroundWindow ((HWND)(((DWORD)hWnd) | 0x01));
return 0;
}
#endif
// Register application main window class.
wc.style = 0; // Window style
wc.lpfnWndProc = MainWndProc; // Callback function
wc.cbClsExtra = 0; // Extra class data
wc.cbWndExtra = 0; // Extra window data
wc.hInstance = hInstance; // Owner handle
wc.hIcon = NULL, // Application icon
wc.hCursor = LoadCursor (NULL, IDC_ARROW);// Default cursor
wc.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH);
wc.lpszMenuName = NULL; // Menu name
wc.lpszClassName = szAppName; // Window class name
if (RegisterClass (&wc) == 0) return 0;
// Create main window.
hWnd = CreateWindowEx (WS_EX_NODRAG, szAppName, TEXT ("TicTac1"),
WS_VISIBLE | WS_CAPTION | WS_SYSMENU,
CW_USEDEFAULT, CW_USEDEFAULT,
CW_USEDEFAULT, CW_USEDEFAULT,
NULL, NULL, hInstance, NULL);
// Return fail code if window not created.
if (!IsWindow (hWnd)) return 0;
// Standard show and update calls
ShowWindow (hWnd, nCmdShow);
UpdateWindow (hWnd);
return hWnd;
}
//----------------------------------------------------------------------
// TermInstance - Program cleanup
//
int TermInstance (HINSTANCE hInstance, int nDefRC) {
return nDefRC;
}
//======================================================================
// Message handling procedures for MainWindow
//
//----------------------------------------------------------------------
// MainWndProc - Callback function for application window
//
LRESULT CALLBACK MainWndProc (HWND hWnd, UINT wMsg, WPARAM wParam,
LPARAM lParam) {
INT i;
//
// Search message list to see if we need to handle this
// message. If in list, call procedure.
//
for (i = 0; i < dim(MainMessages); i++) {
if (wMsg == MainMessages[i].Code)
return (*MainMessages[i].Fxn)(hWnd, wMsg, wParam, lParam);
}
return DefWindowProc(hWnd, wMsg, wParam, lParam);
}
//----------------------------------------------------------------------
// DoSizeMain - Process WM_SIZE message for window.
//
LRESULT DoSizeMain (HWND hWnd, UINT wMsg, WPARAM wParam,
LPARAM lParam) {
RECT rect;
INT i;
// Adjust the size of the client rect to take into account
// the command bar height.
GetClientRect (hWnd, &rect);
// Initialize the board rectangle if not yet initialized.
if (rectBoard.right == 0) {
// Initialize the board.
for (i = 0; i < dim(bBoard); i++)
bBoard[i] = 0;
}
// Define the playing board rect.
rectBoard = rect;
rectPrompt = rect;
// Layout depends on portrait or landscape screen.
if (rect.right - rect.left > rect.bottom - rect.top) {
rectBoard.left += 20;
rectBoard.top += 10;
rectBoard.bottom -= 10;
rectBoard.right = rectBoard.bottom - rectBoard.top + 10;
rectPrompt.left = rectBoard.right + 10;
} else {
rectBoard.left += 20;
rectBoard.right -= 20;
rectBoard.top += 10;
rectBoard.bottom = rectBoard.right - rectBoard.left + 10;
rectPrompt.top = rectBoard.bottom + 10;
}
return 0;
}
//----------------------------------------------------------------------
// DoPaintMain - Process WM_PAINT message for window.
//
LRESULT DoPaintMain (HWND hWnd, UINT wMsg, WPARAM wParam,
LPARAM lParam) {
PAINTSTRUCT ps;
RECT rect;
HFONT hFont, hOldFont;
HDC hdc;
GetClientRect (hWnd, &rect);
hdc = BeginPaint (hWnd, &ps);
// Draw the board.
DrawBoard (hdc, &rectBoard);
// Write the prompt to the screen.
hFont = (HFONT)GetStockObject (SYSTEM_FONT);
hOldFont = (HFONT)SelectObject (hdc, hFont);
if (bTurn == 0)
DrawText (hdc, TEXT (" X�s turn"), -1, &rectPrompt,
DT_CENTER | DT_VCENTER | DT_SINGLELINE);
else
DrawText (hdc, TEXT (" O�s turn"), -1, &rectPrompt,
DT_CENTER | DT_VCENTER | DT_SINGLELINE);
SelectObject (hdc, hOldFont);
EndPaint (hWnd, &ps);
return 0;
}
//----------------------------------------------------------------------
// DoLButtonUpMain - Process WM_LBUTTONUP message for window.
//
LRESULT DoLButtonUpMain (HWND hWnd, UINT wMsg, WPARAM wParam,
LPARAM lParam) {
POINT pt;
INT cx, cy, nCell = 0;
pt.x = LOWORD (lParam);
pt.y = HIWORD (lParam);
// See if pen on board. If so, determine which cell.
if (PtInRect (&rectBoard, pt)){
// Normalize point to upper left corner of board.
pt.x -= rectBoard.left;
pt.y -= rectBoard.top;
// Compute size of each cell.
cx = (rectBoard.right - rectBoard.left)/3;
cy = (rectBoard.bottom - rectBoard.top)/3;
// Find column.
nCell = (pt.x / cx);
// Find row.
nCell += (pt.y / cy) * 3;
// If cell empty, fill it with mark.
if (bBoard[nCell] == 0) {
if (bTurn) {
bBoard[nCell] = 2;
bTurn = 0;
} else {
bBoard[nCell] = 1;
bTurn = 1;
}
Invalidat
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
Keyboard and Stylus.7z (45个子文件)
KeyTrac
KeyTrac
ProgWinCE_SDK (x86)
Debug
KeyTrac.exe 14KB
Release
KeyTrac.exe 5KB
KeyTrac.cpp 10KB
KeyTrac.vcproj.MICROSOF-YUE.yue.user 3KB
KeyTrac.h 2KB
KeyTrac.vcproj 9KB
ProgWinCE_SDK (ARMV4I)
Debug
KeyTrac.exe 8KB
Release
KeyTrac.exe 6KB
KeyTrac.vcproj.MICROSOFT-YUE.Administrator.user 3KB
KeyTrac.suo 8KB
KeyTrac.sln 2KB
TicTac1
TicTac1.sln 2KB
TicTac1.suo 8KB
TicTac1
ProgWinCE_SDK (x86)
Debug
TicTac1.exe 14KB
Release
TicTac1.exe 5KB
TicTac1.vcproj.MICROSOFT-YUE.Administrator.user 3KB
TicTac1.vcproj.MICROSOF-YUE.yue.user 3KB
TicTac1.cpp 11KB
TicTac1.h 1KB
TicTac1.vcproj 9KB
ProgWinCE_SDK (ARMV4I)
Debug
vc80.pdb 84KB
TicTac1.pdb 139KB
BuildLog.htm 6KB
TicTac1.obj 25KB
TicTac1.exe 8KB
vc80.idb 195KB
Release
TicTac1.exe 7KB
TicTac1.ncb 1.2MB
PenTrac
PenTrac.sln 2KB
PenTrac.ncb 3.43MB
PenTrac.suo 8KB
PenTrac
ProgWinCE_SDK (x86)
Debug
PenTrac.exe 13KB
Release
PenTrac.exe 4KB
PenTrac.vcproj.MICROSOF-YUE.yue.user 3KB
PenTrac.vcproj.MICROSOFT-YUE.Administrator.user 3KB
PenTrac.vcproj 9KB
PenTrac.cpp 6KB
PenTrac.h 1KB
ProgWinCE_SDK (ARMV4I)
Debug
PenTrac.exe 6KB
vc80.pdb 76KB
BuildLog.htm 6KB
PenTrac.obj 18KB
PenTrac.pdb 123KB
vc80.idb 187KB
Release
PenTrac.exe 5KB
共 45 条
- 1
资源评论
- Mushroom_lb2012-09-21谢谢分享,能运行
- u0102663482013-11-04调用的系统内置的软键盘,凑合用用
boyzxscn
- 粉丝: 0
- 资源: 9
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- ModStartCMS v8.4.0 框架稳定性持续迭代,修复部分已知问题
- bleder 教室学校学生教育室办公室考试
- 人脸检测-使用OpenCV实现的动漫+漫画人脸检测算法-附项目源码-优质项目实战.zip
- 道路贴图,材质材料免费
- 人脸检测-基于OpenCV+Node.js+WebSockets实现的实时人脸检测应用-附项目源码-优质项目实战.zip
- 一些常见的MySQL死锁案例-mysql-deadlocks-master(源代码+案例+图解说明)
- UE4动画烘焙器-ue4.27
- 新建文件夹.zip
- 1103a2a791bbd96ea98021062e327495b1c422e32fb27e0c2d6404b1bd74b692.gif
- 同城相亲交友php小程序
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功