有人知道任何C99预处理器魔法允许创建一个由另一个重复N次的字符串组成的字符串吗?
例如
STRREP( "%s ", 3 )
Run Code Online (Sandbox Code Playgroud)
变
"%s %s %s "
Run Code Online (Sandbox Code Playgroud)
经过预处理.
我能想到的唯一一件事就是这样
#define STRREP( str, N ) STRREP_##N( str )
#define STRREP_0(str) ""
#define STRREP_1(str) str
#define STRREP_2(str) str str
#define STRREP_3(str) str str str
...
Run Code Online (Sandbox Code Playgroud)
哪个效果很好,但是很难看,因为我必须手动为每个重复长度定义一个宏.我想与variadic宏一起使用它,宏返回这里显示的宏参数的数量.
我目前正致力于自动化无法更改的Win32 UI应用程序.到目前为止,我的方法是使用目标应用程序的标准消息队列来注入我的输入.我已经走得很远了:
WM_COMMAND作品"点击"按钮TCM_GETITEMA通过虚拟鼠标点击WM_LBUTTONDOWN/ WM_LBUTTONUP工作来读取选项卡的名称并激活它们然而,我遇到的情况是修改可编辑的ComboBox及其Edit控件的文本.我尝试使用这样的WM_SETTEXT消息:
public static void SetText(IntPtr hWnd, string text) {
// Maximum item text buffer length
const int MAX_LEN = 512;
// Get process
uint ProcessId;
WinAPI.GetWindowThreadProcessId(hWnd, out ProcessId);
IntPtr process = WinAPI.OpenProcess(
WinAPI.ProcessAccessFlags.VMOperation | WinAPI.ProcessAccessFlags.VMRead |
WinAPI.ProcessAccessFlags.VMWrite | WinAPI.ProcessAccessFlags.QueryInformation,
false, ProcessId
);
if( process == IntPtr.Zero )
throw new Exception("Could not open process");
// Allocate memory in remote process
IntPtr farTextPtr = WinAPI.VirtualAllocEx(process, IntPtr.Zero, MAX_LEN,
WinAPI.AllocationType.Commit, …Run Code Online (Sandbox Code Playgroud)