目录
1、创建一个600x600的窗口,并画一条横线和竖线,以他们交点画个矩形
前言:
本五子棋代码只实现了人人对战,不包含人机对战内容,小白编写,有不足之处请谅解!
所需头文件:
#include <stdio.h>
#include <minigui/common.h>
#include <minigui/minigui.h>
#include <minigui/gdi.h>
#include <minigui/window.h>
#include <minigui/control.h>
#include <string.h>
主函数
//主函数
int MiniGUIMain (int argc, const char* argv[]) {
MSG Msg;
HWND hMainWnd;
MAINWINCREATE CreateInfo;
#ifdef _LITE_VERSION
SetDesktopRect(0, 0, 800, 600);
#endif
CreateInfo.dwStyle = WS_VISIBLE | WS_BORDER | WS_CAPTION;
CreateInfo.dwExStyle = WS_EX_NONE;
CreateInfo.spCaption = "HelloWorld";
CreateInfo.hMenu =createmenu();
CreateInfo.hCursor = GetSystemCursor(0);
CreateInfo.hIcon = 0;
CreateInfo.MainWindowProc = HelloWinProc;
CreateInfo.lx = 0; //窗口左上角x坐标
CreateInfo.ty = 0; //左上角y坐标
CreateInfo.rx = 600; //右下角x坐标
CreateInfo.by = 600; //右下角y坐标
CreateInfo.iBkColor = COLOR_lightwhite;
CreateInfo.dwAddData = 0;
CreateInfo.hHosting = HWND_DESKTOP;
hMainWnd = CreateMainWindow (&CreateInfo);
if (hMainWnd == HWND_INVALID)
return -1;
ShowWindow(hMainWnd, SW_SHOWNORMAL);
//消息队列
while (GetMessage(&Msg, hMainWnd)) {
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
MainWindowThreadCleanup (hMainWnd);
UnloadBitmap(&pic); 此函数用于卸载指定的位图
return 0;
}
#ifndef _LITE_VERSION
#include <minigui/dti.c>
#endif
下面开始编写:
1、创建一个600x600的窗口,并画一条横线和竖线,以他们交点画个矩形
#include <stdio.h>
#include <minigui/common.h>
#include <minigui/minigui.h>
#include <minigui/gdi.h>
#include <minigui/window.h>
#include <minigui/control.h>
#include <string.h>
static BITMAP pic;
HDC hdc;
static int HelloWinProc(HWND hWnd, int message, WPARAM wParam, LPARAM lParam) {
int i, j;
LoadBitmap (HDC_SCREEN, &pic, "2.bmp");//加载位图
switch (message) {
case MSG_PAINT:
hdc = BeginPaint (hWnd);
FillBoxWithBitmap (hdc, 0, 0, 560, 560, &pic);
//画横线
MoveTo(hdc, 20, 100);//开始点坐标
LineTo(hdc, 500, 100);//结束点坐标
//画竖线
MoveTo(hdc, 100, 20);
LineTo(hdc, 100, 500);
//画矩形
Rectangle(hdc,90,90,110,110);
EndPaint (hWnd, hdc);
return 0;
//主窗口和控件的销毁
case MSG_CLOSE:
DestroyAllControls (hWnd);
DestroyMainWindow (hWnd);
PostQuitMessage (hWnd);
return 0;
}
return DefaultMainWinProc (hWnd, message, wParam, lParam);
}
int MiniGUIMain (int argc, const char* argv[]) {
MSG Msg;
HWND hMainWnd;
MAINWINCREATE CreateInfo;
#ifdef _LITE_VERSION
SetDesktopRect(0, 0, 800, 600);
#endif
CreateInfo.dwStyle = WS_VISIBLE | WS_BORDER | WS_CAPTION;
CreateInfo.dwExStyle = WS_EX_NONE;
CreateInfo.spCaption = "HelloWorld";
CreateInfo.hMenu =0;
CreateInfo.hCursor = GetSystemCursor(0);
CreateInfo.hIcon = 0;
CreateInfo.MainWindowProc = HelloWinProc;
CreateInfo.lx = 0; //窗口左上角x坐标
CreateInfo.ty = 0;//窗口左上角xy坐标
CreateInfo.rx = 600;//窗口右下角x坐标
CreateInfo.by = 600;//窗口右下角y坐标
CreateInfo.iBkColor = COLOR_lightwhite;
CreateInfo.dwAddData = 0;
CreateInfo.hHosting = HWND_DESKTOP;
hMainWnd = CreateMainWindow (&CreateInfo);
if (hMainWnd == HWND_INVALID)
return -1;
ShowWindow(hMainWnd, SW_SHOWNORMAL);
while (GetMessage(&Msg, hMainWnd)) {
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
MainWindowThreadCleanup (hMainWnd);
UnloadBitmap(&pic);//此函数用于卸载指定的位图
return 0;
}
#ifndef _LITE_VERSION
#include <minigui/dti.c>
#endif
效果
2、判断鼠标左键点击是否在矩形内
static int HelloWinProc(HWND hWnd, int message, WPARAM wParam, LPARAM lParam) {
int i, j;
LoadBitmap (HDC_SCREEN, &pic, "2.bmp");
switch (message) {
case MSG_LBUTTONDOWN:
SetCapture(hWnd); //获取鼠标位置
pre_x = LOWORD (lParam);
pre_y = HIWORD (lParam);
RECT rect_1 = {90,90,110,110};
if (PtInRect(&rect_1, pre_x, pre_y)) //判断是否在矩形内,如果在,发送坐标
{
sprintf(str,"%d,%d ",pre_x,pre_y);
MessageBox (hWnd, str, "place:", MB_OK | MB_ICONINFORMATION);
}
break;
case MSG_PAINT:
hdc = BeginPaint (hWnd);
FillBoxWithBitmap (hdc, 0, 0, 560, 560, &pic);
MoveTo(hdc, 20, 100);
LineTo(hdc, 500, 100);
MoveTo(hdc, 100, 20);
LineTo(hdc, 100, 500);
Rectangle(hdc,90,90,110,110);
EndPaint (hWnd, hdc);
return 0;
case MSG_LBUTTONUP:
ReleaseCapture();
break;
case MSG_CLOSE:
DestroyAllControls (hWnd);
DestroyMainWindow (hWnd);
PostQuitMessage (hWnd);
return 0;
}
return DefaultMainWinProc (hWnd, message, wParam, lParam);
}
3、如果在矩形内画一个黑色的圆
case MSG_LBUTTONDOWN:
SetCapture(hWnd); //获取鼠标位置
pre_x = LOWORD (lParam);
pre_y = HIWORD (lParam);
RECT rect_1 = {90,90,110,110};
if (PtInRect(&rect_1, pre_x, pre_y))
{
//sprintf(str,"%d,%d ",pre_x,pre_y);
//MessageBox (hWnd, str, "place:", MB_OK | MB_ICONINFORMATION);
hdc = GetClientDC(hWnd);
SetBrushColor(hdc, COLOR_black);//设置黑色
FillCircle(hdc,100,100, 10);//画圆
BitBlt(hdc, 0, 0, 20, 20, hdc, 0, 0, 0);//颜色数据的位块传输
ReleaseDC(hdc);
}
break;
4、布局棋盘
#include <stdio.h>
#include <minigui/common.h>
#include <minigui/minigui.h>
#include <minigui/gdi.h>
#include <minigui/window.h>
#include <minigui/control.h>
#include <string.h>
int colors,color = 1;
static BITMAP pic;
HDC hdc;
static int pre_x, pre_y;
int chess[25][25] = {{0}};//棋盘
static int HelloWinProc(HWND hWnd, int message, WPARAM wParam, LPARAM lParam) {
int i, j;
LoadBitmap (HDC_SCREEN, &pic, "2.bmp");
switch (message) {
case MSG_LBUTTONDOWN:
SetCapture(hWnd);
pre_x = LOWORD (lParam);
pre_y = HIWORD (lParam);
//判断点是否在矩形内并画圆
for (i = 1; i <= 25; i++) {
for (j = 1; j <= 25; j++) {
RECT rect_1 = {i * 20 - 10, 20 * j - 10, 20 * i + 10, 20 * j + 10};
if (PtInRect(&rect_1, pre_x, pre_y) && chess[i - 1][j - 1] == 0) {
hdc = GetClientDC(hWnd);
//黑白交替
if (color == 1) {
SetBrushColor(hdc, COLOR_black);
chess[i - 1][j - 1] = 1;
colors = 1;//黑色圆标记
color = 0;
} else {
SetBrushColor(hdc, PIXEL_lightwhite);
chess[i - 1][j - 1] = 2;
colors = 2;//白色圆标记
color = 1;
}
FillCircle(hdc, 20 * i, 20 * j, 10);
BitBlt(hdc, 0, 0, 20, 20, hdc, 0, 0, 0);//颜色数据的位块传输
ReleaseDC(hdc);
break;
}
}
}
break;
case MSG_PAINT:
hdc = BeginPaint (hWnd);
FillBoxWithBitmap (hdc, 0, 0, 560, 560, &pic);
for (i = 1; i <= 25; i++) {
for (j = 1; j <= 25; j++) {
MoveTo(hdc, 20, 20 * j);
LineTo(hdc, 500, 20 * j);
MoveTo(hdc, 20 * i, 20);
LineTo(hdc, 20 * i, 500);
//Rectangle(hdc,i*20-10,20*j-10,20*i+10,20*j+10);//矩形不必要画出
}
}
EndPaint (hWnd, hdc);
return 0;
case MSG_LBUTTONUP:
ReleaseCapture();
break;
case MSG_CLOSE:
DestroyAllControls (hWnd);
DestroyMainWindow (hWnd);
PostQuitMessage (hWnd);
return 0;
}
return DefaultMainWinProc (hWnd, message, wParam, lParam);
}
int MiniGUIMain (int argc, const char* argv[]) {
MSG Msg;
HWND hMainWnd;
MAINWINCREATE CreateInfo;
#ifdef _LITE_VERSION
SetDesktopRect(0, 0, 800, 600);
#endif
CreateInfo.dwStyle = WS_VISIBLE | WS_BORDER | WS_CAPTION;
CreateInfo.dwExStyle = WS_EX_NONE;
CreateInfo.spCaption = "HelloWorld";
CreateInfo.hMenu =0;
CreateInfo.hCursor = GetSystemCursor(0);
CreateInfo.hIcon = 0;
CreateInfo.MainWindowProc = HelloWinProc;
CreateInfo.lx = 0;
CreateInfo.ty = 0;
CreateInfo.rx = 600;
CreateInfo.by = 600;
CreateInfo.iBkColor = COLOR_lightwhite;
CreateInfo.dwAddData = 0;
CreateInfo.hHosting = HWND_DESKTOP;
hMainWnd = CreateMainWindow (&CreateInfo);
if (hMainWnd == HWND_INVALID)
return -1;
ShowWindow(hMainWnd, SW_SHOWNORMAL);
while (GetMessage(&Msg, hMainWnd)) {
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
MainWindowThreadCleanup (hMainWnd);
UnloadBitmap(&pic);
return 0;
}
#ifndef _LITE_VERSION
#include <minigui/dti.c>
#endif
5、判断输赢
char strs[2][25] = {{"Black chess wins"}, {"White chess wins"}};
int level, Vertical, Left_oblique, Right_oblique;
void jude (HWND hWnd,int i,int j)
{
int k;
int sign[16]={0};
level = 0;
Vertical = 0;
Left_oblique = 0;
Right_oblique = 0;
//遍历棋子8个方向是否满足5子连线
for (k = 1; k <= 4; k++) {
//左上
if (chess[i - k - 1][j - k - 1] ==colors && sign[0]==0) {
Right_oblique += chess[i - k - 1][j - k - 1];
}
else
sign[0]=1;
//右下
if (chess[i + k - 1][j + k - 1] ==colors && sign[1]==0) {
Right_oblique += chess[i + k - 1][j + k - 1];
}
else
sign[1]=1;
//左下
if (chess[i - k - 1][j + k - 1] ==colors && sign[2]==0) {
Left_oblique += chess[i - k - 1][j + k - 1];
}
else
sign[2]=1;
//右上
if (chess[i + k - 1][j - k - 1] ==colors && sign[3]==0) {
Left_oblique += chess[i + k - 1][j - k - 1];
}
else
sign[3]=1;
//水平左
if (chess[i - k - 1][j - 1] ==colors && sign[4]==0) {
level += chess[i - k - 1][j - 1];
}
else
sign[4]=1;
//水平右
if (chess[i + k - 1][j - 1] ==colors && sign[5]==0) {
level += chess[i + k - 1][j - 1];
}
else
sign[5]=1;
//竖直下
if (chess[i - 1][j + k - 1] ==colors && sign[6]==0) {
Vertical += chess[i - 1][j + k - 1];
}
else
sign[6]=1;
//竖直上
if (chess[i - 1][j - k - 1] ==colors && sign[7]==0) {
Vertical += chess[i - 1][j - k - 1];
}
else
sign[7]=1;
if (level +colors == 5 || Vertical +colors == 5 || Left_oblique +colors == 5 || Right_oblique +colors == 5) {
MessageBox (hWnd, strs[0], "", MB_OK | MB_ICONINFORMATION);
InvalidateRect(hWnd, NULL, TRUE);//更新区域
memset(chess, 0, sizeof(chess));
color = 1;
break;
}
else if (level +colors == 10 || Vertical +colors == 10 || Left_oblique +colors == 10 || Right_oblique +colors == 10) {
MessageBox (hWnd, strs[1], "", MB_OK | MB_ICONINFORMATION);
InvalidateRect(hWnd, NULL, TRUE);//更新区域
memset(chess, 0, sizeof(chess));
color = 1;
break;
}
}
}
6、设置菜单:包含重新开始,悔棋,白棋先手,黑棋先手
static HMENU createpmenufile (void)//子菜单
{
HMENU hmnu;
MENUITEMINFO mii;
memset (&mii, 0, sizeof(MENUITEMINFO));
mii.type = MFT_STRING;
mii.id =IDM_FILE;
mii.typedata = (DWORD)"game";
hmnu = CreatePopupMenu(&mii);
memset (&mii, 0, sizeof(MENUITEMINFO));
mii.type = MFT_STRING;
mii.state = 0;
mii.id =IDM_RE;
mii.typedata = (DWORD)"restart";
InsertMenuItem(hmnu, 0, TRUE, &mii);
memset (&mii, 0, sizeof(MENUITEMINFO));
mii.type = MFT_STRING;
mii.state = 0;
mii.id = IDM_RT;
mii.typedata = (DWORD)"Repentance";
InsertMenuItem(hmnu, 1, TRUE, &mii);
mii.type = MFT_STRING;
mii.state = 0;
mii.id = IDM_BCF;
mii.typedata = (DWORD)"Black chess forerunner";
InsertMenuItem(hmnu, 2, TRUE, &mii);
mii.type = MFT_STRING;
mii.state = 0;
mii.id = IDM_WCF;
mii.typedata = (DWORD)"white chess forerunner";
InsertMenuItem(hmnu, 3, TRUE, &mii);
return hmnu;
}
static HMENU createmenu(void)//主菜单
{
HMENU hmnu;
MENUITEMINFO mii;
hmnu = CreateMenu();
memset (&mii, 0, sizeof(MENUITEMINFO));
mii.type = MFT_STRING;
mii.id =IDM_FILE;
mii.typedata = (DWORD)"game";
mii.hsubmenu = createpmenufile ();
InsertMenuItem(hmnu, 0, TRUE, &mii);
return hmnu;
}
case MSG_COMMAND:
switch (wParam) {
case IDM_RE:
InvalidateRect(hWnd, NULL, TRUE);//更新区域
memset(chess, 0, sizeof(chess));
break;
case IDM_RT:
if(m>=0){
chess[chess_sign[m][0]][chess_sign[m][1]]=0;
color=chess_sign[m][2];
m=m-1;
}
InvalidateRect(hWnd, NULL, TRUE);//更新区域
break;
case IDM_BCF:
color=1;
break;
case IDM_WCF:
color=0;
break;
};
//刷新棋盘
void Repentance(HWND hWnd)
{
int i,j;
for(i=0;i<25;i++){
for(j=0;j<25;j++){
if(chess[i][j]==1){
hdc = GetClientDC(hWnd);
SetBrushColor(hdc, COLOR_black);//设置画笔
FillCircle(hdc, 20 *(i+1),20 *(j+1), 10);//画圆
BitBlt(hdc, 0, 0, 20, 20, hdc, 0, 0, 0);//该函数响应于从指定的源设备上下文hsdc到目标设备上下文hddc的像素矩形,执行颜色数据的位块传输。
ReleaseDC(hdc);
}
if(chess[i][j]==2){
hdc = GetClientDC(hWnd);
SetBrushColor(hdc, COLOR_lightwhite);
FillCircle(hdc, 20 *(i+1), 20 *(j+1), 10);
BitBlt(hdc, 0, 0, 20, 20, hdc, 0, 0, 0);
ReleaseDC(hdc);
}
}
}
}
7、最终代码:
#include <stdio.h>
#include <minigui/common.h>
#include <minigui/minigui.h>
#include <minigui/gdi.h>
#include <minigui/window.h>
#include <minigui/control.h>
#include <string.h>
#define IDM_RE 1010
#define IDM_BCF 1011
#define IDM_WCF 1012
#define IDM_FILE 1013
#define IDM_RT 1014
int colors,color = 1;//颜色记录
static BITMAP pic;
static char str[25];
char strs[2][25] = {{"Black chess wins"}, {"White chess wins"}};//获胜消息
HDC hdc;
static int pre_x, pre_y;//坐标
int chess[25][25] = {{0}};//棋盘
int chess_sign[625][3];//所下的每个棋的信息
int m=-1;//记录悔棋次数
int level, Vertical, Left_oblique, Right_oblique;//4种方式计数
//判断输赢
void jude (HWND hWnd,int i,int j)
{
int k;
int sign[16]={0};
level = 0;
Vertical = 0;
Left_oblique = 0;
Right_oblique = 0;
for (k = 1; k <= 4; k++) {
if (chess[i - k - 1][j - k - 1] ==colors && sign[0]==0) {
Right_oblique += chess[i - k - 1][j - k - 1];
}
else
sign[0]=1;
if (chess[i + k - 1][j + k - 1] ==colors && sign[1]==0) {
Right_oblique += chess[i + k - 1][j + k - 1];
}
else
sign[1]=1;
if (chess[i - k - 1][j + k - 1] ==colors && sign[2]==0) {
Left_oblique += chess[i - k - 1][j + k - 1];
}
else
sign[2]=1;
if (chess[i + k - 1][j - k - 1] ==colors && sign[3]==0) {
Left_oblique += chess[i + k - 1][j - k - 1];
}
else
sign[3]=1;
if (chess[i - k - 1][j - 1] ==colors && sign[4]==0) {
level += chess[i - k - 1][j - 1];
}
else
sign[4]=1;
if (chess[i + k - 1][j - 1] ==colors && sign[5]==0) {
level += chess[i + k - 1][j - 1];
}
else
sign[5]=1;
if (chess[i - 1][j + k - 1] ==colors && sign[6]==0) {
Vertical += chess[i - 1][j + k - 1];
}
else
sign[6]=1;
if (chess[i - 1][j - k - 1] ==colors && sign[7]==0) {
Vertical += chess[i - 1][j - k - 1];
}
else
sign[7]=1;
if (level +colors == 5 || Vertical +colors == 5 || Left_oblique +colors == 5 || Right_oblique +colors == 5) {
MessageBox (hWnd, strs[0], "", MB_OK | MB_ICONINFORMATION);
//InvalidateRect(hWnd, NULL, TRUE);
//memset(chess, 0, sizeof(chess));
color = 1;
break;
}
else if (level +colors == 10 || Vertical +colors == 10 || Left_oblique +colors == 10 || Right_oblique +colors == 10) {
MessageBox (hWnd, strs[1], "", MB_OK | MB_ICONINFORMATION);
//InvalidateRect(hWnd, NULL, TRUE);
//memset(chess, 0, sizeof(chess));
color = 1;
break;
}
}
}
//刷新棋盘
void Repentance(HWND hWnd)
{
int i,j;
for(i=0;i<25;i++){
for(j=0;j<25;j++){
if(chess[i][j]==1){
hdc = GetClientDC(hWnd);
SetBrushColor(hdc, COLOR_black);
FillCircle(hdc, 20 *(i+1),20 *(j+1), 10);
BitBlt(hdc, 0, 0, 20, 20, hdc, 0, 0, 0);
ReleaseDC(hdc);
}
if(chess[i][j]==2){
hdc = GetClientDC(hWnd);
SetBrushColor(hdc, COLOR_lightwhite);
FillCircle(hdc, 20 *(i+1), 20 *(j+1), 10);
BitBlt(hdc, 0, 0, 20, 20, hdc, 0, 0, 0);
ReleaseDC(hdc);
}
}
}
}
//子菜单
static HMENU createpmenufile (void)
{
HMENU hmnu;
MENUITEMINFO mii;
memset (&mii, 0, sizeof(MENUITEMINFO));
mii.type = MFT_STRING;
mii.id =IDM_FILE;
mii.typedata = (DWORD)"game";
hmnu = CreatePopupMenu(&mii);
memset (&mii, 0, sizeof(MENUITEMINFO));
mii.type = MFT_STRING;
mii.state = 0;
mii.id =IDM_RE;
mii.typedata = (DWORD)"restart";
InsertMenuItem(hmnu, 0, TRUE, &mii);
memset (&mii, 0, sizeof(MENUITEMINFO));
mii.type = MFT_STRING;
mii.state = 0;
mii.id = IDM_RT;
mii.typedata = (DWORD)"Repentance";
InsertMenuItem(hmnu, 1, TRUE, &mii);
mii.type = MFT_STRING;
mii.state = 0;
mii.id = IDM_BCF;
mii.typedata = (DWORD)"Black chess forerunner";
InsertMenuItem(hmnu, 2, TRUE, &mii);
mii.type = MFT_STRING;
mii.state = 0;
mii.id = IDM_WCF;
mii.typedata = (DWORD)"white chess forerunner";
InsertMenuItem(hmnu, 3, TRUE, &mii);
return hmnu;
}
//主菜单
static HMENU createmenu(void)
{
HMENU hmnu;
MENUITEMINFO mii;
hmnu = CreateMenu();
memset (&mii, 0, sizeof(MENUITEMINFO));
mii.type = MFT_STRING;
mii.id =IDM_FILE;
mii.typedata = (DWORD)"game";
mii.hsubmenu = createpmenufile ();
InsertMenuItem(hmnu, 0, TRUE, &mii);
return hmnu;
}
static int HelloWinProc(HWND hWnd, int message, WPARAM wParam, LPARAM lParam) {
int i, j;
LoadBitmap (HDC_SCREEN, &pic, "2.bmp");//加载位图
switch (message) {
case MSG_LBUTTONDOWN:
SetCapture(hWnd);
pre_x = LOWORD (lParam);
pre_y = HIWORD (lParam);
//sprintf(str,"%d,%d ",pre_x,pre_y);
//TextOut (hdc, 500, 500,str);
//MessageBox (hWnd, str, "place:", MB_OK | MB_ICONINFORMATION);
for (i = 1; i <= 25; i++) {
for (j = 1; j <= 25; j++) {
RECT rect_1 = {i * 20 - 10, 20 * j - 10, 20 * i + 10, 20 * j + 10};
if (PtInRect(&rect_1, pre_x, pre_y) && chess[i - 1][j - 1] == 0) {
m+=1;
chess_sign[m][0]=i-1;
chess_sign[m][1]=j-1;
chess_sign[m][2]=color;
hdc = GetClientDC(hWnd);
if (color == 1) {
SetBrushColor(hdc, COLOR_black);
chess[i - 1][j - 1] = 1;
colors = 1;
color = 0;
} else {
SetBrushColor(hdc, PIXEL_lightwhite);
chess[i - 1][j - 1] = 2;
colors = 2;
color = 1;
}
FillCircle(hdc, 20 * i, 20 * j, 10);
BitBlt(hdc, 0, 0, 20, 20, hdc, 0, 0, 0);//颜色数据的位块传输
ReleaseDC(hdc);
jude(hWnd,i,j);
break;
}
}
}
break;
case MSG_COMMAND:
switch (wParam) {
case IDM_RE://重新开始
InvalidateRect(hWnd, NULL, TRUE);
memset(chess, 0, sizeof(chess));
color=1;
break;
case IDM_RT://悔棋
if(m>=0){
chess[chess_sign[m][0]][chess_sign[m][1]]=0;
color=chess_sign[m][2];
m=m-1;
}
InvalidateRect(hWnd, NULL, TRUE);
break;
case IDM_BCF://黑棋先手
color=1;
break;
case IDM_WCF://白棋先手
color=0;
break;
};
case MSG_PAINT:
hdc = BeginPaint (hWnd);
FillBoxWithBitmap (hdc, 0, 0, 560, 560, &pic);//设置背景
for (i = 1; i <= 25; i++) {
for (j = 1; j <= 25; j++) {
MoveTo(hdc, 20, 20 * j);
LineTo(hdc, 520, 20 * j);
MoveTo(hdc, 20 * i, 20);
LineTo(hdc, 20 * i, 520);
//Rectangle(hdc,i*20-10,20*j-10,20*i+10,20*j+10);
}
}
EndPaint (hWnd, hdc);
Repentance(hWnd);//刷新显示棋盘
return 0;
case MSG_LBUTTONUP:
ReleaseCapture();
break;
case MSG_CLOSE:
DestroyAllControls (hWnd);
DestroyMainWindow (hWnd);
PostQuitMessage (hWnd);
return 0;
}
return DefaultMainWinProc (hWnd, message, wParam, lParam);
}
int MiniGUIMain (int argc, const char* argv[]) {
MSG Msg;
HWND hMainWnd;
MAINWINCREATE CreateInfo;
#ifdef _LITE_VERSION
SetDesktopRect(0, 0, 800, 600);
#endif
CreateInfo.dwStyle = WS_VISIBLE | WS_BORDER | WS_CAPTION;
CreateInfo.dwExStyle = WS_EX_NONE;
CreateInfo.spCaption = "HelloWorld";
CreateInfo.hMenu =createmenu();//创建菜单,不能为0
CreateInfo.hCursor = GetSystemCursor(0);
CreateInfo.hIcon = 0;
CreateInfo.MainWindowProc = HelloWinProc;
CreateInfo.lx = 0;
CreateInfo.ty = 0;
CreateInfo.rx = 560;
CreateInfo.by = 560;
CreateInfo.iBkColor = COLOR_lightwhite;
CreateInfo.dwAddData = 0;
CreateInfo.hHosting = HWND_DESKTOP;
hMainWnd = CreateMainWindow (&CreateInfo);
if (hMainWnd == HWND_INVALID)
return -1;
ShowWindow(hMainWnd, SW_SHOWNORMAL);
while (GetMessage(&Msg, hMainWnd)) {
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
MainWindowThreadCleanup (hMainWnd);
UnloadBitmap(&pic);//此函数用于卸载指定的位图
return 0;
}
#ifndef _LITE_VERSION
#include <minigui/dti.c>
#endif