当前位置:编程学习 > C/C++ >>

扫雷游戏(纯C实现)(三)

使用WIN32API连接窗口

首先,我弄个主窗口出来,没有用到MFC,直接调用API函数实现,先看看代码吧:

///////////////////////////////////////
//
//主函数:扫雷
//
///////////////////////////////////////

#include <windows.h>
#include <stdio.h>
#include "DrawMap.h"//见下文
#include "def.h"

int m = 10, n = 10;
int map[MAX_X][MAX_Y];
int Global_x[MAX_X], Global_y[MAX_Y];


LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ;
WINGDIAPI BOOL WINAPI MoveToEx(HDC hdc, int x, int y, LPPOINT lppt);
//移动当前画笔的位置
WINGDIAPI BOOL WINAPI LineTo(HDC hdc, int x, int y);//用来画直线的函数
WINGDIAPI HPEN WINAPI CreatePen(int iStyle, int cWidth, COLORREF color);




int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
PSTR szCmdLine, int iCmdShow)
{
init();//初始化数组(地雷分布
int x_position, y_position, x_size, y_size;
set_position_size(&x_position, &y_position, &x_size, &y_size);

static TCHAR szAppName[] = TEXT ("MainWin") ;
HWND hwnd ;
MSG msg ;
WNDCLASS wndclass ;

wndclass.style = CS_HREDRAW | CS_VREDRAW ;
wndclass.lpfnWndProc = WndProc ;
wndclass.cbClsExtra = 0 ;
wndclass.cbWndExtra = 0 ;
wndclass.hInstance = hInstance ;
wndclass.hIcon = LoadIcon (NULL, IDI_APPLICATION) ;
wndclass.hCursor = LoadCursor (NULL, IDC_ARROW) ;
wndclass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH) ;
wndclass.lpszMenuName = NULL ;
wndclass.lpszClassName = szAppName ;

if (!RegisterClass (&wndclass))
{
MessageBox (NULL, TEXT ("This program requires Windows NT!"),
szAppName, MB_ICONERROR) ;
return 0 ;
}

hwnd = CreateWindow (szAppName, // window class name
TEXT ("扫雷游戏——The ClearMines Game"), // window caption
WS_OVERLAPPED |
WS_CAPTION |
WS_SYSMENU |
WS_MINIMIZEBOX, // window style
x_position, // initial x position
补充:软件开发 , C语言 ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,