Click here to Skip to main content
14,334,138 members
Rate this:
Please Sign up or sign in to vote.
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

Rate this:
Please Sign up or sign in to vote.

Solution 1

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

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
   
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.
Member 7935364 1-Jun-11 12:28pm
   
I tried my same code in a new empty project and it worked... then I tried to build my project on release, ran my .exe and it all worked fine. I have no idea why on debug my top screen fails to show everything properly... thanks for the help!
freeluna 20-Jan-17 14:31pm
   
This worked great for me. I am a tiny C compiler fan and ended up writing a routine to launch a web page from the command line in windows (suitable for including in a batch file or as a code example). I had to add shellapi.h and create the shell32.def file to get things to compile, but it worked.

-------------------------------------------------------------------
#include <windows.h>
#include <shellapi.h>
#include <string.h>
#include <ctype.h>

// *************************************************
// *
// * If tiny C had a caps insensitive strstr
// * function, This would not be here. This
// * just sets a string to lower case.
// *
// *************************************************
void strToLower_s(char *dest, char *src, int destsize)
{
while(*src!=0 && destsize>1)
{
*dest = (char)tolower(*src);
destsize--;
dest++;
src++;
}
*dest=(char)0;
return;
}


// *************************************************
// * Main routine
// *
// * Usage: http URL ex: http http://www.google.com - or -
// * http www.google.com
// *
// *************************************************
int main(int argc, char *argv[])
{
HINSTANCE h;
char buff[256];

if(argc != 2) return 1;

strToLower_s(buff,argv[1],256);

// check to see if 'http' is in argv[1].
// if so, assume the passed argument is a complete URL.
// otherwise, strap http onto the front of the argument
// and hope for the best.

if(strstr(buff,"http")==NULL)
{
sprintf(buff,"http://%s",argv[1]);
}
h = ShellExecute(NULL,"open",buff,NULL,NULL, SW_SHOWNORMAL);

return 0;
}

------------------------------------------------------
compiled with tinyCC like this:

tcc http.c -lshell32

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




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100