For Programmers: Free Programming Magazines  


Home > Archive > VC Language > November 2005 > WM_CLOSE









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author WM_CLOSE
ama

2005-11-20, 9:59 pm

hi

i wrote a small program that runs a timer
to look for windows of a specific class.

The window belongs to another program.

When the window exists i need to kill it.

I know i cant use WM_DESTROY because
its another thread. So i tried WM_CLOSE
but the other program crashes.
The window i send a WM_CLOSE to is a
popup , not the main window of the other
application.

Am i supposed to do something extra , like
another message or something ?

thanks





William DePalo [MVP VC++ ]

2005-11-20, 9:59 pm

"ama" <a.m.a@videotron.ca> wrote in message
news:_6agf.43$u%2.6283@weber.videotron.net...
> When the window exists i need to kill it.
>
> I know i cant use WM_DESTROY because
> its another thread. So i tried WM_CLOSE
> but the other program crashes.
> The window i send a WM_CLOSE to is a
> popup , not the main window of the other
> application.
>
> Am i supposed to do something extra , like
> another message or something ?


There is no guaranteed way to close cleanly an arbitrary application.

You can try search for a (I didn't say _the_) main window and sending it a
WM_SYSCOMMAND/SC_CLOSE, WM_ENDSESSION or WM_CLOSE but nothing is guaranteed.

Regards,
Will


Tim Roberts

2005-11-21, 4:00 am

"ama" <a.m.a@videotron.ca> wrote:
>
>i wrote a small program that runs a timer
>to look for windows of a specific class.
>
>The window belongs to another program.
>
>When the window exists i need to kill it.
>
>I know i cant use WM_DESTROY because
>its another thread. So i tried WM_CLOSE
>but the other program crashes.
>The window i send a WM_CLOSE to is a
>popup , not the main window of the other
>application.
>
>Am i supposed to do something extra , like
>another message or something ?


It's unusual that WM_CLOSE would cause a crash. How are you sending it?
Simple SendMessage?

Is this a window that you can close by clicking the X icon? If so, then
you can try sending a WM_SYSCOMMAND with SC_CLOSE.
--
- Tim Roberts, timr@probo.com
Providenza & Boekelheide, Inc.
ama

2005-11-21, 4:00 am



>
> There is no guaranteed way to close cleanly an arbitrary application.
>
> You can try search for a (I didn't say _the_) main window and sending it a
> WM_SYSCOMMAND/SC_CLOSE, WM_ENDSESSION or WM_CLOSE but nothing is
> guaranteed.
>
> Regards,
> Will
>


Thanks a lot..

I was thinking to try using EnumThreadWindows to be more
efficient. How do i get the threadID from the other application ?

thanks again


Igor Tandetnik

2005-11-21, 7:58 am

"ama" <a.m.a@videotron.ca> wrote in message
news:7pdgf.7926$u%2.98490@weber.videotron.net
> I was thinking to try using EnumThreadWindows to be more
> efficient. How do i get the threadID from the other application ?


What do you already know about that other application?
--
With best wishes,
Igor Tandetnik

With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925


ama

2005-11-21, 7:04 pm


> I was thinking to try using EnumThreadWindows to be more
> efficient. How do i get the threadID from the other application ?


ok i found it, GetWindowThreadProcessId


ama

2005-11-21, 7:04 pm


> It's unusual that WM_CLOSE would cause a crash. How are you sending it?
> Simple SendMessage?
>
> Is this a window that you can close by clicking the X icon? If so, then
> you can try sending a WM_SYSCOMMAND with SC_CLOSE.
> --
> - Tim Roberts


The SC_CLOSE works good. Thanks guys.

The windows appear to have been made
with ATL. Using Spy++ and looking at the
info on those. At first i thought i might have
to use EndDialog but SC_CLOSE is fine.

....





William DePalo [MVP VC++ ]

2005-11-21, 7:04 pm

"Tim Roberts" <timr@probo.com> wrote in message
news:oco2o117c4hqhqdl9ngnpbuiblhomsblmu@
4ax.com...
> It's unusual that WM_CLOSE would cause a crash. How are you sending it?
> Simple SendMessage?


I _think_ that he is sending the close message to a popup and that some
other code does something bad when its assumption that the popup is present
is faulty. I could be wrong.

Regards,
Will


ama

2005-11-21, 7:04 pm



>
> I _think_ that he is sending the close message to a popup and that some
> other code does something bad when its assumption that the popup is
> present is faulty. I could be wrong.


> Will


I was using SendMessage. Then changed to PostMessage.

When i call the EnumThreadWindows for the other Program,
I close the windows if their class names are specific kinds but,
I wonder if its possible that i may be asking it to close itself
before it has had a change to fully construct itself. This is
why i decided to go with PostMessage. Then again i may be
completely off track here.



William DePalo [MVP VC++ ]

2005-11-21, 9:58 pm

"ama" <a.m.a@videotron.ca> wrote in message
news:MKsgf.19518$u%2.477282@weber.videotron.net...
> When i call the EnumThreadWindows for the other Program,
> I close the windows if their class names are specific kinds but,
> I wonder if its possible that i may be asking it to close itself
> before it has had a change to fully construct itself.


Well, the call to CreateWindow[Ex]() sends the window a WM_CREATE message.
The handler for WM_CREATE returns status which can be used to fail the
create. Once WM_CREATE has been processed the window should be fully
constructed. There may be a _small_ timing window while the handler for
WM_CREATE is running, I don't know. I doubt though that that would be your
problem.

Regards,
Will


Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com