473,396 Members | 1,771 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

FindWindow returning handles of non existant programs

Bob
Hi,
Trying to determine if a program is running or not.
I implemented the example code below but I am getting handles returned
regardless of whether a program exists or not. i.e. You can feed in a
rubbish string for the lpClassName parameter and still get back a long > 0.
What am I doing wrong?
thanks
Bob
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal
_

lpClassName As String, ByVal lpWindowName As String) As Long

Public Function GetHandleByClass(ByVal strTargetProgram As String) As Long

Try

Return FindWindow(strTargetProgram, vbNullString) ' Always returns a large
arbitary number

Catch ex As Exception

MsgBox("Gethandle error " & ex.Message)

End Try

End Function


Nov 21 '05 #1
3 2189
On 2005-08-03, Bob <bo*@nowhere.com> wrote:
Hi,
Trying to determine if a program is running or not.
I implemented the example code below but I am getting handles returned
regardless of whether a program exists or not. i.e. You can feed in a
rubbish string for the lpClassName parameter and still get back a long > 0.
What am I doing wrong?
thanks
Bob
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal
_

lpClassName As String, ByVal lpWindowName As String) As Long


This declaration should be:

Private Declare Auto Function FindWindow Lib "user32" _
(ByVal lpClassName As String, _
ByVal lpWindowName As String) As IntPtr

A long is 64-bits in VB.NET.

--
Tom Shelton [MVP]
Nov 21 '05 #2
Bob
Hi Tom, Thanks for that,
I also found
<DllImport("user32.dll")> Public Shared Function _

FindWindow(ByVal strClassName As String, ByVal strWindowName _

As String) As Integer

Which works.

Is there any .net reference for the WINAPI calls? Guess there must be but I
haven't been able to find it. All the examples I have tried have been from
trolling through the help etc.
regards
bob
"Tom Shelton" <ts******@YOUKNOWTHEDRILLcomcast.net> wrote in message
news:%2******************@TK2MSFTNGP15.phx.gbl...
On 2005-08-03, Bob <bo*@nowhere.com> wrote:
Hi,
Trying to determine if a program is running or not.
I implemented the example code below but I am getting handles returned
regardless of whether a program exists or not. i.e. You can feed in a
rubbish string for the lpClassName parameter and still get back a long > 0. What am I doing wrong?
thanks
Bob
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal _

lpClassName As String, ByVal lpWindowName As String) As Long


This declaration should be:

Private Declare Auto Function FindWindow Lib "user32" _
(ByVal lpClassName As String, _
ByVal lpWindowName As String) As IntPtr

A long is 64-bits in VB.NET.

--
Tom Shelton [MVP]

Nov 21 '05 #3
Hi Bob
Is there any .net reference for the WINAPI calls? Guess there must be but I haven't been able to find it. All the examples I have tried have been from
trolling through the help etc.


Try ApiViewer 2004:

http://www.activevb.de/rubriken/apiv...viewereng.html

It provides declarations of many API functions, constants, and structures in
VB, VB .NET, C# and many more.

For descriptions and samples see API-Guide:

http://www.allapi.net/cgi-bin/redire...place=apiguide

Most samples there are in VB6, but there's some .NET replacement code as
well.

HTH

Roman

Nov 21 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

17
by: lauren quantrell | last post by:
I have an Access application with the name: MyAppName® It has the "®" symbol (ChrW$(&H00AE)) at the end of it. If I remane the application without the "®" symbol, I can use FindWindow to close the...
5
by: Tony | last post by:
I need to send a message to a window in another application. The name of the window is known at design time and set in the constant App2_MONITOR_CAPTION. The message is defined as X_GenerateEvent....
5
by: victor | last post by:
Help .... This is my situation: I've made two apps, a Managed C# and an Unmanaged MFC. The C# app communicates with the MFC-app via (Win32-API) PostMessage, done with the P/Invoke method. One...
3
by: kd | last post by:
Hi All, I need to check whether an application is executing. I do not know the class name of the application; however, I know the window caption of the application. What would be the first...
0
by: ntm | last post by:
Hi all you good m8 I try to make my first small program in vb, but im not very succesfull :D (Im using Visual Studio 2005) Form my own program i will like to set focus on an other running...
0
by: Jim S | last post by:
Is looping FindWindow() ok? We have a simple little c# 2.0 app that’s sole purpose is to look for a dialog box from another app to pop up and then click it’s OK button. To do this we use a...
2
by: Alex | last post by:
Dear coleagues, I am trying to call FindWindow function but it seems not to be working. It returns a loooooong value even if the Window "SoftMaxPro GxP" is not started. I can't even find a...
23
by: pauldepstein | last post by:
Below is posted from a link for Stanford students in computer science. QUOTE BEGINS HERE Because of the risk of misuse, some experts recommend never returning a reference from a function or...
0
by: pipo | last post by:
Hi, When I call FindWindow("SciCalc", null) I always get the same handle back. How can I enumerate through the (open) calculator forms? I dont want to use EnumWindows and check for the handles...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.