|
|
#include "stdafx.h"
#include "windows.h"
#include "shellapi.h"
#pragma comment(linker, "/OPT:nowin98 ")
#pragma comment(linker, "/subsystem:\"windows\" /entry:\"mainCRTStartup\"" ) // 设置入口地址
void RemoveQuotes(char* str) {
char* src = str;
char* dst = str;
while (*src) {
if (*src != '\"') { // 只拷贝非引号字符
*dst = *src;
dst++;
}
src++;
}
*dst = '\0'; // 终止字符串
}
void TrimLeft(char* str) {
char* p = str;
// 找到第一个非空格字符
while (*p == ' ') {
p++;
}
// 移动非空格字符到字符串起始位置
memmove(str, p, strlen(p) + 1);
}
int main(int argc, char* argv[])
{
if (argc < 3) {
return 0;
}
char *param = "";
char* found = strstr(GetCommandLine(), argv[2]);
if (found) {
// 移动指针到 searchStr 之后的内容
found = found + 2 + strlen(argv[2]);
// 如果后面还有内容,输出
if (*found) {
RemoveQuotes(found);
TrimLeft(found);
strcat(param, "\"");
strcat(param, found);
strcat(param, "\"");
}
}
char szPath[MAX_PATH] = {0};
GetModuleFileName(NULL, szPath, MAX_PATH);
char* pLastSlash = strrchr(szPath, '\\'); // 找到最后一个 '\'
if (pLastSlash) {
*pLastSlash = '\0'; // 截断字符串
}
strcat(szPath, "\\");
strcat(szPath, argv[1]);
// 参数分别为:父窗口句柄,要执行的程序,参数,目录,窗口显示方式,进程优先级
ShellExecute(NULL, "open", szPath, param, NULL, SW_SHOWNORMAL);
return 0;
} 很早以前,瞎写的,原理很简单
|
|