How to use PostThreadMessage to close Internet Explorer from C ++
I am trying to start iexplore.exe
to start it for 5 seconds and then close it again.
iexplore
opens just fine, but doesn't close when I call PostThreadMessage. Can anyone see what I am doing wrong? Here is my code:
CString IEPath = "C:\\Program Files\\Internet Explorer\\IEXPLORE.EXE";//GetIEPath();
//IEPath += ' ' + url;
std::string strCommand((LPCTSTR)IEPath);
PROCESS_INFORMATION procinfo;
STARTUPINFO startupinfo;
GetStartupInfo(&startupinfo);
CreateProcess(
NULL,
(char *)strCommand.c_str(),// name of executable module
NULL, // lpProcessAttributes
NULL, // lpThreadAttributes
false, // handle inheritance option
CREATE_SHARED_WOW_VDM, // creation flags
NULL, // new environment block
NULL, // current directory name
&startupinfo, // startup information
&procinfo // process information
);
Sleep(5000);
::PostThreadMessage(procinfo.dwThreadId, WM_QUIT, 0, 0); //<---Dosent Close internet explorer!
Does anyone have any idea what I am doing wrong? Or is there a better way to do the trick?
source to share
I have no answer why PostThreadMessage is not working. But perhaps if you clarify why you want to do this, is there a better solution?
For example, if you just want to show a web page for 5 seconds, you can create and show your own window with the built-in Internet Explorer ActiveX control. You will also be able to add a listener to detect when a web page is loaded in an ActiveX control so that you only start your 5 second counter after the web page is loaded and rendered.
source to share
I ended up doing the enumeration of windows (as the serval of you mentioned what I should do) I was inspired by http://simplesamples.info/Windows/EnumWindows.php .
source to share
Do not use PostThreadMessage (), which sends a message to a specific thread in the target process instead of the "Message Message Pump" process. Use PostMessage () or SendMessage () instead, which puts the message into the target Windows Message Pump process - which is exactly what you want.
source to share