Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Opening a web page from C or C++

Options
  • 19-03-2005 4:14pm
    #1
    Closed Accounts Posts: 1,541 ✭✭✭


    Hi All,

    I want to open a web page from witthin my c program. Anyone have any ideas how to do this. The C program will NOT be inside a web server.

    Anyone know how to call/open a web page from inside a C program. ?

    Thanks.


Comments

  • Registered Users Posts: 1,481 ✭✭✭satchmo


    If you're using Windows, ShellExecute will do that.
    Eg:
    ShellExecute(NULL, "open", "http://www.boards.ie", NULL, NULL, SW_SHOWNORMAL);
    
    If you substitute a file like "c:\\temp\\textfile.txt" for the webpage address, it'll open that file with the program associated with its extension.


  • Closed Accounts Posts: 1,541 ✭✭✭finnpark


    Thanks for that Satchmo,

    Yes I am using Windows. All I really want to do is to open a webpage using C. I will try this out.

    Can I close the webpage a second later using C? Or do I have to use Javascript or something to do this.

    Thanks Again.


  • Registered Users Posts: 1,481 ✭✭✭satchmo


    If it's exactly a second later you want to close it, javascript would be much easier.


  • Closed Accounts Posts: 447 ✭✭MickFarr


    Use the CreateProcess function to start
    DWORD ExitCode;
    STARTUPINFO si;
    PROCESS_INFORMATION pi;
    
    
    memset(&si, 0, sizeof(si));
    memset(&pi, 0, sizeof(pi));
    si.cb = sizeof(si);
    
    // Create the process. 
    if(!CreateProcess(NULL, "C:\\Program Files\\Internet Explorer\\iexplore.exe www.boards.ie",NULL,NULL,FALSE,0,NULL,NULL,&si,&pi))
       AfxMessageBox("CreateProcess failed.");
    	
    

    Then use TerminateProcess at any time to kill the process
    // Close process. 
    GetExitCodeProcess(pi.hProcess, &ExitCode);
    TerminateProcess(pi.hProcess, ExitCode);
    

    That's the easiet way to do what you want.

    Can you believe I can type drunk! :p


  • Closed Accounts Posts: 1,541 ✭✭✭finnpark


    Thanks All,

    Many thanks for that. I will try it out. That is exactly what I am looking for. :)

    Finn


  • Advertisement
Advertisement