当前位置: 首页 > news >正文

多线程2(gamere)

#include<iostream>
#include<windows.h>
#include<tchar.h>
#include<stdio.h>
#include <process.h>
#pragma warning(disable:4996)
//exe应用程序
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;
}
//unsigned _stdcall ThreadTwo(VOID* PArg)
//{
//	for (size_t i = 0; i < 60; i++) {
//		SendMessage((HWND)0x00020B32, WM_PASTE, 0, 0);/*发送剪切板内容到窗口*/
//
//	}
//	return 0;
//}
//unsigned _stdcall ThreadThree(VOID* PArg)
//{
//	for (size_t i = 0; i < 60; i++) {
//		SendMessage((HWND)0x00020B32, WM_PASTE, 0, 0);/*发送剪切板内容到窗口*/
//
//	}
//	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);/*应用程序将 WM_PASTE 消息发送到编辑控件或组合框,以将剪贴板的当前内容复制到位于当前插入点位置的编辑控件。 仅当剪贴板包含 CF_TEXT 格式的数据时,才会插入数据。*/}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);}/*_beginthreadex(NULL, NULL, ThreadOne, HanDarray[0], NULL,0);_beginthreadex(NULL, NULL, ThreadTwo,HanDarray[1], NULL, 0);_beginthreadex(NULL, NULL, ThreadThree, HanDarray[2], NULL, 0);*///for (size_t i = 0; i < 60; i++) {//	SendMessage((HWND)0x00020B32, WM_PASTE, 0, 0);/*发送剪切板内容到窗口*///}//Sleep(200000);}
#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));// 替代 PathRemoveFileSpecACHAR 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));// 替代 PathRemoveFileSpecACHAR 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);//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); // 关闭线程句柄,防止资源泄漏//    }//}// 等待线程完成的逻辑可以在这里添加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;
}

在这里插入图片描述


http://www.mrgr.cn/news/29627.html

相关文章:

  • RabbitMQ 在 Linux CentOS 和 Docker 环境下的部署及分布式部署指南
  • MQ集群
  • 038 进程线程
  • 23.网工入门篇--------介绍一下园区网典型组网架构及案例实践
  • STM32问题集
  • 论文1—《基于卷积神经网络的手术机器人控制系统设计》文献阅读分析报告
  • Python 课程16-Pygame
  • spring security 手机号 短信验证码认证、验证码认证 替换默认的用户名密码认证132
  • itk c++ 3D医学图像刚性配准
  • 【与C++的邂逅】--- C++的IO流
  • wifi中的相干带宽
  • Windows系统下使用VS排查内存泄露的两种办法
  • 如何在 Qt 的 QListWidget 中逐行添加和显示数据
  • eNSP简单用法
  • 超级简约的B端页面,B端系统就该如此简化设计。
  • 自动化流程机器人(RPA)
  • Nginx反向代理出现502 Bad Gateway问题的解决方案
  • ram和rom的种类迭代和介绍
  • 【隐私计算篇】不经意传输协议(OT/OTE)的进一步补充
  • 自组织是管理者和成员的双向奔赴
  • 示波器的使用
  • Lucene详解介绍以及底层原理说明
  • maven pom文件中的变量定义
  • Qt安卓开发连接手机调试(红米K60为例)
  • 数据结构入门学习(全是干货)——树(中)
  • 【研发日记】嵌入式处理器技能解锁(六)——ARM的Cortex-M4内核