Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

Opening a web page from C or C++

  • 19-03-2005 04: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, Registered Users 2 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, Registered Users 2 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