判断ShellExecute参数!

baoyufu 2009-11-24 04:52:05
ShellExecute(NULL,_T("open"),_T("..\\debug\\VedioConverter.exe"),"-f",NULL,SW_SHOWNORMAL);

我用入如上代码重先启动程序本身(目的是让程序自动重启),同时赋了一个参数"-f";
当程序启动后如何判断此时是否带了参数"f"

请赐教!
...全文
122 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
wb_rock 2009-11-24
  • 打赏
  • 举报
回复
一般情况下,写成NULL就可以了~~
Allen_zhang 2009-11-24
  • 打赏
  • 举报
回复
在你函数的入口处获取命令行参数即可

要知道怎样用查msdn就可以了


LPTSTR GetCommandLine(void);
LPWSTR *CommandLineToArgvW(LPCWSTR lpCmdLine,int *pNumArgs);

//两个API都可以
//或者用宏,在来解析就可以了
int argc = __argc;
char** argv = __argv;


[Quote]
CommandLineToArgvW Function

--------------------------------------------------------------------------------

Parses a Unicode command-line string and returns an array of null-terminated Unicode strings containing the individual arguments found in that command line as well as a count of arguments, similar to the standard C run-time argv and argc values.

Syntax

LPWSTR *CommandLineToArgvW( LPCWSTR lpCmdLine,
int *pNumArgs
);
Parameters

lpCmdLine
[in] Pointer to a null-terminated Unicode string containing the full command line. An application will usually directly pass on the value returned by a call to the GetCommandLineW function.
If this parameter is the empty string (""), the function returns the path to the current executable file.

pNumArgs
[out] Pointer to a variable of type int that receives the number of array elements returned.
Return Value

Pointer to an array of null-terminated Unicode strings representing the individual arguments found on the command line. The first element contains the program name; each subsequent element contains one argument.
If the function fails, the return value is NULL. To get extended error information, call GetLastError.

GetCommandLine

The GetCommandLine function retrieves the command-line string for the current process.


LPTSTR GetCommandLine(void);

Parameters
This function has no parameters.
Return Values
The return value is a pointer to the command-line string for the current process.


[/Quote]
zyq5945 2009-11-24
  • 打赏
  • 举报
回复
自己在程序要检查参数的地方
CString strTmp;
strTmp = GetCommandLine();
strTmp.MakeLower();
if(-1==strTmp.Find("-f"))
{
//找不到参数-f
}
else
{
//有参数-f
}
baoyufu 2009-11-24
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 zyq5945 的回复:]
LPTSTR WINAPI GetCommandLine(void);
[/Quote]
这个要怎么用,能不能给个实例;我百度过没百出来
Dingnifei123 2009-11-24
  • 打赏
  • 举报
回复
这不太好搞吧,启动后还判断是否带参数?~
zyq5945 2009-11-24
  • 打赏
  • 举报
回复
LPTSTR WINAPI GetCommandLine(void);

16,551

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Creator Browser
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