使用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