我调用子程序exe,通过各位的creatprocess, winexec, shellexecute和COM调用,为什么输入参数设为Sleep, lpCmdLine == "Sleep"却不为真?呵呵,哪里错了?int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
...
if(lpCmdLine == "Sleep")
{
MessageBox(NULL, "Sleep", "test", MB_OK);
}
else if(lpCmdLine == "Restart")
{
MessageBox(NULL, "Restart", "test", MB_OK);
}
else if(lpCmdLine == "Suspend")
{
MessageBox(NULL, "Suspend", "test", MB_OK);
}
else
{
MessageBox( NULL, "Illegal", "test", MB_OK);
} // Main message loop:
while (GetMessage(&msg, NULL, 0, 0))
{
if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
return msg.wParam;
}
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
...
if(lpCmdLine == "Sleep")
{
MessageBox(NULL, "Sleep", "test", MB_OK);
}
else if(lpCmdLine == "Restart")
{
MessageBox(NULL, "Restart", "test", MB_OK);
}
else if(lpCmdLine == "Suspend")
{
MessageBox(NULL, "Suspend", "test", MB_OK);
}
else
{
MessageBox( NULL, "Illegal", "test", MB_OK);
} // Main message loop:
while (GetMessage(&msg, NULL, 0, 0))
{
if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
return msg.wParam;
}
解决方案 »
- VS2008 MFC中的CToolBar怎么在CFrameWnd中没有定义?
- 炫彩界面库系列教程之360杀毒软件界面,XML实现,快速开发,c++,DirectUI
- vc如何在分割视图中显示不同的文件内容
- AddNew发生异常
- (子窗口)为什么WM_KEYDOWN不响应?
- 程序打开一个URL,怎么预设Cookie?
- 求教,初级入门问题
- CRecordView关闭的问题
- IpIImage对象成员widthStep不是字节对齐吗?//为啥480是4的倍数 不知为啥报错!
- 视频采集,想加入自己的算法,求教
- 挑战进度条,急ing,在线等
- 一百分求助!!Web Service 中 VC6 客户端调用 C# 服务端的小问题!
WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR CmdLinePointer, int WndShowState)
{
if(GetCmdLinePara()=="-y")
...
}
AnsiString GetCmdLinePara(void)
{
char *p=GetCommandLine();
do
{
p++;
}while(*p!='"');
p++;
if(*p=='\0')
{
return NULL;
}
else
{
while(*p==' ')
{
p++;
}
return (AnsiString)p;
}
}
-------------------------------------------------------------------------------------
输出是正确的,如输入"cmd.exe Sleep", 那么LPSTR lpCmdLine为"Sleep"
Creatprocess, WinExec, ShellExecute或COM调用