Home > Back-end >  The first time to learn the win32 programming, did the individual on white fast semi-finished produc
The first time to learn the win32 programming, did the individual on white fast semi-finished produc

Time:10-07

Code like this:

#include
# include

Declare Windows procedure/* */
LRESULT a CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);

/* Make the class name into a global variable */
Char szClassName []="CodeBlocksWindowsApp";

Int blocks [5] [4]={0};//screen display only 4 line 4 columns, blocks [0] this line drawing on the screen above the

Int cxClient cyClient;

Int block_width;

Int a mutex.//offset

Void init () {

For (int I=0; I & lt; 4. I++) {

Blocks [I] [4] rand () %=1;

}
}

Int WINAPI WinMain (HINSTANCE hThisInstance,
HINSTANCE hPrevInstance,
LPSTR lpszArgument,
Int nCmdShow)
{

The init ();
The HWND HWND;/* This is the handle for our window */
MSG messages;/* Here messages to the application are saved */
Modifed WNDCLASSEX wincl;/* Data structure for the windowclass */

/* The Window structure */
Wincl. HInstance=hThisInstance;
Wincl. LpszClassName=szClassName;
Wincl. LpfnWndProc=WindowProcedure;/* This function is called by Windows */
Wincl. Style=CS_VREDRAW | CS_HREDRAW;/* Catch double - on */
Wincl. CbSize=sizeof (modifed WNDCLASSEX);

/* Use the default icon and the mouse pointer */
Wincl. HIcon=LoadIcon (NULL, IDI_APPLICATION);
Wincl. HIconSm=LoadIcon (NULL, IDI_APPLICATION);
Wincl. HCursor=LoadCursor (NULL, IDC_ARROW);
Wincl. LpszMenuName=NULL;/* No menu */
Wincl. CbClsExtra=0;/* No extra bytes after the window class */
Wincl. CbWndExtra=0;/* structure or the window instance */
/* Use Windows' s default see colour as the background of the window */
Wincl. HbrBackground=(HBRUSH) GetStockObject (WHITE_BRUSH);

/* Register the window class, and if it fails to quit the program */
if (! RegisterClassEx (& amp; Wincl))
return 0;

/* The class is registered, let 's create The program */
HWND=CreateWindowEx (
0,/* Extended possibilites for variation */
SzClassName, Classname/* */
"Don't step on white PC quickly,"/* the Title Text */
WS_OVERLAPPEDWINDOW,/* the default Windows */
CW_USEDEFAULT,/* Windows decides the position */
CW_USEDEFAULT,/* where the window ends up on the screen */
544,/* The designed width */
375,/* and height in pixels */
HWND_DESKTOP,/* The window to The desktop window is a child - */
NULL, No menu/* */
HThisInstance,/* Program Instance handler */
NULL Window Creation/* No data */
);

/* Make the window visible on the screen */
ShowWindow (HWND, nCmdShow);

/* Run the message loop, It will Run until GetMessage () returns 0 */
While (GetMessage (& amp; Messages, NULL, 0, 0))
{
/* Translate the virtual - key messages into character messages */
TranslateMessage (& amp; Messages);
/* the Send message to WindowProcedure */
DispatchMessage (& amp; Messages);
}

/* The program return - The value is 0 - The value that PostQuitMessage () gave, */
Return messages. WParam;
}


Void onPaint (HDC HDC) {//not dealing with HDC destruction

SelectObject (HDC, GetStockObject (BLACK_PEN));

For (int I=0; I & lt; 4. I + +)
{
//horizontal lines
MoveToEx (HDC, 0, (cyClient/4 * I + mutex) % cyClient, NULL);
The LineTo (HDC, cxClient, (cyClient/4 * I + mutex) % cyClient);

//vertical lines
MoveToEx (HDC, cxClient (I + 1)/4 * and 0, NULL);
LineTo (HDC, cxClient (I + 1)/4 * and cyClient);

}

For (int I=1; I & lt; 4. I++)
{
For (int j=0; J & lt; 4. J++)
{

If (blocks [j] [I + 1]==1) {

SelectObject (HDC, GetStockObject (BLACK_BRUSH));

A Rectangle (HDC, cxClient/4 * j, (cyClient/4 * I + mutex) % cyClient, cxClient/4 * (j + 1), (cyClient/4 * I + mutex) % cyClient + block_width);
}
}
}
}


/* This function is called by the Windows function DispatchMessage () */

LRESULT a CALLBACK WindowProcedure (HWND HWND, UINT message, WPARAM WPARAM, LPARAM LPARAM)
{

HDC HDC.
HDC hdcMen;
PAINTSTRUCT ps;
HBITMAP HBITMAP;

The switch (the message)/* handle the messages */
{
Case WM_CREATE message handler:
The SetTimer (HWND, 1, 50, NULL);
return 0;
Case WM_TIMER:
Mutex +=5;
If (mutex & gt;=block_width)//one case was completely mobile in the bottom of the screen, at this moment, the mutex set to 0, and will move forward an array by the values
{
Mutex=0;

For (int I=4; i> 0; I -)
For (int j=0; J<4. J++)
Blocks [I] [j]=blocks [I - 1) [j];
for(int j=0; J<4. J++)
Blocks [0] [j]=0;
Blocks [0] [4] rand () %=1;//blocks [0] [N] this line is drawn in from one place on the screen
}
The InvalidateRect (HWND, NULL, TRUE);
return 0;
Case WM_SIZE:
Mutex=0;
CxClient=LOWORD (lParam);
CyClient=HIWORD (lParam);
Block_width=cyClient/4;
The InvalidateRect (HWND, NULL, TRUE); nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related