Mine game (pure C implementation) (iii)

Source: Internet
Author: User

Use WIN32API to connect to the window

First, I got a main window and didn't use MFC to call the API function implementation directly. Let's look at the code first:

///////////////////////////////////////
//
//Main function: mine clearance
//
///////////////////////////////////////

# Include<Windows. h>
# Include<Stdio. h>
# Include"DrawMap. h"// See the following
# Include"Def. h"

IntM= 10, N= 10;
IntMap [MAX_X] [MAX_Y];
IntGlobal_x [MAX_X], Global_y [MAX_Y];


Lresult callback WndProc (HWND, UINT, WPARAM, LPARAM );
Wingdiapi bool winapi MoveToEx (HDC hdc,IntX,IntY, LPPOINT lppt );//Move the position of the current paint brush
Wingdiapi bool winapi LineTo (HDC hdc,IntX,IntY );//Function used to draw a straight line
Wingdiapi hpen winapi CreatePen (IntIStyle,IntCWidth, COLORREF color );




IntWINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
PSTR szCmdLine,IntICmdShow)
{
Init ();//Initialize the Array (mine Distribution
IntX_position, y_position, x_size, y_size;
Set_position_size (&X_position,&Y_position,&X_size,&Y_size );

StaticTCHAR 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 ("Clearance Game-The ClearMines Game"),//Window caption
WS_OVERLAPPED|
WS_CAPTION|
WS_SYSMENU|
WS_MINIMIZEBOX,//Window style
X_position,//Initial x position
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.