DOS下可以在main()中修改argc argv来实现带参数的运行程序,如c:\A.exe h来运行A程序,如只输入c:\A.exe程序不执行或给出提示,WINDOWS下如何实现程序双击鼠标无反应,只能以命令行的方式如c:\A.exe h来执行?

解决方案 »

  1.   

    在App的init中用_argc _argv(MSDN中有谁明)判断是否有参数h,有则执行,无则返回False
      

  2.   

    是不是想给某个程序传递参数?
    两种方式:
    1 进入命令行方式,和dos一样的操作;
    2 建立一个对应的应用程序的快捷方式,在快捷方式上右键-〉属性-〉目标 后加上你的参数。运行快捷方式。
      

  3.   

    我的意思是如何使一个WINDOWS程序只能带参数运行,不带参数,在命令行和双击鼠标都无反应
      

  4.   

    在App的InitInstance
    你解释一下commandLine,有参数就继续,没有就退出.
      

  5.   

    同上,判断winmain的命令行参数是否为空或符合你要的条件。
      

  6.   

    我觉得Azusa()的判断参数的个数的文件比较好。
      

  7.   

    如果是在SDK下,只需要象 mscf 所说的"判断winmain的命令行参数是否为空或符合你要的条件"就行了的,即
    int WINAPI WinMain(
      HINSTANCE hInstance,      // handle to current instance
      HINSTANCE hPrevInstance,  // handle to previous instance
      LPSTR lpCmdLine,          // command line
      int nCmdShow              // show state
    );
    检查lpCmdLine即可.如果是在MFC下的,情况就复杂了.首先在你的CWinApp的继承类中,通过其
    ParseCommandLine()方法得知是否有命令行参数,然后override它的Run()方法,使之在无命令行参数的情况下直接返回0,有命令行参数时调用CWinApp::Run().
      

  8.   

    ShellExecute(0,"open","c:\\1.exe",0,0,SW_SHOW);ShellExecute();
    WinExec();
    CreateProcess()
    这三个函数都可以启动一个.exe文件
    具体参数请参考MSDN
      

  9.   

    在任何地方都可以这样得到参数信息
    for (int i = 1; i < __argc; i++)
    {
    LPCTSTR pszParam = __targv[i];
    }
      

  10.   

    The GetCommandLine function returns a pointer to the command-line string for the current process. LPTSTR GetCommandLine(VOID)
     ParametersThis function has no parameters. Return ValuesThe return value is a pointer to the command-line string for the current process. ResNon-Unicode console processes written in C can use the argc and argv arguments to access the command-line arguments. The parameters of the command-line string, excluding the program name, are also available to such non-Unicode applications as a parameter of the WinMain function. The reason for the Unicode exclusion from these options is that WinMain, argc, and argv use the LPSTR data type for parameters, not the LPTSTR datatype. See Also
      

  11.   

    BOOL Cdlg3App::InitInstance()
    {
    ...
    InitCommonControls(); CWinApp::InitInstance(); if(m_lpCmdLine[0] == _T('\0')) {
    ::MessageBox(NULL,"无参数","错误",MB_OK|MB_ICONSTOP);
    return FALSE;
    }
    ...
    }