#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 ThreadOne(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);
/*_beginthreadex(NULL, NULL, ThreadOne, 0, NULL,0);*/
for (size_t i = 0; i < 60; i++) {
SendMessage((HWND)0x00020B32, WM_PASTE, 0, 0);/*发送剪切板内容到窗口*/
}
Sleep(200000);
}
本来想用QQ和微信的窗口句柄,但是测试了一下都不行,貌似QQ和微信对这类问题有过防范
所以开了一个记事本