Environment: Visual C++
Introduction
The Vice President (academic) of Valley View University (in Ghana) wanted me to develop a software application to monitor the transactions that go on in our newly established Internet cafe center.
The problem definition or specification requires launching and closing the IE from the application. Initially, I decided to create a custom browser, but I felt it would be more convient to use the standard browser. The ShellExecute() function could launch the IE from my program, but what about closing the IE from my program? With the help of MSDN, I found that the BroadcastSystemMessage() fuction could do the job. For more on BroadcastSystemMessage(), check MSDN.
I chose BSF_POSTMESSAGE, WM_CLOSE, BSM_APPLICATIONS, NULL, and NULL as parameters of BroadcastSystemMessage() function.
The codes are below:
/*lounching IE, you need an html file on your pc or if you have access to the net you can use a remote address*/ void lounchIE() { HWND h=FindWindowEx(NULL,NULL,NULL, "Microsoft Internet Explorer") ; ShellExecute(h,"open","C:\simple.html", NULL,NULL,SW_SHOWNORMAL); } //closing IE and all applications void CloseIE() { int app=BSM_APPLICATIONS; unsigned long bsm_app=(unsigned long )app; BroadcastSystemMessage(BSF_POSTMESSAGE,&bsm_app, WM_CLOSE,NULL,NULL); }
Problem: The shot-down window may display. When you choose Cancel, you can only run your application from the icons of the applications on the Desktop.