Wuziqi (API writing)

Source: Internet
Author: User
Tags return tag

# Include <windows. h>
# Include <iostream>
# Include <TCHAR. h>
# Include <stdio. h>
# Include <afxres. h>
Using namespace std;
TCHAR character [] = TEXT ("My checkers program ");
Static int shuzu [20] [20];
Bool tagx = false ;//

Static int ix, iy; // determines the selected grid;

Bool is_win () // This function is used to determine if it has won
{
Bool tag = false;
Static int;
A = shuzu [ix] [iy];
Static int I, j;

Static int count;
Count = 0;

For (I = ix; I >= ix-4 & I> = 0; -- I) // check left and right
{
If (shuzu [I] [iy] =)
++ Count;
Else
Break;
}

If (count> = 5)
Return true;

For (I = ix; I <= ix + 4 & I <20; ++ I)
{
If (shuzu [I] [iy] = a) // note that here ix, iy is calculated twice.
++ Count;
Else
Break;
}

If (count> 5)
Return true;

Count = 0; // count multiple zeros;

For (j = iy; j> = iy-4 & j> = 0; -- j) // check up and down
{
If (shuzu [ix] [j] =)
++ Count;
Else
Break;
}

If (count> = 5)
Return true;

For (j = iy; j <= iy + 4 & j <20; ++ j)
{
If (shuzu [ix] [j] =)
++ Count;
Else
Break;
}

If (count> 5)
Return true;

Count = 0; // count all 0
For (I = ix, j = iy; I> = ix-4 & j> = iy-4 & I> = 0 & j> = 0; -- I, -- j) // check the right slash
{
If (shuzu [I] [j] =)
++ Count;
Else
Break;
}
If (count> = 5)
Return true;

For (I = ix, j = iy; I <= ix + 4 & j <= iy + 4 & I <20 & j <20; ++ I, ++ j)
{

If (shuzu [I] [j] =)
++ Count;
Else
Break;
}
If (count> 5)
Return true;

Count = 0; // count all 0
For (I = ix, j = iy; I> = ix-4 & I> = 0 & j <= iy + 4 & j <20; -- I, + + j) // check the left slash
{
If (shuzu [I] [j] =)
++ Count;
Else
Break;
}
If (count> = 5)
Return true;

For (I = ix, j = iy; I <= ix + 4 & j> = iy-4 & I <20 & j> = 0; ++ I, -- j)
{
If (shuzu [I] [j] =)
++ Count;
Else
Break;
}

If (count> 5)
Return true;

Return tag;

}

Lresult callback myownproc (HWND, UINT, WPARAM, LPARAM); // declare the window Handler
Int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpComLine, int nShowCmd)
{

MSG msg; // define your own message body
WNDCLASS myownclass; // defines its own window category
HWND hwnd; // window handle

// Design your own window category first
Myownclass. style = CS_HREDRAW | CS_VREDRAW;
Myownclass. lpszMenuName = NULL;
Myownclass. lpszClassName = callback; // window class name
Myownclass. lpfnWndProc = myownproc; // processing function of the window class
Myownclass. hInstance = hInstance; // The first parameter passed in using the WinMain Function
Myownclass. hIcon = LoadIcon (NULL, IDI_APPLICATION );
Myownclass. hCursor = LoadCursor (NULL, IDC_ARROW );
Myownclass. hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH); // the background color is white.
Myownclass. cbClsExtra = 0; // set the extra space to 0.
Myownclass. cbWndExtra = 0; // set the extra space to 0.
// The following registration window class

/* For (int s = 0; s <20; s ++) // initialize the Array
{
For (int k = 0; k <20; k ++)
Shuzu [s] [k] = 0;
}
*/

If (! RegisterClass (& myownclass ))
{
MessageBox (NULL, TEXT ("registration window class failed"), success, 0 );
Return 0;
}

// Create a window below
Hwnd = createwindow (rows, rows, ws_overlappedwindow, cw_usedefault, null, null, hinstance, null );
 
// The Window shown below
Showwindow (hwnd, nshowcmd );
Updatewindow (hwnd );

// Perform the following message loop

While (getmessage (& MSG, null, 0, 0 ))
{
Translatemessage (& MSG );
Dispatchmessage (& MSG );
}

Return msg. wparam;
} // The End Of The winmain Function

 

