-
Feb 10th, 2009, 10:02 PM
#1
Thread Starter
Junior Member
[RESOLVED] [2005] Process.MainWindowTitle
Hi Guys,
I have an issue using Process.MainWindowTitle,Process.MainWindowHandle on some older VB6 applications.
After Process.Start I use Process.MainWindowTitle to display in a listbox.
The MainWindowTitle returned is not the Window Title but in fact the Project name of the VB6 exe. ??
I also store the MainWindowHandle to use the ShowWindow and SetForeGroundWindow API's.
It would appear that the ShowWindow API does not work, but the SetForegroundWindow does. ie: if the VB6 app is minimized, showwindow does not restore, if it is NOT minimized setforewgroundwindow sets it to the foreground.
The exact same code does work correctly for any other .net exe or notepad, only on these vb6 programs I am having a problem.
Any ideas or thoughts would be appreciated.
(The code is pretty straight forward, hence i haven't bothered to post it.)
Cheers
-
Feb 10th, 2009, 10:38 PM
#2
Re: [2005] Process.MainWindowTitle
Are you running the actual vb exe or are you running the app from the vb6 ide?
-
Feb 10th, 2009, 10:47 PM
#3
Thread Starter
Junior Member
Re: [2005] Process.MainWindowTitle
Its the actual compiled vb6 exe.
Cheers
-
Feb 10th, 2009, 10:55 PM
#4
Re: [2005] Process.MainWindowTitle
Do you have the code to the apps? Are they doing anything weird with windows messages?
If you post your code, I can test it out on some vb6 apps I have on my machine.
-
Feb 10th, 2009, 11:23 PM
#5
Thread Starter
Junior Member
Re: [2005] Process.MainWindowTitle
I have the source to all apps, certainly nothing weird with Windows messaging.
Below is the code.
The process is passed into the tag property of a button.
Code:
Dim mvk As New Process
Dim sTitle As String = ""
Dim I As Integer = 0
With mvk
.EnableRaisingEvents = True
.StartInfo.FileName = "c:\projects\test\app.exe"
AddHandler mvk.Exited, AddressOf ProcessExit
.Start()
End With
sTitle = mvk.MainWindowTitle
Do Until sTitle <> ""
System.Threading.Thread.Sleep(500)
mvk.Refresh()
sTitle = mvk.MainWindowTitle
I += 1
If I = 20 Then sTitle = "Error"
Loop
Code:
Private SW_SHOWNORMAL As Integer = &H1
<Runtime.InteropServices.DllImport("user32", EntryPoint:="ShowWindow")> _
Private Shared Function ShowWindow(ByVal hwnd As IntPtr, ByVal nCmdShow As Integer) As Integer
End Function
<Runtime.InteropServices.DllImport("user32", EntryPoint:="SetForegroundWindow")> _
Private Shared Function SetForegroundWindow(ByVal hwnd As IntPtr) As Integer
End Function
'The button click event below.
Dim myProc As Process = DirectCast(myButton.Tag, Process)
myProc.Refresh()
ShowWindow(myProc.MainWindowHandle, SW_SHOWNORMAL)
SetForegroundWindow(myProc.MainWindowHandle)
I'll be interested in what see what happens.
Cheers
-
Feb 12th, 2009, 05:24 PM
#6
Thread Starter
Junior Member
Re: [2005] Process.MainWindowTitle
Anyone have any suggestions?
-
Feb 12th, 2009, 08:49 PM
#7
Re: [2005] Process.MainWindowTitle
I am seeing the same behavior that you are. I have been trying with postmessage and other API tricks, but I can't get the main window to show.
Last edited by Negative0; Feb 12th, 2009 at 09:28 PM.
-
Feb 12th, 2009, 09:36 PM
#8
Re: [2005] Process.MainWindowTitle
I am making some progress here. It looks like Process.MainWindowHandle is returing the a different value than what it should.
I launched the app and then used Spy++ to find the window and it gave me a different window handle than what showed up in the MainWindowHandle. I called ShowWindow with that handle and it restored the window properly.
-
Feb 12th, 2009, 10:12 PM
#9
Re: [2005] Process.MainWindowTitle
After doing quite a bit of digging, this is what appears to be happening:
Process.MainWindowHandle is returning the ThunderRT6Main window. From what I understand, that is a hidden window that all vb6 apps have. For some reason when we pass our windows messages to that window, it is not getting passed to the ThunderRT6Form window, which is the actual window on the screen.
So what seems to be working for me is, using GetWindow with the GW_HWNDPREV, which will retreive the window above the passed window in the z-order.
Code:
Declare Auto Function GetWindow Lib "user32.dll" ( _
ByVal hWnd As IntPtr, ByVal uCmd As UInt32) As IntPtr
Const GW_HWNDPREV As Integer = 3
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim vb6Window As IntPtr = GetWindow(mvk.MainWindowHandle, GW_HWNDPREV)
ShowWindow(vb6Window, SW_SHOWNORMAL)
End Sub
Try it out and let me know if it works.
-
Feb 13th, 2009, 12:31 AM
#10
Thread Starter
Junior Member
Re: [2005] Process.MainWindowTitle
Excellent, it works.
Kudos to you Negative.
Thankyou very much for your help.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|