Disappearing MainWindowsTitle property

C

Chris Ullman

I have a piece of VB.NET code (.NET 1.1) that calls a new exe as follows:

Dim fileName = "C:\sample.exe"

newProcess.StartInfo = New System.Diagnostics.ProcessStartInfo(fileName)

newProcess.Start()

newProcess.WaitForInputIdle()

This works fine, and I then call the Windows API for FindWindow as follows,
using the mainWindowTitle property as a parameter:

lnghwnd = FindWindow(vbNullString, newProcess.MainWindowTitle)

This also works fine and it returns the name of the Window for the exe to
FindWindow. However if I call the clipboard before I do this:

Clipboard.SetDataObject("Hello World")

then MainWindowTitle returns nothing. Also MainWindowHandle also returns
nothing. For my application to work, I need to set the clipboard, as the
other application will poll the clipboard for data on start up. Any idea why
the clipboard is causing this behavior? Is it intentional and I can probably
get around it, but I'm just wondering why this behavior should happen.

Regards,

Chris Ullman
 
J

Jeremy

Clipboard.SetDataObject("Hello World")
then MainWindowTitle returns nothing. Also MainWindowHandle also returns
nothing. For my application to work, I need to set the clipboard, as the


Can you post your code (the interesting part)? That sound's really strange,
setting the clipboard should have no effect on FindWindow.
 
C

Chris Ullman

Here's the entire function and associated API calls (the clipboard stuff
was in a separate function originally, I've included it to keep it compact).
The CallMars function is just called from an event handler from a button.
Moving the two lines of clipboard associated code after the FindWindow call
ensures that a value is returned.

Regards,
Chris UllmanPublic Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal
lpClassName As String, ByVal lpWindowName As String) As Integer

Private Declare Function BringWindowToTop Lib "user32.dll" (ByVal hwnd As
Integer) As Integer


Private Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Integer,
ByVal hWndInsertAfter As Integer, ByVal X As Integer, ByVal Y As Integer, _

ByVal cX As Integer, ByVal cY As Integer, ByVal wFlags As Integer) As Long

.....
Public Sub CallMars()

Const HWND_BOTTOM = 1

Const SWP_NOSIZE = &H1

Const SWP_SHOWWINDOW = &H40

Const SWP_NOOWNERZORDER = &H200

Dim t As String = "MemberID=" + ClientLoggedOn.CurrentCall + ";"

Clipboard.SetDataObject(t)

Dim fileName = "C:\sample.exe"

newProcess.StartInfo = New System.Diagnostics.ProcessStartInfo(fileName)

newProcess.Start()

newProcess.WaitForInputIdle()

Dim lnghwnd As Integer

'Find the target

lnghwnd = FindWindow(vbNullString, newProcess.MainWindowTitle)

'Move the target and bring it to the front

SetWindowPos(lnghwnd, HWND_BOTTOM, 10, 5, 675, 625, SWP_SHOWWINDOW)

BringWindowToTop(lnghwnd)

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top