-
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.
-
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
-
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;
}
-
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:
http://cboard.cprogramming.com/showt...threadid=34753
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.
-
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!
-
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.
-