// CreateClipboardData.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <Windows.h>
#define LINE_LEN 430
int _tmain(int argc, _TCHAR* argv[])
{
char str[LINE_LEN + 1];
const int line = 1;
char header[] = "\x04\x08\x5b\x05o:\x16RPG::EventCommand\x08:\x10@parameters[\x06\"\x05";
char footer[] = ":\x0c@indenti\0\x3a\xa@codeij";
header[3] += line;
gets_s(str, LINE_LEN);
int strlength = strlen(str);
int count = 4;
char data[200];
int size = sizeof(header) - 1;
header[size - 1] += strlength;
memcpy(data + count, header, size);
count += size;
size = strlength;
memcpy(data + count, str, size);
count += size;
size = sizeof(footer) - 1;
memcpy(data + count, footer, size);
count += size;
size = count - 0x04;
data[0] = size & 0xff;
data[1] = size >> 8 & 0xff;
data[2] = size >> 16 & 0xff;
data[3] = size >> 24 & 0xff;
OpenClipboard(NULL);
EmptyClipboard();
HGLOBAL hMem = GlobalAlloc(GMEM_FIXED, count);
char *space = (char *)GlobalLock(hMem);
memcpy(space, data, count);
/*FILE *fp;
fopen_s(&fp, "mem.dat", "wb");
fwrite(space, count, 1, fp);
fclose(fp);*/
GlobalUnlock(hMem);
SetClipboardData(50287, hMem);
CloseClipboard();
return 0;
}
【技巧】
运行该程序时,可以输入一段超长内容:
粘贴到RMXP的事件编辑器后,可以看到这一长串a独占了一行文字,没有任何换行。
这是RMXP本身所不能做到的。