A
Alex
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
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