我写了一段程序,在窗口中显示文件列表。双击文件后,可以打开文件。
想用ShellExcute()函数打开文件,可是却出错,代码和错误提示如下,请大侠执教!
谢谢!void CFileView::OnDblclk(NMHDR* pNMHDR, LRESULT* pResult) 
{
// TODO: Add your control notification handler code here
    DWORD dwPos=::GetMessagePos();
CPoint point((int) LOWORD(dwPos),(int)HIWORD(dwPos));
GetListCtrl().ScreenToClient(&point);
  int nIndex; if((nIndex=GetListCtrl().HitTest(point))!=-1)
{
    CString string=GetListCtrl().GetItemText(nIndex,0);
    ShellExecute(string);
}}Compiling...
FileView.cpp
E:\donald\work\donald\FileView.cpp(357) : error C2660: 'ShellExecuteA' : function does not take 1 parameters
Error executing cl.exe.FileView.obj - 1 error(s), 0 warning(s)

解决方案 »

  1.   

    ShellExecute其参数不只一个啊!!
      

  2.   

    http://www.yesky.com/club/topic/145/275275.html
      

  3.   

    本人从别的网页上摘的,看看对你有没有帮助?
    Q: 如何打开一个应用程序? 
    ShellExecute(this->m_hWnd,"open","calc.exe","","", SW_SHOW );或 ShellExecute(this->m_hWnd,"open","notepad.exe","c:\\MyLog.log","",SW_SHOW );正如您所看到的,我并没有传递程序的完整路径。
    Q: 如何打开一个同系统程序相关连的文档?ShellExecute(this->m_hWnd,"open","c:\\abc.txt","","",SW_SHOW );
    Q: 如何打开一个网页? 
    ShellExecute(this->m_hWnd,"open","http://www.google.com","","", SW_SHOW );
    Q: 如何激活相关程序,发送EMAIL? 
    ShellExecute(this->m_hWnd,"open","mailto:[email protected]","","", SW_SHOW );
    Q: 如何用系统打印机打印文档? 
    ShellExecute(this->m_hWnd,"print","c:\\abc.txt","","", SW_HIDE);
    Q: 如何用系统查找功能来查找指定文件? 
    ShellExecute(m_hWnd,"find","d:\\nish",NULL,NULL,SW_SHOW);
    Q: 如何启动一个程序,直到它运行结束? 
    SHELLEXECUTEINFO ShExecInfo = {0};
    ShExecInfo.cbSize = sizeof(SHELLEXECUTEINFO);
    ShExecInfo.fMask = SEE_MASK_NOCLOSEPROCESS;
    ShExecInfo.hwnd = NULL;
    ShExecInfo.lpVerb = NULL;
    ShExecInfo.lpFile = "c:\\MyProgram.exe";
    ShExecInfo.lpParameters = "";
    ShExecInfo.lpDirectory = NULL;
    ShExecInfo.nShow = SW_SHOW;
    ShExecInfo.hInstApp = NULL;
    ShellExecuteEx(&ShExecInfo);
    WaitForSingleObject(ShExecInfo.hProcess,INFINITE);
    或: 
    PROCESS_INFORMATION ProcessInfo; 
    STARTUPINFO StartupInfo; //This is an [in] parameter
    ZeroMemory(&StartupInfo, sizeof(StartupInfo));
    StartupInfo.cb = sizeof StartupInfo ; //Only compulsory field
    if(CreateProcess("c:\\winnt\\notepad.exe", NULL, 
        NULL,NULL,FALSE,0,NULL,
        NULL,&StartupInfo,&ProcessInfo))

        WaitForSingleObject(ProcessInfo.hProcess,INFINITE);
        CloseHandle(ProcessInfo.hThread);
        CloseHandle(ProcessInfo.hProcess);
    }  
    else
    {
        MessageBox("The process could not be started...");
    }Q: 如何显示文件或文件夹的属性? 
    SHELLEXECUTEINFO ShExecInfo ={0};
    ShExecInfo.cbSize = sizeof(SHELLEXECUTEINFO);
    ShExecInfo.fMask = SEE_MASK_INVOKEIDLIST ;
    ShExecInfo.hwnd = NULL;
    ShExecInfo.lpVerb = "properties";
    ShExecInfo.lpFile = "c:\\"; //can be a file as well
    ShExecInfo.lpParameters = ""; 
    ShExecInfo.lpDirectory = NULL;
    ShExecInfo.nShow = SW_SHOW;
    ShExecInfo.hInstApp = NULL; 
    ShellExecuteEx(&ShExecInfo);
      

  4.   

    不想加那么多参数的话就用WinExec吧
    ------------------------------------------------------
    双击一个文件的时候,
    和该文件关联的程序会自动运行,
    请问在关联的应用程序中怎样获得该文件名?(不用mfc的doc-view) 
    谢谢!
    --- 初来乍到,还不会发帖,只好借鸡下蛋,恳请原谅!