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 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
"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/> This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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...
|
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...
|
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...
|
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....
|
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...
| |
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...
|
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...
|
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...
|
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...
|
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,...
|
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...
| |
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,...
|
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...
|
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...
|
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...
|
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: 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...
| |
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...
| |