📄 winmain.cpp
字号:
}
break;
case ID_OPTIONS_BASICEVADE:
BasicEvade = !BasicEvade;
state = BasicEvade ? MF_CHECKED:MF_UNCHECKED;
CheckMenuItem(GetMenu(hMainWindow), ID_OPTIONS_BASICEVADE, state);
if(BasicChase)
{
BasicChase = false;
CheckMenuItem(GetMenu(hMainWindow), ID_OPTIONS_BASICCHASE, MF_UNCHECKED);
}
break;
case ID_OPTIONS_INTERCEPT:
InterceptChase = !InterceptChase;
state = InterceptChase ? MF_CHECKED:MF_UNCHECKED;
CheckMenuItem(GetMenu(hMainWindow), ID_OPTIONS_INTERCEPT, state);
if(BasicEvade)
{
BasicEvade = false;
CheckMenuItem(GetMenu(hMainWindow), ID_OPTIONS_BASICEVADE, MF_UNCHECKED);
}
if(BasicChase)
{
BasicChase = false;
CheckMenuItem(GetMenu(hMainWindow), ID_OPTIONS_BASICCHASE, MF_UNCHECKED);
}
break;
case ID_OPTIONS_POTENTIALCHASE:
PotentialChase = !PotentialChase;
state = PotentialChase ? MF_CHECKED:MF_UNCHECKED;
CheckMenuItem(GetMenu(hMainWindow), ID_OPTIONS_POTENTIALCHASE, state);
if(BasicEvade)
{
BasicEvade = false;
CheckMenuItem(GetMenu(hMainWindow), ID_OPTIONS_BASICEVADE, MF_UNCHECKED);
}
break;
}
break;
case WM_DESTROY:
DeleteBackBuffer();
PostQuitMessage(0);
break;
case WM_KEYDOWN:
break;
case WM_PAINT:
pDC = BeginPaint(hMainWindow, (LPPAINTSTRUCT) &ps);
w = MainWindowRect.right - MainWindowRect.left;
h = MainWindowRect.bottom - MainWindowRect.top;
BitBlt(pDC, 0, 0, w, h, BackBufferDC, 0, 0, SRCCOPY);
EndPaint(hMainWindow, (LPPAINTSTRUCT) &ps);
return (0);
break;
default:
return (DefWindowProc(hWnd, message, wParam, lParam));
}
return (0);
}
void CopyBackBufferToWindow(void)
{
int w, h;
HDC dc;
dc = GetDC(hMainWindow);
w = MainWindowRect.right - MainWindowRect.left;
h = MainWindowRect.bottom - MainWindowRect.top;
BitBlt(dc, 0, 0, w, h, BackBufferDC, 0, 0, SRCCOPY);
DeleteDC(dc);
}
void ClearBackBuffer(void)
{
DrawRectangle(&MainWindowRect, 1, RGB(0,0,0), RGB(255, 255, 255));
}
void CreateBackBuffer(void)
{
HDC hdc = GetDC(hMainWindow);
BYTE *lpbits = NULL;
DWORD retval = 0;
BackBufferDC = CreateCompatibleDC(hdc);
lpBackBufferBitmapInfo = (LPBITMAPINFO) malloc(sizeof(BITMAPINFOHEADER));
lpBackBufferBitmapInfo->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
lpBackBufferBitmapInfo->bmiHeader.biWidth = MainWindowRect.right - MainWindowRect.left;
lpBackBufferBitmapInfo->bmiHeader.biHeight = MainWindowRect.bottom - MainWindowRect.top;
lpBackBufferBitmapInfo->bmiHeader.biPlanes = 1;
lpBackBufferBitmapInfo->bmiHeader.biBitCount = 24;
lpBackBufferBitmapInfo->bmiHeader.biCompression = BI_RGB;
lpBackBufferBitmapInfo->bmiHeader.biSizeImage = 0;
lpBackBufferBitmapInfo->bmiHeader.biXPelsPerMeter = 0;
lpBackBufferBitmapInfo->bmiHeader.biYPelsPerMeter = 0;
lpBackBufferBitmapInfo->bmiHeader.biClrUsed = 0;
lpBackBufferBitmapInfo->bmiHeader.biClrImportant = 0;
hBackBuffer = CreateDIBSection(BackBufferDC, lpBackBufferBitmapInfo, DIB_RGB_COLORS, (void **) &lpbits, NULL, 0);
SelectObject(BackBufferDC, (HBITMAP) hBackBuffer);
DrawRectangleToDC(BackBufferDC, &MainWindowRect, 4, RGB(0, 0, 0), RGB(255, 255, 255));
}
void DeleteBackBuffer(void)
{
DeleteDC(BackBufferDC);
DeleteObject(hBackBuffer);
free(lpBackBufferBitmapInfo);
}
//----------------------------------------------------------------------------------------------------//
// This function simply draws a solid line to the given device context, given the line
// start and end point, its thickness and its color.
//----------------------------------------------------------------------------------------------------//
void DrawLineToDC(HDC hdc, int h1, int v1, int h2, int v2, int thk, COLORREF clr)
//----------------------------------------------------------------------------------------------------//
{
HBRUSH CurrentBrush;
HBRUSH OldBrush;
HPEN CurrentPen;
HPEN OldPen;
COLORREF FColor = clr;
COLORREF BColor = RGB(0, 0, 0);
CurrentBrush = CreateSolidBrush(FColor);
OldBrush = (HBRUSH) SelectObject( hdc, CurrentBrush);
CurrentPen = CreatePen(PS_SOLID, thk, FColor);
OldPen = (HPEN) SelectObject(hdc, CurrentPen);
MoveToEx(hdc, h1, v1, NULL);
LineTo(hdc, h2, v2);
SelectObject(hdc, OldBrush);
SelectObject(hdc, OldPen);
DeleteObject(CurrentBrush);
DeleteObject(CurrentPen);
}
//----------------------------------------------------------------------------------------------------//
// This function simply draws a filled rectangle to the given device context, given the
// rectangle dimensions, its border thickness and its border color (the rectangle is filled
// in black).
//----------------------------------------------------------------------------------------------------//
void DrawRectangleToDC(HDC hdc, RECT *r, int thk, COLORREF borderCLR, COLORREF fillCLR)
{
HBRUSH CurrentBrush;
HBRUSH OldBrush;
HPEN CurrentPen;
HPEN OldPen;
COLORREF FColor = borderCLR;
COLORREF BColor = fillCLR;
CurrentBrush = CreateSolidBrush(BColor);
OldBrush = (HBRUSH) SelectObject( hdc, CurrentBrush);
CurrentPen = CreatePen(PS_SOLID, thk, FColor);
OldPen = (HPEN) SelectObject(hdc, CurrentPen);
Rectangle(hdc, r->left, r->top, r->right, r->bottom);
SelectObject(hdc, OldBrush);
SelectObject(hdc, OldPen);
DeleteObject(CurrentBrush);
DeleteObject(CurrentPen);
}
//----------------------------------------------------------------------------------------------------//
// This function simply draws a filled rectangle to the given device context, given the
// rectangle dimensions, its border thickness and its border color (the rectangle is filled
// in black).
//----------------------------------------------------------------------------------------------------//
void DrawEllipseToDC(HDC hdc, RECT *r, int thk, COLORREF clr)
{
HBRUSH CurrentBrush;
HBRUSH OldBrush;
HPEN CurrentPen;
HPEN OldPen;
COLORREF FColor = clr;
COLORREF BColor = RGB(0, 0, 0);
CurrentBrush = CreateSolidBrush(BColor);
OldBrush = (HBRUSH) SelectObject( hdc, CurrentBrush);
CurrentPen = CreatePen(PS_SOLID, thk, FColor);
OldPen = (HPEN) SelectObject(hdc, CurrentPen);
Ellipse(hdc, r->left, r->top, r->right, r->bottom);
SelectObject(hdc, OldBrush);
SelectObject(hdc, OldPen);
DeleteObject(CurrentBrush);
DeleteObject(CurrentPen);
}
//----------------------------------------------------------------------------------------------------//
// This function simply draws text to the given device context, given the text string
// and the x,y coordinates of its lower left corner, the number of characters in the string,
// and the desired point size.
//----------------------------------------------------------------------------------------------------//
void DrawStringToDC(HDC hdc, int x, int y, LPCSTR lpszString, int size, int ptsz)
{
COLORREF FColor = RGB(255, 255, 255);
COLORREF BColor = RGB(0, 0, 0);
HFONT hFont, hOldFont;
SetTextColor(hdc, FColor);
SetBkColor(hdc, BColor);
SetBkMode(hdc, TRANSPARENT);
SetTextAlign(hdc, TA_BOTTOM|TA_LEFT);
hFont = CreateFont(-ptsz, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, "MS Serif");
hOldFont = (HFONT) SelectObject(hdc, hFont);
TextOut(hdc, x, y, lpszString, size);
SelectObject(hdc, hOldFont);
DeleteObject(hFont);
}
//----------------------------------------------------------------------------------------------------//
// All of these function draw to the back buffer...
//----------------------------------------------------------------------------------------------------//
void DrawLine(int x1, int y1, int x2, int y2, int thk, COLORREF clr)
{
DrawLineToDC(BackBufferDC, x1, y1, x2, y2, thk, clr);
}
void DrawRectangle(RECT *r, int thk, COLORREF borderCLR, COLORREF fillCLR)
{
DrawRectangleToDC(BackBufferDC, r, thk, borderCLR, fillCLR);
}
void DrawEllipse(RECT *r, int thk, COLORREF clr)
{
DrawEllipseToDC(BackBufferDC, r, thk, clr);
}
BOOL IsKeyDown(short KeyCode)
{
SHORT retval;
retval = GetAsyncKeyState(KeyCode);
if (HIBYTE(retval))
return TRUE;
return FALSE;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -