程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> C語言 >> 關於C語言 >> 掃雷游戲(純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
  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved