• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 459
  • Last Modified:

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.
0
JustinWillis
Asked:
JustinWillis
  • 4
  • 2
  • 2
1 Solution
 
pcsentinelCommented:
Haven't gor messenger running, but have you tried

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

instead

regards
0
 
JustinWillisAuthor Commented:
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?
0
 
JustinWillisAuthor Commented:
Points increased.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
din345Commented:
if you have msn messenger 7.0 the classname is "MSBLWindowClass".

try this:
var ProcessHandle: THandle;
    ExitCode, pid: Cardinal;
begin
  GetWindowThreadProcessId(FindWindow('MSBLWindowClass', nil), @pid);
  ProcessHandle := OpenProcess($0001, FALSE, pid);
  GetExitCodeProcess(ProcessHandle, ExitCode);
  TerminateProcess(ProcessHandle, ExitCode);
  CloseHandle(ProcessHandle);
end;
0
 
pcsentinelCommented:
darn beat me to it

well done din345
0
 
JustinWillisAuthor Commented:
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.
0
 
din345Commented:
 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.
0
 
JustinWillisAuthor Commented:
Thanks for clarifying, it makes sense now.

Cheers,
Justin Willis.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 4
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now