Browser Help

This is a discussion on Browser Help within the Windows Programming forums, part of the Platform Specific Boards category; Hello, I am new to programming and I am trying to write a program that will open Internet Explorer and ...

  1. #1
    Registered User mach5's Avatar
    Join Date
    Feb 2003
    Posts
    7

    Browser Help

    Hello,

    I am new to programming and I am trying to write a program that will open Internet Explorer and then add text to an input box and then press enter... here is an example:

    #include <stdio.h>
    #include <stdlib.h>

    int main()
    {

    int open_ie;

    open_ie = system("IEXPLORE.EXE www.google.com");


    When the window opens, I would like to add text to googles input box and press enter. I have tried using fputs(), but I don't think that I am targeting the open window properly (or if fputs() is even correct). I'm not sure how to press enter, or automate any keyboard functionality.

    I understand, by reading the FAQ, that ShellExecute() would be a better option than using system(), but I have used system() in the past on Linux machines and I'm a little more familiar (emphasis on little).

    Language: C
    OS: Windows 2000
    Compilier: Turbo C

    Any advice would be very helpful.

  2. #2
    Registered User mach5's Avatar
    Join Date
    Feb 2003
    Posts
    7
    Thank you for moving this thread to the correct board, and for supplying the link for a Windows compilier.

    I am working with visual c++ to get a better handle on Windows programming. I'm sure I'll have additional questions soon...

    Thanks

  3. #3
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,789
    Even with a windows compiler, you are going about this the wrong way IMO

    Easier way is to build the URL to search google with and call ShellExecute on it - like so

    Code:
    #include <windows.h>
    #include <string>
    #include <iostream>
    
    
    int main()
    {
    
    	std::string strGooglePath = "http://www.google.com/search?q=";
    	
    	std::cout << "Enter what you want to search for" << std::endl;
    	char szToken[256];
    	std::cin.getline(szToken,255);
    	strGooglePath += szToken;
    
    	ShellExecute(0,"open",strGooglePath.c_str(),0,0,SW_SHOW);	
    	return 0;
    }

  4. #4
    Registered User mach5's Avatar
    Join Date
    Feb 2003
    Posts
    7
    Fordy,

    Thanks for the reply and the code example; it's really helpful.

    Just to clarify, the opening of the browser and searching Google is just an example. I have been following another thread which seems to be more along the lines of what I'm trying to accomplish:

    SendInput()?

    Just to alter your code a bit...

    #include <windows.h>
    #include <string>
    #include <iostream>


    int main()
    {

    std::string strGooglePath = "http://www.google.com";

    ShellExecute(0,"open",strGooglePath.c_str(),0,0,SW _SHOW);
    return 0;
    }

    ... I would like to send keystokes to the window -- in this case, sending text to Google's input box and pressing enter. Sorry, my original question was not very clear.

    I'm going to try WM_COPYDATA or one of the other options from the above thread.

    Thanks again.

  5. #5
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,789
    Ok....but the instant problem you have is that to send info that matters (keystrokes, mouse gestures) you need to know where to send it - for example a specific button or edit control. You can find this stuff with FindWindow() to get the window for IE...then FindWindowEx recursively to find the control you want to play with.

    But as web content changes to much, you may find as soon as your prog is set, they change the webpage and your prog doesnt work!

  6. #6
    Registered User mach5's Avatar
    Join Date
    Feb 2003
    Posts
    7
    Thank you for this information, you are pointing me in the right direction. I have a small test script and I am using with FindWindow() and SendMessage(). I am able to find the window, but cannot seem to send a message to the window with the SendMessage() function.

    Here is the code:
    Code:
    #include <windows.h>
    #include <string>
    #include <iostream>
    
    
    int main()
    {
        std::string strGooglePath = "http://www.google.com";
        ShellExecute(0,"open",strGooglePath.c_str(),0,0,SW_SHOW);
    
        Sleep(5000);
    
        HWND OpenGoogle = FindWindow(0, "Google - Microsoft Internet Explorer");
    
        if(OpenGoogle != NULL)
          SendMessage(OpenGoogle, WM_CLOSE, 0, 0);
        else
          std::cout << "Could not locate window" << std::endl;
        return 0;
    }

    Just for test purposes, I wanted to find the window, then close it. I have tested the code with:

    if(OpenGoogle != NULL)
    std::cout << "Found the window" << std::endl;
    else
    std::cout << "Could not locate window" << std::endl;

    "Found the window" is displayed. I seem to be having a problem with the SendMessage() function. Do you notice anything that I am doing wrong?

    Thanks for your help Fordy.
    Last edited by mach5; 02-25-2003 at 02:36 AM.

  7. #7
    Registered User mach5's Avatar
    Join Date
    Feb 2003
    Posts
    7
    My mistake, it works.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Internet Browser Handling
    By pobri19 in forum Windows Programming
    Replies: 9
    Last Post: 04-04-2009, 07:19 AM
  2. Browser speed
    By KroniskBakfylla in forum A Brief History of Cprogramming.com
    Replies: 9
    Last Post: 03-24-2009, 01:49 PM
  3. Getting Default Browser and Running It
    By Driver in forum Windows Programming
    Replies: 4
    Last Post: 10-22-2004, 03:08 PM
  4. Replies: 4
    Last Post: 05-28-2002, 07:19 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21