473,503 Members | 1,697 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

FindWindow is not working

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 window which is open. What am I doing wrong?
Plese help....
Kind regards, Alex
Imports System

Imports System.Data

Imports System.Windows.Forms

Module Module1

'Declaration

Private Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA"
(ByVal lpClassName As String, ByVal lpWindowName As String) As Long

Private Declare Function SendMessage Lib "user32" Alias "SendMessageA"
(ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam
As String) As Long

Private Declare Function RegisterWindowMessage Lib "user32" Alias
"RegisterWindowMessageA" (ByVal msgName As String) As Long

Public Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

Const WM_SETTEXT = 12

'No. of seconds that GetMsgFromPro() will wait before timing out

Dim mcsngMsgTimeout As Single = 600

Sub Main()

Dim sndMsg, inpStr As String

sndMsg = "_"

inpStr = "OK"

Do

Console.WriteLine("Type command")

sndMsg = Console.ReadLine()

GetMsgFromPro(sndMsg)

'SendMsgToProT(sndMsg)

Console.WriteLine("Finish. Press a key to continue or space Q to finish.")

inpStr = Console.ReadLine()

Loop Until inpStr <"Q"

End Sub

Public Function SendMsgToProT(ByVal msgStr As String) As Long

'Function to send windows command to SOftMaxPro application

'This is the primary method of communication between the two processes, on
the same PC

Console.WriteLine("..command sending in progress.Please wait.")

Dim lVal, hWnd, softmaxMsg As Long

hWnd = 0

softmaxMsg = 0

hWnd = FindWindow("SoftMaxPROMainWnd", "SoftMax Pro GxP")

'hWnd = FindWindow(vbNullString, "Notepad")

If hWnd = 0 Then

Console.WriteLine("OK: SoftMax Pro GxP connected.")

'Beep()

Else

softmaxMsg = RegisterWindowMessage("SoftMaxProMsg")

If softmaxMsg = 0 Then

Console.WriteLine("ERROR: SoftMax")

'Beep()

'Beep()

Else

lVal = SendMessage(hWnd, WM_SETTEXT, softmaxMsg, msgStr)

Console.WriteLine("Command " + msgStr + " is sent to SoftMax Pro GxP.")

End If

End If

End Function

Public Function GetMsgFromPro(ByVal strMessage As String) As Long

'First send a request message to the iunstrument and then get

'back a text message from the instrument via the clipboard.

'Wait for a message for up to (mcsngMsgTimeout) seconds before giving up.

Dim strClip As String

Dim sngStart As Integer = New Integer

Dim sngEnd As Integer = New Integer

sngStart = 0

sngEnd = 30

SendMsgToProT(strMessage)

Console.WriteLine("..feedback waiting in progress.Please wait.")

While sngStart < sngEnd

strClip = Clipboard.GetText()

Console.WriteLine(strClip)

sngStart = sngStart + 1

End While

End Function

End Module
Apr 13 '07 #1
2 7851
Dear all,

It works now with new declaration. Integer instead of Long is the solution.

Kind regards, Alex

"Alex" <in********@gmx.chwrote in message
news:O0****************@TK2MSFTNGP02.phx.gbl...
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 window which is open. What am I doing wrong?
Plese help....
Kind regards, Alex
Imports System

Imports System.Data

Imports System.Windows.Forms

Module Module1

'Declaration

Private Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA"
(ByVal lpClassName As String, ByVal lpWindowName As String) As Long

Private Declare Function SendMessage Lib "user32" Alias "SendMessageA"
(ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal
lParam As String) As Long

Private Declare Function RegisterWindowMessage Lib "user32" Alias
"RegisterWindowMessageA" (ByVal msgName As String) As Long

Public Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

Const WM_SETTEXT = 12

'No. of seconds that GetMsgFromPro() will wait before timing out

Dim mcsngMsgTimeout As Single = 600

Sub Main()

Dim sndMsg, inpStr As String

sndMsg = "_"

inpStr = "OK"

Do

Console.WriteLine("Type command")

sndMsg = Console.ReadLine()

GetMsgFromPro(sndMsg)

'SendMsgToProT(sndMsg)

Console.WriteLine("Finish. Press a key to continue or space Q to finish.")

inpStr = Console.ReadLine()

Loop Until inpStr <"Q"

End Sub

Public Function SendMsgToProT(ByVal msgStr As String) As Long

'Function to send windows command to SOftMaxPro application

'This is the primary method of communication between the two processes, on
the same PC

Console.WriteLine("..command sending in progress.Please wait.")

Dim lVal, hWnd, softmaxMsg As Long

hWnd = 0

softmaxMsg = 0

hWnd = FindWindow("SoftMaxPROMainWnd", "SoftMax Pro GxP")

'hWnd = FindWindow(vbNullString, "Notepad")

If hWnd = 0 Then

Console.WriteLine("OK: SoftMax Pro GxP connected.")

'Beep()

Else

softmaxMsg = RegisterWindowMessage("SoftMaxProMsg")

If softmaxMsg = 0 Then

Console.WriteLine("ERROR: SoftMax")

'Beep()

'Beep()

Else

lVal = SendMessage(hWnd, WM_SETTEXT, softmaxMsg, msgStr)

Console.WriteLine("Command " + msgStr + " is sent to SoftMax Pro GxP.")

End If

End If

End Function

Public Function GetMsgFromPro(ByVal strMessage As String) As Long

'First send a request message to the iunstrument and then get

'back a text message from the instrument via the clipboard.

'Wait for a message for up to (mcsngMsgTimeout) seconds before giving up.

Dim strClip As String

Dim sngStart As Integer = New Integer

Dim sngEnd As Integer = New Integer

sngStart = 0

sngEnd = 30

SendMsgToProT(strMessage)

Console.WriteLine("..feedback waiting in progress.Please wait.")

While sngStart < sngEnd

strClip = Clipboard.GetText()

Console.WriteLine(strClip)

sngStart = sngStart + 1

End While

End Function

End Module


Apr 13 '07 #2
"Alex" <in********@gmx.chschrieb:
It works now with new declaration. Integer instead of Long is the
solution.
Note that handles must be declared as 'IntPtr' in order to make the code
work on 64-bit systems.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Apr 13 '07 #3

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

Similar topics

3
20270
by: Otie | last post by:
I found the following under the GetObject help notes and in the example for GetObject: "This example uses the GetObject function to get a reference to a specific Microsoft Excel worksheet...
17
3035
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...
4
2891
by: Olex Malko | last post by:
How to manage FindWindow() function working properly in ASP.NET application? In Windows Forms application it works fine. But in ASP.NET it returns NULL :( Probalby this is because of different...
5
27221
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
7042
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
3086
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...
3
2195
by: Bob | last post by:
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...
0
1534
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...
0
1400
by: Apnea | last post by:
Hi all I am working on a C# application that is launched as a child within a 3rd party application (not .net) my problem is that when i use the any control on the form that inherits from...
0
7199
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
7074
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
7273
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7322
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...
1
6982
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
7451
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
5572
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,...
1
5000
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3161
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...

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.