By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,446 Members | 3,090 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,446 IT Pros & Developers. It's quick & easy.

FindWindow is not working

P: n/a
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
Share this Question
Share on Google+
2 Replies


P: n/a
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

P: n/a
"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 discussion thread is closed

Replies have been disabled for this discussion.