#include<iostream>
#include<windows.h>
#include<tchar.h>
#include<stdio.h>
#include <process.h>
#pragma warning(disable:4996)
VOID PrintUI(CONST CHAR* ExeName, CONST CHAR* UIName, CONST CHAR* color, SHORT X坐标, SHORT y坐标, WORD UIwide, WORD UIHigh)
{AllocConsole();freopen("conin$", "r+t", stdin);freopen("conout$", "w+t", stdout);SetConsoleTitleA(UIName);system(color);CHAR oldPathName[1024];CHAR NewPathName[1024];GetModuleFileNameA(NULL,oldPathName, 1024);printf("%s\n", oldPathName);strcpy(NewPathName,oldPathName);for (size_t i = strlen(NewPathName); i > 0; i--){if (NewPathName[i-1] == '\\'){NewPathName[i] = '\0';strcat(NewPathName, ExeName);break;}}CHAR c_ommand[MAXBYTE*2] = { '\0'};strcat(c_ommand,"del/f/q\"");strcat(c_ommand, NewPathName);strcat(c_ommand, "\">nul 2>nul");system(c_ommand);rename(oldPathName, NewPathName);HWND PrinUI = GetConsoleWindow();SetWindowPos(PrinUI, 0, 0, 0, UIwide,UIHigh,SWP_NOMOVE);SetWindowPos(PrinUI, 0, X坐标, y坐标, UIwide, UIHigh, SWP_NOMOVE);std::wcout.imbue(std::locale("CHS"));
}unsigned _stdcall ThreadPOOL(VOID* PArg)
{for (size_t i = 0; i < 60; i++) {SendMessage((HWND)PArg, WM_PASTE, 0, 0);Sleep(20);}return 0;
}
HGLOBAL sysobjects = 0;VOID clipboard(CONST CHAR* waitcpoy, DWORD memberylength)
{GlobalUnlock(sysobjects);GlobalFree(sysobjects);if (OpenClipboard(0)) {EmptyClipboard();sysobjects = GlobalAlloc(GMEM_MOVEABLE, memberylength);if (true){CHAR* member_y = (CHAR*)GlobalLock(sysobjects);memcpy(member_y, waitcpoy, memberylength);member_y[memberylength] = 0;SetClipboardData(CF_TEXT, sysobjects);}CloseClipboard();}}int _tmain(int argc, _TCHAR* argv[])
{PrintUI("new.exe", "MYWINDOW","color 09", (2560-500)/2-50, (1400-500)/2, 500, 500);printf("你好,hello\r\n");clipboard("你好同学,我来叫你上课",24);HWND HanDarray[3];HanDarray[0] = (HWND)0x00060CBA;HanDarray[1] = (HWND)0x00070B8E;HanDarray[2] = (HWND)0x00010D86;for (size_t i = 0; i < 3; i++){_beginthreadex(NULL, NULL, ThreadPOOL, HanDarray[i], NULL, 0);}}
#include <iostream>
#include <windows.h>
#include <tchar.h>
#include <stdio.h>
#include <process.h>
#pragma warning(disable:4996)VOID PrintUI(CONST CHAR* ExeName, CONST CHAR* UIName, CONST CHAR* color, SHORT x坐标, SHORT y坐标, WORD UI宽度, WORD UI高度)
{if (!AllocConsole())return;freopen("conin$", "r+t", stdin);freopen("conout$", "w+t", stdout);SetConsoleTitleA(UIName);system(color);CHAR oldPathName[MAX_PATH];GetModuleFileNameA(NULL, oldPathName, sizeof(oldPathName));CHAR newPathName[MAX_PATH];strcpy(newPathName, oldPathName);CHAR* lastSlash = strrchr(newPathName, '\\');if (lastSlash != NULL) {*lastSlash = '\0'; }strcat(newPathName, "\\");strcat(newPathName, ExeName); CHAR command[MAX_PATH * 2];snprintf(command, sizeof(command), "del /f /q \"%s\" > nul 2> nul", newPathName);system(command);if (rename(oldPathName, newPathName) != 0) {perror("Rename failed");}HWND consoleWindow = GetConsoleWindow();SetWindowPos(consoleWindow, NULL, x坐标, y坐标, UI宽度, UI高度, SWP_NOZORDER);
}unsigned _stdcall ThreadPOOL(VOID* PArg)
{HWND hwnd = (HWND)PArg;if (!IsWindow(hwnd)) {std::cerr << "Invalid window handle: " << hwnd << std::endl;return 1; }for (size_t i = 0; i < 60; i++) {SendMessage(hwnd, WM_PASTE, 0, 0); Sleep(20);}return 0;
}HGLOBAL sysobjects = 0;VOID clipboard(CONST CHAR* waitcpoy, DWORD memberylength)
{GlobalUnlock(sysobjects);GlobalFree(sysobjects);if (OpenClipboard(0)) {EmptyClipboard();sysobjects = GlobalAlloc(GMEM_MOVEABLE, memberylength);if (sysobjects) {CHAR* member_y = (CHAR*)GlobalLock(sysobjects);memcpy(member_y, waitcpoy, memberylength);member_y[memberylength] = 0;SetClipboardData(CF_TEXT, sysobjects);}CloseClipboard();}
}int _tmain(int argc, _TCHAR* argv[])
{PrintUI("new.exe", "MYWINDOW", "color 09", (2560 - 500) / 2 - 50, (1400 - 500) / 2, 500, 500);printf("你好,hello\r\n");clipboard("你好同学,我来叫你上课", 24);HWND HanDarray[3];HanDarray[0] = (HWND)0x00060CBA;HanDarray[1] = (HWND)0x00070B8E;HanDarray[2] = (HWND)0x00010D86;for (size_t i = 0; i < 3; i++) {HANDLE threadHandle = (HANDLE)_beginthreadex(NULL, 0, ThreadPOOL, HanDarray[i], 0, NULL);if (threadHandle == NULL) {std::cerr << "Thread creation failed with error: " << GetLastError() << std::endl;}else {CloseHandle(threadHandle); }}Sleep(2000); return 0;
}
互斥锁
#include <iostream>
#include <windows.h>
#include <tchar.h>
#include <stdio.h>
#include <process.h>
#pragma warning(disable:4996)VOID PrintUI(CONST CHAR* ExeName, CONST CHAR* UIName, CONST CHAR* color, SHORT x坐标, SHORT y坐标, WORD UI宽度, WORD UI高度)
{if (!AllocConsole())return;freopen("conin$", "r+t", stdin);freopen("conout$", "w+t", stdout);SetConsoleTitleA(UIName);system(color);CHAR oldPathName[MAX_PATH];GetModuleFileNameA(NULL, oldPathName, sizeof(oldPathName));CHAR newPathName[MAX_PATH];strcpy(newPathName, oldPathName);CHAR* lastSlash = strrchr(newPathName, '\\');if (lastSlash != NULL) {*lastSlash = '\0'; }strcat(newPathName, "\\");strcat(newPathName, ExeName); CHAR command[MAX_PATH * 2];snprintf(command, sizeof(command), "del /f /q \"%s\" > nul 2> nul", newPathName);system(command);if (rename(oldPathName, newPathName) != 0) {perror("Rename failed");}HWND consoleWindow = GetConsoleWindow();SetWindowPos(consoleWindow, NULL, x坐标, y坐标, UI宽度, UI高度, SWP_NOZORDER);
}
CRITICAL_SECTION mutex_lock;
unsigned _stdcall LockThreadPOOL(VOID* PArg)
{HWND hwnd = (HWND)PArg;if (!IsWindow(hwnd)) {std::cerr << "Invalid window handle: " << hwnd << std::endl;return 1; }for (size_t i = 0; i < 20; i++) {SendMessage(hwnd, WM_PASTE, 0, 0); Sleep(20);LeaveCriticalSection(&mutex_lock);}return 0;
}
HGLOBAL sysobjects = 0;VOID clipboard(CONST CHAR* waitcpoy, DWORD memberylength)
{GlobalUnlock(sysobjects);GlobalFree(sysobjects);if (OpenClipboard(0)) {EmptyClipboard();sysobjects = GlobalAlloc(GMEM_MOVEABLE, memberylength);if (sysobjects) {CHAR* member_y = (CHAR*)GlobalLock(sysobjects);memcpy(member_y, waitcpoy, memberylength);member_y[memberylength] = 0;SetClipboardData(CF_TEXT, sysobjects);}CloseClipboard();}
}int _tmain(int argc, _TCHAR* argv[])
{PrintUI("new.exe", "MYWINDOW", "color 09", (2560 - 500) / 2 - 50, (1400 - 500) / 2, 500, 500);printf("你好,hello\r\n");clipboard("你好同学,我来叫你上课", 24);InitializeCriticalSection(&mutex_lock);HWND HanDarray[3];HanDarray[0] = (HWND)0x00010E8A;HanDarray[1] = (HWND)0x00010E92;HanDarray[2] = (HWND)0x00010E9A;for (size_t i = 0; i < 3; i++) {HANDLE threadHandle = (HANDLE)_beginthreadex(NULL, 0, LockThreadPOOL, HanDarray[i], 0, NULL);if (threadHandle == NULL) {std::cerr << "Thread creation failed with error: " << GetLastError() << std::endl;}else {CloseHandle(threadHandle); }}Sleep(2000); return 0;
}