To register for an Internet.com membership to receive newsletters and white papers, use the Register button ABOVE.
To participate in the message forums BELOW, click here
VBForums  

VB Wire News
The ASP.NET Chart Control
Article :: Introduction to SharePoint Development in Visual Studio 2010
Part 10 of the Visual Basic .NET 2010 Express Tutorial Complete!
How to Use the Visual Studio Code Analysis Tool FxCop
Article :: Interview with Andrei Alexandrescu (Part 3 of 3)



Go Back   VBForums > Visual Basic > Visual Basic .NET

Reply Post New Thread
 
Thread Tools Display Modes
Old Feb 10th, 2009, 09:02 PM   #1
Pickles89
Junior Member
 
Join Date: Jul 06
Posts: 19
Pickles89 is an unknown quantity at this point (<10)
Resolved [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
Pickles89 is offline   Reply With Quote
Old Feb 10th, 2009, 09:38 PM   #2
Negative0
PowerPoster 2.0
 
Negative0's Avatar
 
Join Date: Jun 00
Location: Southeastern MI
Posts: 4,329
Negative0 is a glorious beacon of light (400+)Negative0 is a glorious beacon of light (400+)Negative0 is a glorious beacon of light (400+)Negative0 is a glorious beacon of light (400+)Negative0 is a glorious beacon of light (400+)Negative0 is a glorious beacon of light (400+)
Re: [2005] Process.MainWindowTitle

Are you running the actual vb exe or are you running the app from the vb6 ide?
Negative0 is offline   Reply With Quote
Old Feb 10th, 2009, 09:47 PM   #3
Pickles89
Junior Member
 
Join Date: Jul 06
Posts: 19
Pickles89 is an unknown quantity at this point (<10)
Re: [2005] Process.MainWindowTitle

Its the actual compiled vb6 exe.

Cheers
Pickles89 is offline   Reply With Quote
Old Feb 10th, 2009, 09:55 PM   #4
Negative0
PowerPoster 2.0
 
Negative0's Avatar
 
Join Date: Jun 00
Location: Southeastern MI
Posts: 4,329
Negative0 is a glorious beacon of light (400+)Negative0 is a glorious beacon of light (400+)Negative0 is a glorious beacon of light (400+)Negative0 is a glorious beacon of light (400+)Negative0 is a glorious beacon of light (400+)Negative0 is a glorious beacon of light (400+)
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.
Negative0 is offline   Reply With Quote
Old Feb 10th, 2009, 10:23 PM   #5
Pickles89
Junior Member
 
Join Date: Jul 06
Posts: 19
Pickles89 is an unknown quantity at this point (<10)
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
Pickles89 is offline   Reply With Quote
Old Feb 12th, 2009, 04:24 PM   #6
Pickles89
Junior Member
 
Join Date: Jul 06
Posts: 19
Pickles89 is an unknown quantity at this point (<10)
Re: [2005] Process.MainWindowTitle

Anyone have any suggestions?
Pickles89 is offline   Reply With Quote
Old Feb 12th, 2009, 07:49 PM   #7
Negative0
PowerPoster 2.0
 
Negative0's Avatar
 
Join Date: Jun 00
Location: Southeastern MI
Posts: 4,329
Negative0 is a glorious beacon of light (400+)Negative0 is a glorious beacon of light (400+)Negative0 is a glorious beacon of light (400+)Negative0 is a glorious beacon of light (400+)Negative0 is a glorious beacon of light (400+)Negative0 is a glorious beacon of light (400+)
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 08:28 PM.
Negative0 is offline   Reply With Quote
Old Feb 12th, 2009, 08:36 PM   #8
Negative0
PowerPoster 2.0
 
Negative0's Avatar
 
Join Date: Jun 00
Location: Southeastern MI
Posts: 4,329
Negative0 is a glorious beacon of light (400+)Negative0 is a glorious beacon of light (400+)Negative0 is a glorious beacon of light (400+)Negative0 is a glorious beacon of light (400+)Negative0 is a glorious beacon of light (400+)Negative0 is a glorious beacon of light (400+)
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.
Negative0 is offline   Reply With Quote
Old Feb 12th, 2009, 09:12 PM   #9
Negative0
PowerPoster 2.0
 
Negative0's Avatar
 
Join Date: Jun 00
Location: Southeastern MI
Posts: 4,329
Negative0 is a glorious beacon of light (400+)Negative0 is a glorious beacon of light (400+)Negative0 is a glorious beacon of light (400+)Negative0 is a glorious beacon of light (400+)Negative0 is a glorious beacon of light (400+)Negative0 is a glorious beacon of light (400+)
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.
Negative0 is offline   Reply With Quote
Old Feb 12th, 2009, 11:31 PM   #10
Pickles89
Junior Member
 
Join Date: Jul 06
Posts: 19
Pickles89 is an unknown quantity at this point (<10)
Re: [2005] Process.MainWindowTitle

Excellent, it works.
Kudos to you Negative.

Thankyou very much for your help.
Pickles89 is offline   Reply With Quote
Reply

Go Back   VBForums > Visual Basic > Visual Basic .NET


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -5. The time now is 08:34 PM.





Acceptable Use Policy

Internet.com
The Network for Technology Professionals

Search:

About Internet.com

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers

Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.