#include <windows.h> // 質溺億雛瘩� 筏萄�鋼蒐 � 縯璀麋�憂 API
#include <stdlib.h>
#include <time.h>
#include <vector>
#include "resource.h"
// �螂畫贛� 髡�暴:
HINSTANCE hInst; //丹縈撿養褒 頜蝶擋憂
LPCTSTR szWindowClass = "QWERTY";
LPCTSTR szTitle = "芬奎� 表注咽味";
// 俠閱擇準� 複撇 縯璀麋�
HANDLE event;
ATOM MyRegisterClass(HINSTANCE hInstance);
BOOL InitInstance(HINSTANCE, int);
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
// 狐瘟隅� 頜蝶擋影
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine,
int nCmdShow)
{
MSG msg;
// 姻�隧皖�� 蓊痘� 貳蜜�
MyRegisterClass(hInstance);
// 殃隆擇瘩� 貳蜜� 頜蝶擋憂
if (!InitInstance(hInstance, nCmdShow))
{
return FALSE;
}
// 疾蓊 螂曉萎� 頡貳溜慫粵�
while (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
ATOM MyRegisterClass(HINSTANCE hInstance)
{
WNDCLASSEX wcex;
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.style = CS_HREDRAW | CS_VREDRAW; //羲慣� 貳蜜�
wcex.lpfnWndProc = (WNDPROC)WndProc; //貳蜻瘩� 頜談窟曖�
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = hInstance; //滇縈撿養褒 頜蝶擋憂
wcex.hIcon = LoadIcon(NULL, IDI_HAND); //閎鳩皓粵�� �衝蒐
wcex.hCursor = LoadCursor(NULL, IDC_ARROW); //閎鳩皓粵�� 蝕曇褒�
wcex.hbrBackground = GetSysColorBrush(COLOR_WINDOW); //檀錶瘟階� 縴皚
wcex.lpszMenuName = MAKEINTRESOURCE(IDR_MENU1);
wcex.lpszClassName = szWindowClass; //��� 蓊痘�
wcex.hIconSm = NULL;
return RegisterClassEx(&wcex); //擇�隧皖�� 蓊痘� 貳蜜�
}
// FUNCTION: InitInstance (HANDLE, int)
// 殃隆橇� 貳蜜� 頜蝶擋憂 � 頓綑�湮 滇縈撿養褒 頜蝶擋憂 � 髡�暴� hInst
HWND hWnd;
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
hInst = hInstance; //頓綑�湮 滇縈撿養褒 溜滓錦� � 髡�暴� hInst
hWnd = CreateWindow(szWindowClass, // ��� 蓊痘� 貳蜜�
szTitle, // 熱頊� 頜蝶擋憂
WS_OVERLAPPEDWINDOW, // 羲慣� 貳蜜�
CW_USEDEFAULT, // 頡餃詭瘩� 頡 �
CW_USEDEFAULT, // 頡餃詭瘩� 頡 Y
CW_USEDEFAULT, // 曉髡� 頡 �
CW_USEDEFAULT, // 曉髡� 頡 Y
NULL, // 滇縈撿養褒 菴靦粽隄讒蝶� 貳蜜�
NULL, // 滇縈撿養褒 慮磊 貳蜜�
hInstance, // 滇縈撿養褒 頜蝶擋憂
NULL); // 鋒擋慮隧� 羲隆擇瘩�.
if (!hWnd) //棠攘 貳蜜� 獗 錳褒慣褓�, 縯璀麋� 頡閑暸湮 FALSE
{
return FALSE;
}
ShowWindow(hWnd, nCmdShow); //俠蒙頑錚 貳蜜�
UpdateWindow(hWnd); //狀蝴摘� 貳蜜�
return TRUE;
}
// FUNCTION: WndProc (HWND, unsigned, WORD, LONG)
// ␒蜻瘩� 頜談窟曖�. 俏慷影� � 螂曉萄�� 隄� 頡貳溜慫粵��, 攘 頜摸蝠�靦 � 溜滓錙�
RECT rc; // 螂閤羲�
STARTUPINFO si;
PROCESS_INFORMATION pi;
DWORD lp;
bool isProcess = false;
DWORD WINAPI ThreadG(LPVOID lpParam)
{
srand(time(NULL));
INT sl = 45; // 縈褒褓靦 滂慇檗稞褓� ��闐(鋒擰� 溫� 頡錙蒙 15憬 = 1 蒲痢�)
HDC hdc;
GetClientRect(hWnd, &rc);
CONST INT width = 100, height = 100; // 擋髡綑� ��闐
POINT xyPoint; // 擋縉蝓蝸粵徹
HBRUSH hbr1, hbr2; // 頑鞅階�
HPEN hPen1, hPen2;
BOOL flagPush, flagGV; // 熱頜琵雒璃� 滂慇粵��
INT xRegion = rc.right - width; // GetSystemMetrics ( SM_CXFULLSCREEN )
INT yRegion = rc.bottom - height;
// 擋獎衛磋� 燾綏 ��闐
INT red = rand() % 256;
INT green = rand() % 256;
INT blue = rand() % 256;
// 熱闐鼻磋� 蜻褒溘熱靜 頡�隋粵�� ��闐
xyPoint.x = rand() % xRegion;
xyPoint.y = rand() % yRegion;
// 熱頜琵雒璃� 滂慇粵��
flagPush = 1;
flagGV = 1;
hdc = GetDC(hWnd);
hbr1 = CreateSolidBrush(RGB(red, green, blue));
hbr2 = CreateSolidBrush(RGB(255, 255, 255));
hPen1 = CreatePen(BS_SOLID, 1, RGB(0, 0, 0));
hPen2 = CreatePen(BS_SOLID, 1, RGB(255, 255, 255));
while (true)
{
SelectObject(hdc, hbr1);
SelectObject(hdc, hPen1);
Ellipse(hdc, xyPoint.x, xyPoint.y, xyPoint.x + width, xyPoint.y + height);
Sleep(sl);
SelectObject(hdc, hbr2);
SelectObject(hdc, hPen2);
Ellipse(hdc, xyPoint.x, xyPoint.y, xyPoint.x + width, xyPoint.y + height);
// 愿慮獗璃� 熱頜琵雒璃� 滂慇粵��
if (flagGV)
{
if (!xyPoint.x) flagPush = TRUE;
else if (xyPoint.x == xRegion) flagPush = FALSE;
if (flagPush) xyPoint.x++;
else xyPoint.x--;
}
}
DeleteObject(hbr1);
DeleteObject(hPen1);
DeleteObject(hbr2);
DeleteObject(hPen2);
ReleaseDC(hWnd, hdc);
return 0;
}
DWORD WINAPI ThreadV(LPVOID lpParam)
{
srand(time(NULL));
INT sl = 105; // 縈褒褓靦 滂慇檗稞褓� ��闐(鋒擰� 溫� 頡錙蒙 15憬 = 1 蒲痢�)
HDC hdc;
GetClientRect(hWnd, &rc);
CONST INT width = 100, height = 100; // 擋髡綑� ��闐
POINT xyPoint; // 擋縉蝓蝸粵徹
HBRUSH hbr1, hbr2; // 頑鞅階�
HPEN hPen1, hPen2;
BOOL flagPush, flagGV; // 熱頜琵雒璃� 滂慇粵��
INT xRegion = rc.right - width; // GetSystemMetrics ( SM_CXFULLSCREEN )
INT yRegion = rc.bottom - height;
// 擋獎衛磋� 燾綏 ��闐
INT red = rand() % 256;
INT green = rand() % 256;
INT blue = rand() % 256;
// 熱闐鼻磋� 蜻褒溘熱靜 頡�隋粵�� ��闐
xyPoint.x = rand() % xRegion;
xyPoint.y = rand() % yRegion;
// 熱頜琵雒璃� 滂慇粵��
flagPush = 1;
flagGV = 1;
hdc = GetDC(hWnd);
hbr1 = CreateSolidBrush(RGB(red, green, blue));
hbr2 = CreateSolidBrush(RGB(255, 255, 255));
hPen1 = CreatePen(BS_SOLID, 1, RGB(0, 0, 0));
hPen2 = CreatePen(BS_SOLID, 1, RGB(255, 255, 255));
while (true)
{
SelectObject(hdc, hbr1);
SelectObject(hdc, hPen1);
Ellipse(hdc, xyPoint.x, xyPoint.y, xyPoint.x + width, xyPoint.y + height);
Sleep(sl);
SelectObject(hdc, hbr2);
SelectObject(hdc, hPen2);
Ellipse(hdc, xyPoint.x, xyPoint.y, xyPoint.x + width, xyPoint.y + height);
// 愿慮獗璃� 熱頜琵雒璃� 滂慇粵��
if (flagGV)
{
if (!xyPoint.y) flagPush = TRUE;
else if (xyPoint.y == yRegion) flagPush = FALSE;
if (flagPush) xyPoint.y++;
else xyPoint.y--;
}
}
DeleteObject(hbr1);
DeleteObject(hPen1);
DeleteObject(hbr2);
DeleteObject(hPen2);
ReleaseDC(hWnd, hdc);
return 0;
}
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
PAINTSTRUCT ps;
HDC hdc;
static std::vector < HANDLE > hPThread;
static std::vector < DWORD > dwPThreadId;
static UINT COUNT;
switch (message)
{
case WM_CREATE:
COUNT = 0;
break;
case WM_PAINT: //青擇影億鈇錚 貳蜜�
hdc = BeginPaint(hWnd, &ps); //俠闐錚 彙登�璃� 閎貳�
GetClientRect(hWnd, &rc); //泠閤羲� 貳蜜� 溫� 影億鈇瘩�
EndPaint(hWnd, &ps); //囝粽瞇摘� 彙登�璃� 閎貳�
break;
case WM_COMMAND:
switch (LOWORD(wParam))
{
case ID_40001:
hdc = GetDC(hWnd);
ZeroMemory(&si, sizeof(si));
si.cb = sizeof(si);
ZeroMemory(&pi, sizeof(pi));
if (!isProcess)
{
if (!CreateProcess(
TEXT("c:\\WINDOWS\\system32\\notepad.exe"),
NULL, NULL, NULL, FALSE, NULL, NULL, NULL, &si, &pi))
TextOut(hdc, 10, 10, "Process start failed!", 21);
isProcess = true;
}
else
MessageBox(hWnd, "丑璃� 頜談綁 間� 羲隆擇瘟", "", MB_OK);
ReleaseDC(hWnd, hdc);
break;
case ID_40002:
hdc = GetDC(hWnd);
if (!GetExitCodeProcess(pi.hProcess, (&lp)))
MessageBox(hWnd, "丑璃� 頜談綁 貳溪檔暴�. �煦 閤縈�, 頑餓羲�� 縉諄痞蝕 �� 擇滓蜘褒!", "", MB_OK);
else
{
TerminateProcess(pi.hProcess, NO_ERROR);
isProcess = false;
}
ReleaseDC(hWnd, hdc);
break;
case ID_40003:
TerminateProcess(pi.hProcess, NO_ERROR);
PostQuitMessage(0);
break;
case ID_40005:
hdc = GetDC(hWnd);
event = CreateEvent(NULL, TRUE, FALSE,"step");//縝頌琯� 縝裂錚� "event" � 樽顏籠 愿慮獗璃粳 (雁褒蝗 鋒擋慮隧)
//羲痙錙隆� 鳩皓粵徹 縝裂錚� event = FALSE
dwPThreadId.push_back(0);
ResetEvent(event);//篤擋興鈇粳 縝裂錚� � 0 蒙誅癮 擋�
hPThread.push_back(CreateThread(NULL, 0, ThreadG, &COUNT, 0, &dwPThrea