|
|
#1 |
|
Junior Member
Join Date: Jul 06
Posts: 19
![]() |
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 |
|
|
|
|
|
#2 |
|
PowerPoster 2.0
Join Date: Jun 00
Location: Southeastern MI
Posts: 4,329
![]() ![]() ![]() ![]() ![]() ![]() |
Re: [2005] Process.MainWindowTitle
Are you running the actual vb exe or are you running the app from the vb6 ide?
__________________
Negative 0 Blog | RegEx | Encrypting UN/PW in Web.Config | Enabling ASP.Net on IIS 6 | Port Numbers | Creating GUIDs | Start->Run | Modifying the default class |
|
|
|
|
|
#3 |
|
Junior Member
Join Date: Jul 06
Posts: 19
![]() |
Re: [2005] Process.MainWindowTitle
Its the actual compiled vb6 exe.
Cheers |
|
|
|
|
|
#4 |
|
PowerPoster 2.0
Join Date: Jun 00
Location: Southeastern MI
Posts: 4,329
![]() ![]() ![]() ![]() ![]() ![]() |
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.
__________________
Negative 0 Blog | RegEx | Encrypting UN/PW in Web.Config | Enabling ASP.Net on IIS 6 | Port Numbers | Creating GUIDs | Start->Run | Modifying the default class |
|
|
|
|
|
#5 |
|
Junior Member
Join Date: Jul 06
Posts: 19
![]() |
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)
Cheers |
|
|
|
|
|
#6 |
|
Junior Member
Join Date: Jul 06
Posts: 19
![]() |
Re: [2005] Process.MainWindowTitle
Anyone have any suggestions?
|
|
|
|
|
|
#7 |
|
PowerPoster 2.0
Join Date: Jun 00
Location: Southeastern MI
Posts: 4,329
![]() ![]() ![]() ![]() ![]() ![]() |
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.
__________________
Negative 0 Blog | RegEx | Encrypting UN/PW in Web.Config | Enabling ASP.Net on IIS 6 | Port Numbers | Creating GUIDs | Start->Run | Modifying the default class Last edited by Negative0; Feb 12th, 2009 at 08:28 PM. |
|
|
|
|
|
#8 |
|
PowerPoster 2.0
Join Date: Jun 00
Location: Southeastern MI
Posts: 4,329
![]() ![]() ![]() ![]() ![]() ![]() |
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.
__________________
Negative 0 Blog | RegEx | Encrypting UN/PW in Web.Config | Enabling ASP.Net on IIS 6 | Port Numbers | Creating GUIDs | Start->Run | Modifying the default class |
|
|
|
|
|
#9 |
|
PowerPoster 2.0
Join Date: Jun 00
Location: Southeastern MI
Posts: 4,329
![]() ![]() ![]() ![]() ![]() ![]() |
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
__________________
Negative 0 Blog | RegEx | Encrypting UN/PW in Web.Config | Enabling ASP.Net on IIS 6 | Port Numbers | Creating GUIDs | Start->Run | Modifying the default class |
|
|
|
|
|
#10 |
|
Junior Member
Join Date: Jul 06
Posts: 19
![]() |
Re: [2005] Process.MainWindowTitle
Excellent, it works.
Kudos to you Negative. Thankyou very much for your help.
|
|
|
|
![]() |
|
||||||
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|