如何在程序中通过程序调用打开浏览器并访问一个网址? 急 !

解决方案 »

  1.   

    ShellExecute(0,NULL,"http://www.sohu.com",NULL,NULL,SW_NORMAL);
      

  2.   

    ShellExecute(NULL, "open", "www.163.com", NULL, NULL, SW_SHOWNORMAL);
      

  3.   

    // "GotoURL" function by Stuart Patterson
    // As seen in the August, 1997 Windows Developer's Journal.
    HINSTANCE CHyperLink::GotoURL(LPCTSTR url, int showcmd)
    {
        TCHAR key[MAX_PATH + MAX_PATH];     // First try ShellExecute()
        HINSTANCE result = ShellExecute(NULL, _T("open"), url, NULL,NULL, showcmd);    // If it failed, get the .htm regkey and lookup the program
        if ((UINT)result <= HINSTANCE_ERROR) {

            if (GetRegKey(HKEY_CLASSES_ROOT, _T(".htm"), key) == ERROR_SUCCESS) {
                lstrcat(key, _T("\\shell\\open\\command"));            if (GetRegKey(HKEY_CLASSES_ROOT,key,key) == ERROR_SUCCESS) {
                    TCHAR *pos;
                    pos = _tcsstr(key, _T("\"%1\""));
                    if (pos == NULL) {                     // No quotes found
                        pos = _tcsstr(key, _T("%1"));       // Check for %1, without quotes
                        if (pos == NULL)                   // No parameter at all...
                            pos = key+lstrlen(key)-1;
                        else
                            *pos = _T('\0');                   // Remove the parameter
                    }
                    else
                        *pos = _T('\0');                       // Remove the parameter                lstrcat(pos, _T(" "));
                    lstrcat(pos, url);
                    //result = (HINSTANCE) WinExec(key,showcmd);
    PROCESS_INFORMATION psinfo;
    if (CreateProcess( NULL,                  // name of executable module
    key, // command line string
    NULL, // SD
    NULL, // SD
    FALSE,                      // handle inheritance option
    0, // creation flags
    NULL, // new environment block
    NULL, // current directory name
    NULL, // startup information
    &psinfo  // process information
    )== TRUE)
    return (HINSTANCE)psinfo.hProcess;
    result = NULL; 
                }
            }
    }
      
        return result;
    }
      

  4.   

    ShellExecute(0,NULL,"http://www.sohu.com",NULL,NULL,SW_NORMAL);