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