Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsVB SyntaxEnterprise DevelopmentDatabase AccessControlsCOMWin APICrystal ReportDeploymentGeneralGeneral 2
Related Topics
VB.NET / ASP.NETMS SQL ServerMS AccessOther Database ProductsMore Topics ...

VB Forum / Win API / April 2007



Tip: Looking for answers? Try searching our database.

FindWindow is not working

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Alex - 13 Apr 2007 08:03 GMT
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
J French - 13 Apr 2007 08:15 GMT
>Dear coleagues,
>
[quoted text clipped - 9 lines]
>
>Imports System.Windows.Forms

Almost everybody in this newsgroup is using VB6 or lower. While
you may get a stray answer to VB.NET (including VB2003 and VB2005
which has dropped .NET from its name) questions here, you should
ask them in newsgroups devoted exclusively to .NET programming.
Look for newsgroups with either the word "dotnet" or "vsnet" in
their name.

For the microsoft news server, try these newsgroups...

news://msnews.microsoft.com/microsoft.public.dotnet.general
news://msnews.microsoft.com/microsoft.public.dotnet.languages.vb
news://msnews.microsoft.com/microsoft.public.vsnet.general
news://msnews.microsoft.com/microsoft.public.vstudio.general
news://msnews.microsoft.com/microsoft.public.vstudio.setup
news://msnews.microsoft.public.dotnet.languages.vb.upgrade
news://msnews.microsoft.public.dotnet.languages.vb.controls
news://msnews.microsoft.public.dotnet.languages.vb.data

There are some others, but these should get you started.
Alex - 13 Apr 2007 10:53 GMT
Dear all,

Many Thanks to your great help. It works now with new declaration Long is
not available in vb.net.

Kind regards, Alex

>>Dear coleagues,
>>
[quoted text clipped - 29 lines]
>
> There are some others, but these should get you started.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.