Link to home
Start Free TrialLog in
Avatar of JustinWillis
JustinWillis

asked on

SendMessage Close MSN Messenger

Hello, I am trying to use the following to close MSN Messenger (I want to shut it down altogether if possible or at least stop it working while my app is running).

        SendMessage(FindWindow('MSNMSBLClass','MSN Messenger'),WM_CLOSE,0,0);

Only problem is of course is that it uses OnClose to prevent the close and minimizes to the tray instead.
I have experimented with Destroying it but this is messy and causes errors.

Is there a nice clean way of preventing MSN Messenger from working? or shut it down altogether?

Thanks for any help.
Justin Willis.
Avatar of pcsentinel
pcsentinel

Haven't gor messenger running, but have you tried

        SendMessage(FindWindow('MSNMSBLClass','MSN Messenger'),WM_QUIT,0,0);

instead

regards
Avatar of JustinWillis

ASKER

Yes I have also tried that, doesn't do anything at all, Messenger is resisting, I think I need a way to trigger the Exit option within messenger, or can I send it an application.terminate sort of message in an ideal world?
Points increased.
ASKER CERTIFIED SOLUTION
Avatar of din345
din345

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
darn beat me to it

well done din345
Very cool, thanks a lot din345, I was trying this with version 6.2 and changed the classname to MSNMSBLGeneric which seemed to work a treat but will need to close other versions as well so will check for 7 and earlier, sure it will work fine.

Out of interest what is this actually doing? is this similar to remote application.terminate?

I was trying out wm_destroy before which seemed to take a baseball bat to the apps legs, this also caused other progs to become unstable though (Internet Explorer was a biggy).

Thanks again,
Justin Willis.
 GetWindowThreadProcessId(FindWindow('MSBLWindowClass', nil), @pid);  // here it gets the process ID and stores it in pid
  ProcessHandle := OpenProcess($0001, FALSE, pid); // OpenProcess() returns a handle of the process
  GetExitCodeProcess(ProcessHandle, ExitCode);  // the exitcode is stored in ExitCode and it's used in TerminateProcess()
  TerminateProcess(ProcessHandle, ExitCode); // termiantes the process
  CloseHandle(ProcessHandle);  // closes the handle

> is this similar to remote application.terminate?
i don't know.
Thanks for clarifying, it makes sense now.

Cheers,
Justin Willis.