// Window processing function definition
Lresult callback myownproc (hwnd, uint message, wparam, lparam)
{
HDC; // device content handle
Paintstruct pS; // the definition of the drawing struct
Rect; // defines a rectangular area.
Static HBITMAP hBitmap; // bitmap handle
Static int x, y; // used to draw a grid

Static int cxClient and cyClient; // used to obtain the size of the customer Zone
Static bool tag1 = false; // used to indicate whether the blue side has clicked the grid
Static bool tag2 = false; // used to indicate whether the Red Square has clicked the grid
Static bool tag3 = false; // used to take the next child in turn. false indicates that the next child is blue. Otherwise, the next child is red, and the first child is blue.

Static HPEN hpen; // paint brush handle 1
Static HPEN hpen2; // paint brush handle 2
Static HBRUSH hbrush; // specifies the paint brush handle.
Static HBRUSH hbrush2; // paint brush handle 2
// Self-processed message
Switch (message)
{
Case WM_SIZE:
CxClient = LOWORD (lParam );
CyClient = HIWORD (lParam );
Return 0;

Case WM_LBUTTONDOWN:
X = LOWORD (lParam); // cursor position
Y = hiword (lparam );
IX = x/60;
If (X % 60> = 30)
++ IX;
Iy = y/60;
If (Y % 60> = 30)
++ Iy;
If (tag3 = false)
{
Tag1 = true;
Invalidaterect (hwnd, null, false); // invalidates the customer zone. The last parameter is false, so that the original values remain unchanged.
}
Return 0;

Case wm_rbuttondown:
X = loword (lparam); // cursor position
Y = hiword (lparam );
IX = x/60;
If (X % 60> = 30)
++ IX;
Iy = y/60;
If (Y % 60> = 30)
++ Iy;
If (tag3 = true)
{
Tag2 = true;
Invalidaterect (hwnd, null, false); // invalidates the customer zone. The last parameter is false, so that the original values remain unchanged.
}
Return 0;

Case wm_paint:
HDC = beginpaint (hwnd, & PS); // get the device content handle
Getclientrect (hwnd, & rect); // obtain the size of the customer Zone


For (x = 0; x <rect. Right; x + = 60) // draw a vertical line
{
Movetoex (HDC, X, 0, null );
Lineto (HDC, X, rect. Bottom );
}
For (y = 0; y <rect. Bottom; y + = 60) // draw a horizontal line
{
MoveToEx (hdc, 0, y, NULL );
LineTo (hdc, rect. right, y );
}

If (tag1 = true & shuzu [ix] [iy] = 0)
{
Hpen = CreatePen (PS_SOLID, 3, RGB (255,); // create a paint brush
SelectObject (hdc, hpen); // select the paint brush into the device content
Hbrush = CreateSolidBrush (RGB (0, 0, 255 ));
SelectObject (hdc, hbrush );
Ellipse (hdc, ix * 60-30, iy * 60-30, ix * 60 + 30, iy * 60 + 30 );
Tag1 = false;
Tag3 = true;
Shuzu [ix] [iy] = 1;
If (is_win ())
{
Tagx = true;
MessageBox (NULL, "Blue wins", success, 0 );
}
}

If (tag2 = true & shuzu [ix] [iy] = 0)
{
Hpen2 = CreatePen (PS_SOLID, 3, RGB (255, 0, 0); // create a paint brush
SelectObject (hdc, hpen2); // select the paint brush into the device content
Hbrush2 = CreateSolidBrush (RGB (255, 0, 0 ));
SelectObject (hdc, hbrush2 );
Ellipse (hdc, ix * 60-30, iy * 60-30, ix * 60 + 30, iy * 60 + 30 );
Tag2 = false;
Tag3 = false;
Shuzu [ix] [iy] = 2;
If (is_win ())
{
Tagx = true;
MessageBox (NULL, "Red wins", success, 0 );
}

}

Endpaint (hwnd, & PS );
Deleteobject (Hpen );
Deleteobject (hbrush );
Deleteobject (hpen2 );
Deleteobject (hbrush2 );

Return 0;
Case wm_destroy:
Postquitmessage (0 );
Return 0;

}

// The remaining messages are processed by the system by default.
Return defwindowproc (hwnd, message, wparam, lparam );
}

 

 

 

 

 

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.