BOOL CProtectScreenApp::InitInstance()
{
AfxEnableControlContainer(); // Standard initialization
// If you are not using these features and wish to reduce the size
// of your final executable, you should remove from the following
// the specific initialization routines you do not need.#ifdef _AFXDLL
Enable3dControls(); // Call this when using MFC in a shared DLL
#else
Enable3dControlsStatic(); // Call this when linking to MFC statically
#endif
//
// CProtectScreenDlg dlg;
// m_pMainWnd = &dlg;
// int nResponse = dlg.DoModal();
// if (nResponse == IDOK)
// {
// // TODO: Place code here to handle when the dialog is
// // dismissed with OK
// }
// else if (nResponse == IDCANCEL)
// {
// // TODO: Place code here to handle when the dialog is
// // dismissed with Cancel
// }
//
// // Since the dialog has been closed, return FALSE so that we exit the
// // application, rather than start the application's message pump.
// return FALSE; LPTSTR lpszArgv = __argv[1];
if(lpszArgv[0]=='/')
lpszArgv++;
if(lstrcmpi(lpszArgv,_T("s"))==0)
{
CProtectScreenDlg dlg;
m_pMainWnd = &dlg;
int nResponse = dlg.DoModal();
return true;
}
return FALSE;}
这个是一个屏保的程序,最后这边要换成红色的代码
请解释下这段代码
{
AfxEnableControlContainer(); // Standard initialization
// If you are not using these features and wish to reduce the size
// of your final executable, you should remove from the following
// the specific initialization routines you do not need.#ifdef _AFXDLL
Enable3dControls(); // Call this when using MFC in a shared DLL
#else
Enable3dControlsStatic(); // Call this when linking to MFC statically
#endif
//
// CProtectScreenDlg dlg;
// m_pMainWnd = &dlg;
// int nResponse = dlg.DoModal();
// if (nResponse == IDOK)
// {
// // TODO: Place code here to handle when the dialog is
// // dismissed with OK
// }
// else if (nResponse == IDCANCEL)
// {
// // TODO: Place code here to handle when the dialog is
// // dismissed with Cancel
// }
//
// // Since the dialog has been closed, return FALSE so that we exit the
// // application, rather than start the application's message pump.
// return FALSE; LPTSTR lpszArgv = __argv[1];
if(lpszArgv[0]=='/')
lpszArgv++;
if(lstrcmpi(lpszArgv,_T("s"))==0)
{
CProtectScreenDlg dlg;
m_pMainWnd = &dlg;
int nResponse = dlg.DoModal();
return true;
}
return FALSE;}
这个是一个屏保的程序,最后这边要换成红色的代码
请解释下这段代码
如果这个程序的名字,例如a.exe,后面跟了一个参数“/s”("a.exe /s"),则显示窗口CProtectScreenDlg dlg(应该是一个屏保画面窗口);否则,什么都不做,程序退出
lpszArgv++;
if(lstrcmpi(lpszArgv,_T("s"))==0)
{
……
这一段就是在判断命令后的参数啊 把if(lpszArgv[0]=='/')根据自己需要换成其他符号 执行命令时就用相应的符号
-------------------------------------------
问题是我根本没有在cmd里执行啊,
我是作为一个屏保的,难道屏保运行时是默认 命令为:a.exe /s那如果我改成了if(lpszArgv[0]=='-'岂不是不能用了
可是我不明白为什么要这样判断
LPTSTR lpszArgv = __argv[1];
if(lpszArgv[0]=='/')
lpszArgv++;
if(lstrcmpi(lpszArgv,_T("s"))==0)1、难道__argv[1]默认就是 /s ?2、那按照你说的,如何修改成__argv[1] 为 -s ?
argv[1] 是这个 exe 的第一个参数
argv[2] 第二个,类推.这个程序,是判断第一个参数是否 /s,因为如果执行时是 ...exe /s 这样的话,那么
argv[1] = "/s",所以就拿 argv[1] 来判断
那么运行的时候 argv[1] = "/s" argv[2] = "123" [3] = "456"int main(int argc, char* argv[])
{
for (int k=0;k<argc;k++)
{
printf("%s \n",argv[k]);
}这样,多少个参数都可以打印出来看.
其实我想问的 是如果什么都不改的话,argv[k] 将会是什么内容呢?还是这个问题:
难道__argv[1]默认就是 /s ,不是的话,InitInstance()为什么要改成那样,
是不是屏保运行argv[1]默认就是 /s?
难道__argv[1]默认就是 /s ,不是的话,InitInstance()为什么要改成那样,
是不是屏保运行argv[1]默认就是 /s?不会,一定是我们填了参数,argv[1] 才会有内容,否则 argv[1] 没有内容.很多程序,都有运行的参数,看作者的设计意图了.这个代码,作者的意思应该是要传入 /s 的参数
我就是想知道在VC 中如何设置这个命令的,
如何改成 -s的呢
我就是想知道在VC 中如何设置这个命令的,
如何改成 -s的呢
那么运行后 argv[1] = "123" argv[2] = "45" argv[3] = "6789"楼主可以设置参数,试运行一下.
看看结果,可不可以进入你红色的代码.我拿人家一个代码,要求很多参数的程序.我也要在参数入写上 诸如
c:\test.pgm c:\chg.pgm -c -t 30 这类的参数传入来运行的.
我就是搞不懂这个,是不是默认有 /s 命令呢
我就是搞不懂这个,是不是默认有 /s 命令呢回25楼,你是怎样去运行的?
但是那篇文章说,如果最后农场scr屏保文件的时候
要把这个函数处理成这样,最后做成屏保才可以,
然后就是放到system32里,然后就是 桌面右键属性,选择这个scr,然后 就可以了(总之就是屏保文件拉)
要使在桌面属性对话框中选择此屏保时不运行(这里不是说不让它运行),要加最后一段代码。回到VC编程界面,进入CMyApp::InitInstance()中编辑
分别是
/s 运行屏幕保护
/c 设置屏幕保护 (默认)
/p 预视效果
正常window运行一个scr是通过加 /s参数,
而在显示里面那个设置按钮实际上是 /c参数,
那个预示效果的窗口就使用了/p参数
而已双击运行或者是预览的时候,会自动传入 /s 的参数的.刚才测试了一下.
Display Properties there is a small picture representing a display where the user can view a preview of the screen saver - the preview is called using the argument '/p'.
如果
if(lstrcmpi(lpszArgv,_T("s"))==0 || lstrcmpi(lpszArgv,_T("p"))==0)
那么Combobox选择我这个屏保或者点击设置,设置完,确定退出后,第二次进入属性对话框
选择 屏幕包含程序 标签都会启动屏保不过如果
if(lstrcmpi(lpszArgv,_T("s"))==0 || lstrcmpi(lpszArgv,_T("c"))==0)
却没什么反应,