#include <windows.h> // For all that Windows stuff
#include <commctrl.h> // Command bar includes
#include "ClickDraw.h" // Program-specific stuff
//----------------------------------------------------------------------
// Global data
//
const TCHAR szAppName[] = TEXT ("ClickDraw");
HINSTANCE hInst;
RECT rectBoard ;
BYTE Temp[16];
BYTE bTurn = 0;
const struct decodeUINT MainMessages[] = {
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 ("ClickDraw"),
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.
//
//----------------------------------------------------------------------
// 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);
rectBoard = rect;
hdc = BeginPaint (hWnd, &ps);
DrawBoard (hdc, &rect);
hFont = (HFONT)GetStockObject (SYSTEM_FONT);
hOldFont = (HFONT)SelectObject (hdc, hFont);
if (bTurn == 0)
DrawText (hdc, TEXT ("triangle's turn "), -1, &rect,
DT_CENTER | DT_VCENTER);
else
DrawText (hdc, TEXT (" Round's turn"), -1, &rect,
DT_CENTER | DT_VCENTER );
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 dx, dy, nCell = 0;
pt.x = LOWORD (lParam);
pt.y = HIWORD (lParam);
if (PtInRect (&rectBoard, pt)){
dx = (rectBoard.right - rectBoard.left)/4;
dy = (rectBoard.bottom - rectBoard.top)/4;
nCell = (pt.x / dx);
nCell += (pt.y / dy) * 4;
if (Temp[nCell] == 0) {
if (bTurn) {
Temp[nCell] = 2;
bTurn = 0;
} else {
Temp[nCell] = 1;
bTurn = 1;
}
InvalidateRect (hWnd, NULL, FALSE);
} else {
MessageBeep (0);
return 0;
}
}
return 0;
}
//----------------------------------------------------------------------
// DoDestroyMain - Process WM_DESTROY message for window.
//
LRESULT DoDestroyMain (HWND hWnd, UINT wMsg, WPARAM wParam,
LPARAM lParam) {
PostQuitMessage (0);
return 0;
}
void DrawPic (HDC hdc, HPEN hPen, RECT *prect, INT nCell, INT nType) {
POINT pt[2];
INT dx, dy;
RECT rect;
dx = (prect->right - prect->left)/4;
dy = (prect->bottom - prect->top)/4;
rect.left = (dx * (nCell % 4) + prect->left) + 10;
rect.right = rect.right = rect.left + dx - 20;
rect.top = dy * (nCell / 4) + prect->top + 10;
rect.bottom = rect.top + dy - 20;
if (nType == 1) {
pt[0].x = rect.left+(rect.right-rect.left)/2;
pt[0].y = rect.top;
pt[1].x = rect.left;
pt[1].y = rect.bottom;
Polyline (hdc, pt, 2);
pt[1].x=rect.right;
Polyline(hdc,pt,2);
pt[0].x=rect.left;
pt[0].y=rect.bottom;
pt[1].x=rect.right;
pt[1].y=rect.bottom;
Polyline(hdc,pt,2);
} else if (nType == 2) {
Ellipse (hdc, rect.left, rect.top, rect.right, rect.bottom);
}
return;
}
//----------------------------------------------------------------------
// DrawBoard - Draw the tic-tac-toe board.
// VK_MENU
void DrawBoard (HDC hdc, RECT *prect) {
HPEN hPen, hOldPen;
POINT pt[2];
LOGPEN lp;
INT i, dx, dy;
lp.lopnStyle = PS_SOLID;
lp.lopnWidth.x = 5;
lp.lopnWidth.y = 5;
lp.lopnColor = RGB (0, 0, 0);
hPen = CreatePenIndirect (&lp);
hOldPen = (HPEN)SelectObject (hdc, hPen);
dx = (prect->right - prect->left)/4;
dy = (prect->bottom - prect->top)/4;
pt[0].x = dx + prect->left;
pt[1].x = dx + prect->left;
pt[0].y = prect->top;
pt[1].y = prect->bottom;
Polyline (hdc, pt, 2);
for(i=0;i<2;i++)
{
p
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
Win CE.rar (26个子文件)
ClickDraw
ClickDraw
ClickDraw.vcproj.BOBO-1.bobo.user 2KB
ClickDraw.vcproj 5KB
ClickDraw.cpp 8KB
SDKName-DeeguaEmulator (ARMV4I)
Debug
vc80.pdb 92KB
BuildLog.htm 6KB
ClickDraw.pdb 139KB
ClickDraw.exe 9KB
vc80.idb 275KB
ClickDraw.obj 24KB
ClickDraw.h 1006B
ClickDraw.ncb 5.46MB
ClickDraw.suo 12KB
ClickDraw.sln 1KB
PenTest
PenTest.sln 1KB
PenTest.ncb 3.59MB
PenTest
PenTest.vcproj.BOBO-1.bobo.user 2KB
PenTest.h 705B
PenTest.cpp 5KB
PenTest.vcproj 5KB
SDKName-DeeguaEmulator (ARMV4I)
Debug
PenTest.exe 6KB
vc80.pdb 84KB
BuildLog.htm 6KB
PenTest.obj 19KB
PenTest.pdb 123KB
vc80.idb 251KB
PenTest.suo 11KB
共 26 条
- 1
资源评论
llc603
- 粉丝: 29
- 资源: 42
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功