473,651 Members | 2,663 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 "FindWindow A"
(ByVal lpClassName As String, ByVal lpWindowName As String) As Long

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

Private Declare Function RegisterWindowM essage Lib "user32" Alias
"RegisterWindow MessageA" (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.WriteLi ne("Type command")

sndMsg = Console.ReadLin e()

GetMsgFromPro(s ndMsg)

'SendMsgToProT( sndMsg)

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

inpStr = Console.ReadLin e()

Loop Until inpStr <"Q"

End Sub

Public Function SendMsgToProT(B yVal 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.WriteLi ne("..command sending in progress.Please wait.")

Dim lVal, hWnd, softmaxMsg As Long

hWnd = 0

softmaxMsg = 0

hWnd = FindWindow("Sof tMaxPROMainWnd" , "SoftMax Pro GxP")

'hWnd = FindWindow(vbNu llString, "Notepad")

If hWnd = 0 Then

Console.WriteLi ne("OK: SoftMax Pro GxP connected.")

'Beep()

Else

softmaxMsg = RegisterWindowM essage("SoftMax ProMsg")

If softmaxMsg = 0 Then

Console.WriteLi ne("ERROR: SoftMax")

'Beep()

'Beep()

Else

lVal = SendMessage(hWn d, WM_SETTEXT, softmaxMsg, msgStr)

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

End If

End If

End Function

Public Function GetMsgFromPro(B yVal 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 (mcsngMsgTimeou t) 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(s trMessage)

Console.WriteLi ne("..feedback waiting in progress.Please wait.")

While sngStart < sngEnd

strClip = Clipboard.GetTe xt()

Console.WriteLi ne(strClip)

sngStart = sngStart + 1

End While

End Function

End Module
Apr 13 '07 #1
2 7876
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******** ********@TK2MSF TNGP02.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 "FindWindow A"
(ByVal lpClassName As String, ByVal lpWindowName As String) As Long

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

Private Declare Function RegisterWindowM essage Lib "user32" Alias
"RegisterWindow MessageA" (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.WriteLi ne("Type command")

sndMsg = Console.ReadLin e()

GetMsgFromPro(s ndMsg)

'SendMsgToProT( sndMsg)

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

inpStr = Console.ReadLin e()

Loop Until inpStr <"Q"

End Sub

Public Function SendMsgToProT(B yVal 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.WriteLi ne("..command sending in progress.Please wait.")

Dim lVal, hWnd, softmaxMsg As Long

hWnd = 0

softmaxMsg = 0

hWnd = FindWindow("Sof tMaxPROMainWnd" , "SoftMax Pro GxP")

'hWnd = FindWindow(vbNu llString, "Notepad")

If hWnd = 0 Then

Console.WriteLi ne("OK: SoftMax Pro GxP connected.")

'Beep()

Else

softmaxMsg = RegisterWindowM essage("SoftMax ProMsg")

If softmaxMsg = 0 Then

Console.WriteLi ne("ERROR: SoftMax")

'Beep()

'Beep()

Else

lVal = SendMessage(hWn d, WM_SETTEXT, softmaxMsg, msgStr)

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

End If

End If

End Function

Public Function GetMsgFromPro(B yVal 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 (mcsngMsgTimeou t) 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(s trMessage)

Console.WriteLi ne("..feedback waiting in progress.Please wait.")

While sngStart < sngEnd

strClip = Clipboard.GetTe xt()

Console.WriteLi ne(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
20275
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 (MyXL). It uses the worksheet's Application property to make Microsoft Excel visible, to close it, and so on. Using two API calls, the DetectExcel Sub procedure looks for Microsoft Excel, and if it is running, enters it in the Running Object Table. The...
17
3056
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 application, but with the "®" symbol it doesn't. Unfortunaetley this app is already distributed as MyAppName® and I cannot change it. I have tried: hwnd = FindWindow(vbNullString, "myAppName" & ChrW$(&H00AE)) But it won't work. Yikes.
4
2908
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 context. Something like IIS is ran under other account or some services cannot interact with desktop. What exactly should be done to have it working? Thank you!
5
27269
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. The following VB6 code works. I assume this is possible in C#. How do you do it? Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
5
7052
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 of the activities is "FindWindow". Everything works fine. Until ...: I needed the same procedure within another context: now I need to communicate the C# with a web service (dll) running somewhere on a Server machine. This doesnot work anymore!
3
3094
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 parameter that I should be passing to the FindWindow API, in order to check whether the application is executing? Thanks. kd
3
2209
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 rubbish string for the lpClassName parameter and still get back a long > 0. What am I doing wrong? thanks Bob Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal _
0
1551
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 form with a timer control and some unmanaged code. The app works perfectly in test but I’m concerned about long term problems/leaks caused by frequent FindWindow calls (10 per second)? Although the popups might only occur 50-100 times a day,...
0
1410
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 toolstrip the buttons that i add do not do anything. they paint etc ok but no event gets fired. I am relatively new to C# and am just finding my feet. I am grateful
0
8802
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8465
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7297
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6158
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5612
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4144
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4283
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2699
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1587
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.