Click here to Skip to main content
15,887,336 members
Please Sign up or sign in to vote.
4.50/5 (2 votes)
See more:
Hi,

I'm trying to set up a ShellExecute so that when I click on a tray icon, it opens up a new page on the default browser.

I have the following code :
HINSTANCE hInst = ShellExecute(0, "open", server_url,NULL, NULL ,SW_SHOWNORMAL);

with server_url being the url of the website that I wish to go to.

Problem is, if I do it when my browser is already open, it opens up fine with no problem. If I try to do it when my browser is not already open, it opens up but the top bar with the back/next button and the minizime, maximize and close buttons are not there. Anyone else had this problem?

Thanks!
Posted
Updated 31-May-11 10:25am
v5
Comments
Manfred Rudolf Bihy 31-May-11 15:57pm    
Please edit your question with improve question as there seems to be some part missing between "NULL NULL". It maybe only a comma to separate the two parameters, but since it is your code I'll just pass on the guessing game today!
To edit your question please use the "Improve question" link that is located on the right bottom side underneath your question.

Thank you for your attention!

1 solution

Seems that I have found something that might fix your problem:

C++
LONG r = ShellExecute(NULL, "open", "http://www.microsoft.com", NULL, NULL, SW_SHOWNORMAL);


The probelm seems to lie with your parameter being SW_SHOWDEFAULT whereas the MSDN sample I found at http://support.microsoft.com/kb/224816/en-us[^] uses SW_SHOWNORMAL.
You can find an explanation for all the applicable parameters on MSDN: http://msdn.microsoft.com/en-us/library/bb762153(v=vs.85).aspx[^]. This site goes on to explain:

SW_SHOWDEFAULT (10)
Sets the show state based on the SW_ flag specified in the STARTUPINFO structure passed to the CreateProcess function by the program that started the application. An application should call ShowWindow with this flag to set the initial show state of its main window.
SW_SHOWNORMAL (1)
Activates and displays a window. If the window is minimized or maximized, Windows restores it to its original size and position. An application should specify this flag when displaying the window for the first time.

I'm not quite sure if that really solves your problem, but I think you should try your code and substitute SW_SHOWDEFAULT with SW_SHOWNORMAL.

Best regards,

-MRB
 
Share this answer
 
Comments
Member 7935364 31-May-11 16:24pm    
Thank you for your solution, but my ShellExecute still has the same behavior :(
Sergey Alexandrovich Kryukov 31-May-11 17:01pm    
So, why do you think it's wrong?
--SA
Member 7935364 31-May-11 18:58pm    
I have absolutely no idea, I've searched for an hour on the web and couldn't find anyone else with the same problem. Maybe I should use something else than ShellExecute.
Sergey Alexandrovich Kryukov 31-May-11 17:01pm    
All correct, my 5.
--SA
Chandrasekharan P 1-Jun-11 0:06am    
Hi Member, I dont see anything wrong with what MRB responded.. i tried it out and worked the way it should.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900