Notify Icon and Google Searching!

Started by
6 comments, last by ApochPiQ 18 years, 1 month ago
I am currently writing a program in C# which enables the user to search google for...stuff. This is what happens: Application Runs > Normal Search --> Normal Search Form Launches, with a browser within it. Picture Search --> Picture Search Form Launches, with a browser within it. Now after a lot of problems, I figured out how to get the picture search to work, like this:

public void LaunchImageSearch(string keyword)
{
	ImageResultsWindow ImageResults = new ImageResultsWindow();

	System.Object nullObject = 0;
	string str = "";
	System.Object nullObjStr = str;
	Cursor.Current = Cursors.WaitCursor;
	axWebBrowser1.Navigate("http://images.google.co.uk/images?q=" + keyword + "&hl=en", ref nullObject, ref nullObjStr, ref nullObjStr, ref nullObjStr);
}
//edit: there is a *plus* before and after the keyword string...for some reason the forum cuts it out



private void imageSearchButton_Click(object sender, System.EventArgs e)
{	
	ImageResultsWindow ImageResults = new ImageResultsWindow();
	ImageResults.Show();
	ImageResults.LaunchImageSearch(imageSearchBox.Text);
	this.WindowState = FormWindowState.Minimized;
}


But when I try and attempt to do this with my normal search, where the browser is navigated to the regular Google search bar, it doesn't do anything! Any ideas on this one? Is it possible to search string directly through the URL? Another wee problem is the notify icon. I want it to be possible to minimize the program to the system tray, and it's worked...but this occurs. http://show.imagehosting.us/show/1234810/0/nouser_1234/T0_-1_1234810.JPG It opens it three times! Here is the code: NotifyIcon double click...

private void notifyIcon1_DoubleClick(object sender, System.EventArgs e)
{
	Show();
	WindowState = FormWindowState.Normal;
}


Form Resize...

private void Form1_Resize(object sender, System.EventArgs e)
{
	if (FormWindowState.Minimized == WindowState)
	    Hide();
}


Ho, ho, ho!
Advertisement
It is possible to launch a normal Google search in exactly the same way you're launching the image search; there are some tweaks to the URL but that's about it.

We'll need a little bit more code, though, to really get a proper feel for what's broken. If you could post the "LaunchNormalSearch" code and the code used to set up the notification icon, that'd be very helpful.

Wielder of the Sacred Wands
[Work - ArenaNet] [Epoch Language] [Scribblings]

Quote:Original post by ApochPiQ
It is possible to launch a normal Google search in exactly the same way you're launching the image search; there are some tweaks to the URL but that's about it.

We'll need a little bit more code, though, to really get a proper feel for what's broken. If you could post the "LaunchNormalSearch" code and the code used to set up the notification icon, that'd be very helpful.


Thanks for the reply! I didn't think someone would...here is the code for the LaunchNormalSearch:

public void LaunchNormalSearch(string keyword){	NormalResultsWindow NormalResults = new NormalResultsWindow();	System.Object nullObject = 0;	string str = "";	System.Object nullObjStr = str;	Cursor.Current = Cursors.WaitCursor;         browser.Navigate("http://www.google.co.uk/search?hl=en&q=" + keyword + "&meta=", ref nullObject, ref nullObjStr, ref nullObjStr, ref nullObjStr);}


What I don't understand is if I, for example, enter dog between the two seperated URLs, it works on a browser. And yet it doesn't here, very frustrating.

Any ideas?
Ho, ho, ho!
Best I can figure is some difference between your ImageResultsWindow class and your NormalResultsWindow class. I'd try coping bits of code from ImageResultsWindow over to NormalResultsWindow until it starts working, then re-tweak it as needed.

What are the actual symptoms of the problem? Does the window appear at all? Does the browser go to the wrong page? I'm not entirely clear on what exactly is going wrong.

Wielder of the Sacred Wands
[Work - ArenaNet] [Epoch Language] [Scribblings]

Quote:Original post by ApochPiQ
Best I can figure is some difference between your ImageResultsWindow class and your NormalResultsWindow class. I'd try coping bits of code from ImageResultsWindow over to NormalResultsWindow until it starts working, then re-tweak it as needed.

What are the actual symptoms of the problem? Does the window appear at all? Does the browser go to the wrong page? I'm not entirely clear on what exactly is going wrong.


Sorry, I should have made that clearer.

This is a working version, the "picture search". Notice how the browser searches what the user enters in the textbox.

http://show.imagehosting.us/show/1236959/0/nouser_1236/T0_-1_1236959.JPG

This is the problematic one, instead of searching what was entered in the textbox, it navigates the browser to the Google homepage. (Look at the code I posted earlier, it should work!).

http://show.imagehosting.us/show/1236960/0/nouser_1236/T0_-1_1236960.JPG
Ho, ho, ho!
That looks like what happens if you pass an empty query (for example, navigating to http://www.google.co.uk/search?hl=en&q= redirects you immediately to http://www.google.co.uk/webhp?hl=en which is the home page). Are you sure that the keyword parameter is getting passed correctly? If you display a message box with the keyword in it just before calling browser.Navigate, does it show the correct keyword that was entered?

Wielder of the Sacred Wands
[Work - ArenaNet] [Epoch Language] [Scribblings]

Quote:Original post by ApochPiQ
That looks like what happens if you pass an empty query (for example, navigating to http://www.google.co.uk/search?hl=en&q= redirects you immediately to http://www.google.co.uk/webhp?hl=en which is the home page). Are you sure that the keyword parameter is getting passed correctly? If you display a message box with the keyword in it just before calling browser.Navigate, does it show the correct keyword that was entered?


Found out what it was, I've stupidly forgotten to add the LaunchNormalSearch in my button click eventhandler. Sorry about that, very stupid.

I appreciate all the help, thanks for being patient. :)
Ho, ho, ho!
No worries [smile] Glad you found the culprit.

Those kinds of things are the most annoying mistakes, really. I can't count the number of times I've written a bunch of code, found that it didn't work, spent several hours trying to debug it, and then finally figured out that I was never calling it. Happens to the best of us [depressed]

Wielder of the Sacred Wands
[Work - ArenaNet] [Epoch Language] [Scribblings]

This topic is closed to new replies.

Advertisement