Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

FindWindow and changing class names afx:

Status
Not open for further replies.

EDHills

Programmer
Jan 24, 2007
35
US
I've actually found this problem defined a few times on the internet, but without a solution! doh!

I need to detect whether an incompatible app is running and prompting first, shut it down if the user wants to do so and run my app now. FindWindow needs either the caption, or the class name and, since the caption always changes, I looked at the class name in Spy++, but the problem is that the last set of numbers always changes!

Afx:400000:b:10033:6:650a27
Afx:400000:b:10033:6:32c356


I didn't write the app that I'm trying to shutdown, so I can't change the class name. I'm frustrated and have been digging for hours to no avail. Any ideas? thanks in advance
 
Couple of ways to do this. If something within the caption is always the same you could build a FindWindowLike function; this accepts wildcard characters as well. There are some on the net, do a search for findwindowlike.

Another way is using the process.getprocessname("process.exe") to get the handle and then shutdown that handle.

Another way is no matter how often the class name changes, programs always run and create window handles in the same structure. Map out the structure with Spy++ using a combination of GetWindow((FindWindowLike(0,"**Window**,*),GW_CHILD)) and
GetWindow((FindWindowLike(0,"**Window**,*),GW_HWNDNEXT)). Make sure you declare GW_CHILD as
Public Const GW_CHILD As Integer = 5
and GW_HWNDNEXT as
Public Const GW_HWNDNEXT As Integer = 2.

Once you know what position the main handle is always in, you can use that handle to shutdown the program.

Spy++ is helpful tool!! Hope this helps.
~CIAO~
 
thanks for your help arznrchrd
I'd already looked at findwindowlike but didn't stare at it hard enough to figure it out until after you motivate me to do so. Guess what? my typical luck... the classname that I was searching for is used by other programs from different manufacturers!

I used this pattern.. "Afx:400000:b:10011:6:*"

If you have an idea how to get the exe name from the windows handle.. feel free ;)
(meanwhile I keep digging)

thanks again
 
painful it took so long, but here is the net result. Maybe it'll help someone someday

thanks again arznrchrd

function IsProgRunning() as BOOLEAN
Dim bMyPname as BOOLEAN = false
Dim sb As String
Dim ps() As Process = Process.GetProcesses()
Dim p As Process
For Each p In ps
If (p.ProcessName Like "PNAME") Then
bMyPname = True
End If
Next
Return bMyPname
end function
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top