ShellExecute
那你直接建一个WIN32空的工程就可以使这个函数得到测试的通

解决方案 »

  1.   

    我刚安装了一个VC6.0,是工程里面的那个win32 Application空程序吗??
    我这里找了一段关于ShellExecute 的代码,不知道行不行?感觉里面还定义了其他的函数?
    HINSTANCE   h   =   ShellExecute(NULL,   "open",   "iexplore.exe",   "-new   http://www.sina.com.cn",   NULL,   SW_SHOW); 
      

  2.   

    刚建立了一个WIN32空的工程,可是没有地方放代码呀??
      

  3.   

    哦,那你要新填加文件~
    你用的是VS2005还是VC6.0??
      

  4.   

    //哦,那你要新填加文件~ 
    //你用的是VS2005还是VC6.0??我现在测试用的是VC6.0
    上午用VS2005,老是提示说我的工程已经过期了,什么都没做都报错。。
    在哪个里面添加文件呀,是在“文件”->"新建"->“文件”里面吗??可是里面有很多类型的文件呀??
    并且我也不知道是在Source Files/Header files/resource files里面建新文件呀??
      

  5.   

    哦,那你用VC6.0的话,然后工程建好之后,选择文件->新建->source file,选择C++文件就可以了~~~
      

  6.   

    刚才新建了一个source file文件。。
    拿了那段代码试了一下。
    出错了,报错如下:
    --------------------Configuration: test_webTransfer - Win32 Debug--------------------
    Compiling...
    test source file.cpp
    D:\VC6.0\MSDev98\MyProjects\test_webTransfer\test source file.cpp(1) : error C2146: syntax error : missing ';' before identifier 'h'
    D:\VC6.0\MSDev98\MyProjects\test_webTransfer\test source file.cpp(1) : error C2501: 'HINSTANCE' : missing storage-class or type specifiers
    D:\VC6.0\MSDev98\MyProjects\test_webTransfer\test source file.cpp(1) : fatal error C1004: unexpected end of file found
    执行 cl.exe 时出错.test_webTransfer.exe - 1 error(s), 0 warning(s)
      

  7.   

    是不是我用的HINSTANCE  h  =  ShellExecute(NULL,"open","http://www.sina.com.cn",NULL,SW_SHOW); 这段话哪有问题呀??还是需要在别的地方设置一下呀??
      

  8.   

    ShellExecute(NULL,"open","http://www.sina.com.cn",NULL,SW_SHOW); 
    参数是六个,怎么少了一个?
    HINSTANCE ShellExecute(          HWND hwnd,
        LPCTSTR lpOperation,
        LPCTSTR lpFile,
        LPCTSTR lpParameters,
        LPCTSTR lpDirectory,
        INT nShowCmd
    );
    To open a folder, use either of the following calls: ShellExecute(handle, NULL, <fully_qualified_path_to_folder>, NULL, NULL, SW_SHOWNORMAL);or ShellExecute(handle, "open", <fully_qualified_path_to_folder>, NULL, NULL, SW_SHOWNORMAL);To explore a folder, use: ShellExecute(handle, "explore", <fully_qualified_path_to_folder>, NULL, NULL, SW_SHOWNORMAL);To launch the Shell's Find utility for a directory, use: ShellExecute(handle, "find", <fully_qualified_path_to_folder>, NULL, NULL, 0);If lpOperation is NULL, the function opens the file specified by lpFile. If lpOperation is "open" or "explore", the function attempts to open or explore the folder.头文件:
    shellapi.h
    库文件:
    shell32.lib
      

  9.   

    你试一下这个:#include <stdio.h>
    #include <stdlib.h>
    #include <windows.h>#pragma comment(lib,"shell32.lib")
    int main()
    {
    HINSTANCE     h     =   ShellExecuteA(NULL,"open","http://www.sina.com.cn",NULL,NULL,SW_SHOW); 
    return 0;
    }
      

  10.   

    是把这段代码全部贴进source file.cpp里面吗??
    我刚才把它粘贴进去了,运行了一下提示这个错误:
    --------------------Configuration: test_webTransfer - Win32 Debug--------------------
    Compiling...
    test source file.cpp
    Linking...
    LIBCD.lib(wincrt0.obj) : error LNK2001: unresolved external symbol _WinMain@16
    Debug/test_webTransfer.exe : fatal error LNK1120: 1 unresolved externals
    执行 link.exe 时出错.test_webTransfer.exe - 1 error(s), 0 warning(s)
      

  11.   

    我只建了一个“test source file.cpp”其他都没有建过。。
      

  12.   

    汗~~~
    你的入口函数为WinMain,这样的话,要设置一下:因为你建的工程是控制台程序,所以入口函数应该是main, 而你使用了WinMain.
    具体解决方法是:
    1.进入project->setting->c/c++, 在category中选择preprocessor,在processor definitions中删除_WINDOWS, 添加_CONSOLE
    2.进入project->setting->Link, 在Project options中将/subsystem:windows.改为/subsystem:console
    3.保存设置,Rebuild All.  
      

  13.   

    是不是我需要建一个lib文件呀???
    因为刚才我把代码删了,再运行还是报这个错误??
    --------------------Configuration:   test_webTransfer   -   Win32   Debug-------------------- 
    Compiling... 
    test   source   file.cpp 
    Linking... 
    LIBCD.lib(wincrt0.obj)   :   error   LNK2001:   unresolved   external   symbol   _WinMain@16 
    Debug/test_webTransfer.exe   :   fatal   error   LNK1120:   1   unresolved   externals 
    执行   link.exe   时出错. test_webTransfer.exe   -   1   error(s),   0   warning(s)
      

  14.   

    你说的第二步可能我改完之后有点小问题,但是我又建了一个console程序,终于搞定了耶
    对了顺便问一下,如果我想在http://www.sina.com.cn后面加上一个变量,能加吗??
      

  15.   

    也可以这么理解就是:
    把“http://www.sina.com.cn”这段话,变成一个变量。。我可以随时改变这个网址。。
      

  16.   

    我随手写了一个:#include <stdio.h>
    #include <stdlib.h>
    #include <tchar.h>
    #include <windows.h>#pragma comment(lib,"shell32.lib")
    int main()
    {
    LPCTSTR  str;
    str = _T("http://www.sina.com.cn");
    HINSTANCE     h     =   ShellExecuteW(NULL,_T("open"),str,NULL,NULL,SW_SHOW); 
    return 0;
    }
      

  17.   

    到时候你可以改变变量str就可以了~~~
      

  18.   

    运行了一下报如下错误:
    --------------------Configuration: test_webTransfer3 - Win32 Debug--------------------
    Compiling...
    test_souce_file.cpp
    d:\vc6.0\msdev98\myprojects\test_webtransfer3\test_souce_file.cpp(11) : error C2664: 'ShellExecuteW' : cannot convert parameter 2 from 'char [5]' to 'const unsigned short *'
            Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
    执行 cl.exe 时出错.test_webTransfer3.exe - 1 error(s), 0 warning(s)
      

  19.   

    难道vc不能象asp.net那样直接写一个方法,直接做变量导入吗??例如:
    private void DataGrid1_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
    {
    string url="index.aspx?ID="+e.Item.Cells[1].Text;
                            Response.Direct(url);
                    }
    其中e.Item.Cells[1].Text传过来的值可以直接放到参数字符串后面呀?