Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsVB SyntaxEnterprise DevelopmentDatabase AccessControlsCOMWin APICrystal ReportDeploymentGeneralGeneral 2
Related Topics
VB.NET / ASP.NETMS SQL ServerMS AccessOther Database ProductsMore Topics ...

VB Forum / Win API / July 2008



Tip: Looking for answers? Try searching our database.

determine invalid window process

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
X. Zhang - 25 Jul 2008 21:02 GMT
I encountered a strange problem. I have an VB6 Form application. Sometimes,
for some reasons, say crashing, the application stays in the memory (can be
seen in Processes list of Task Manager), but it cannot be activated, and
cannot "Switch to" using Task Manager, even though the call FindWindow DOES
return the window handle. (I call it ghost.) I'm able to kill the ghosts AND
OTHERS from other application, but I do NOT want to kill the innocent (normal
status, that is, window can be activated). So my question, how to determine
the GHOST window application like this?

Thanks in advance.
MikeD - 25 Jul 2008 21:12 GMT
>I encountered a strange problem. I have an VB6 Form application. Sometimes,
> for some reasons, say crashing, the application stays in the memory (can be
[quoted text clipped - 4 lines]
> status, that is, window can be activated). So my question, how to determine
> the GHOST window application like this?

Perhaps should focus your attention on WHY your app crashes and fix it?

Signature

Mike
Microsoft Visual Basic MVP

X. Zhang - 26 Jul 2008 18:05 GMT
First of all, I "have" this application does not mean I "build" it.
Secondly, "for some reasons", not only crashing. I believe "say" means "for
example".
Believe me, if I could I would fix the crashing.
Thanks for your reply anyway.

> >I encountered a strange problem. I have an VB6 Form application. Sometimes,
> > for some reasons, say crashing, the application stays in the memory (can be
[quoted text clipped - 6 lines]
>
> Perhaps should focus your attention on WHY your app crashes and fix it?
expvb - 26 Jul 2008 20:57 GMT
>I encountered a strange problem. I have an VB6 Form application. Sometimes,
> for some reasons, say crashing, the application stays in the memory (can
[quoted text clipped - 11 lines]
>
> Thanks in advance.

The window is not gone, just hidden. Since you were able to use FindWindow,
use IsWindowVisible() to if the window is hidden, then use
GetWindowThreadProcessId() to get the process ID, then use
OpenProcess/TerminateProcess/CloseHandle to terminate it.

This can be a normal behavior for some applications so you don't kill every
application that has a hidden window. Some examples include tray
applications.

If the title changes often, google FindWindowLike() to get hWnd.
X. Zhang - 28 Jul 2008 14:50 GMT
Thanks, expvb.
I tried IsWindowVisible(hwnd), but it always returned 0, even if the main
window was visible.
I even tried lRet = GetWindowLong(hwnd, GWL_STYLE), and then check the value
of (lRet And WS_VISIBLE). It's 0 too, even when the main window was visible.
So weird.
Any ideas?

> >I encountered a strange problem. I have an VB6 Form application. Sometimes,
> > for some reasons, say crashing, the application stays in the memory (can
[quoted text clipped - 22 lines]
>
> If the title changes often, google FindWindowLike() to get hWnd.
expvb - 29 Jul 2008 17:57 GMT
> Thanks, expvb.
> I tried IsWindowVisible(hwnd), but it always returned 0, even if the main
[quoted text clipped - 5 lines]
> So weird.
> Any ideas?

IsWindow() should tell if the handle is a valid hWnd. It's possible that the
window has width and height of 0, or moved off screen. Use Spy++ to see the
screen coordinates. If you don't have Spy++, use this free alternative:

http://www.windows-spy.com
X. Zhang - 29 Jul 2008 20:37 GMT
Yes, I did try IsWindow() and returned 1
Spy++ showed:
   Handle: 00CB0BF2
   Caption: "Project Navigator (TIMS)"
   Class: ThunderRT6FormDC
   Style: 16CF0000
   Rect: (178, 36) - (1212, 848) 1034x812
It seems all good to me.
But IsWindowVisible() returned 0!

> > Thanks, expvb.
> > I tried IsWindowVisible(hwnd), but it always returned 0, even if the main
[quoted text clipped - 11 lines]
>
> http://www.windows-spy.com
X. Zhang - 29 Jul 2008 20:56 GMT
Further to my last post, I tested again and found the following facts:

hWnd = FindWindow(vbNullString, "Project Navigator")
'hwnd=3803704 returned
bVisible = IsWindowVisible(hWnd)
'bVisible=False returned

But Spy++ returned different Handle, 00690BC4 (6884292); then tried
bVisible = IsWindowVisible(6884292)
'bVisible=True returned.

Somehow, my FindWindow() call returned wrong window handle, even though
IsWindow() returned True. Anything wrong with my call hWnd =
FindWindow(vbNullString, "Project Navigator")? Here the real window title
always starts with "Project Navigator", but has more characters appending to
it.

Thanks,

> > Thanks, expvb.
> > I tried IsWindowVisible(hwnd), but it always returned 0, even if the main
[quoted text clipped - 11 lines]
>
> http://www.windows-spy.com
Ed - 30 Jul 2008 05:49 GMT
AFAIK FindWindow only returns a non-zero value if it finds a direct
match, so you may have another window/dialog with just the name "Project
Navigator" in it.

Use the complete title name, and if it changes then you'll need to
enumerate the windows and pick the one you need to get the correct
handle, one easy way is to use a sub called FindWindowLike you can find
on MS site and other sites.

>Further to my last post, I tested again and found the following facts:
>
[quoted text clipped - 30 lines]
>>
>> http://www.windows-spy.com
X. Zhang - 30 Jul 2008 14:43 GMT
Problem solved. Many thanks to expvb and Ed.

> I encountered a strange problem. I have an VB6 Form application. Sometimes,
> for some reasons, say crashing, the application stays in the memory (can be
[quoted text clipped - 6 lines]
>
> Thanks in advance.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.