Results 1 to 5 of 5

Thread: BringWindowToTop Lib "user32" process handling... [RESOLVED]

  1. #1

    Thread Starter
    Fanatic Member Ruku's Avatar
    Join Date
    Jul 2002
    Location
    Canada
    Posts
    655

    Resolved BringWindowToTop Lib "user32" process handling... [RESOLVED]

    I've been using API to bring a window to the foreground but it's not working if it's outside my app... uh, WHY?

    VB Code:
    1. Module modWindow
    2.     'Declare API Function
    3.     Private Declare Function BringWindowToTop Lib "user32" (ByVal hwnd As Long) As Long
    4.  
    5.     Public Sub SelectWindow(ByVal hwnd As Long)
    6.         'Bring target window to front
    7.         BringWindowToTop(hwnd)
    8.     End Sub
    9.  
    10.     Public Sub proTst(ByVal AppID As Integer)
    11.         Dim p As System.Diagnostics.Process
    12.         SelectWindow(Convert.ToInt32(p.GetProcessById(AppID).Handle))
    13.     End Sub
    14. End Module

    Not working... :s! But the API function works fine with let's say the handle of a form inside my app.... very odd...
    Last edited by Ruku; Nov 10th, 2005 at 01:48 PM.

    Using VB.NET 2005/.NET 2.0, NetBeans IDE 5, Fujitsu Cobol85,
    Website: http://DreamForgery.com

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: BringWindowToTop Lib "user32" process handling...

    You're using the Long type and yet calling ToInt32 instead if ToInt64. Also, you're passing that API function the process handle instead of a window handle. Just make all your handles of type IntPtr and then you don't need to convert to anything. You would get the main window of a process by calling GetMainWindow, then you can get the window handle.
    Last edited by jmcilhinney; Nov 9th, 2005 at 10:46 PM.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Fanatic Member Ruku's Avatar
    Join Date
    Jul 2002
    Location
    Canada
    Posts
    655

    Re: BringWindowToTop Lib "user32" process handling...

    Quote Originally Posted by jmcilhinney
    GetMainWindow


    THANK YOU.

    *RESOLVED*


    Using VB.NET 2005/.NET 2.0, NetBeans IDE 5, Fujitsu Cobol85,
    Website: http://DreamForgery.com

  4. #4
    Member
    Join Date
    Nov 2005
    Posts
    36

    Re: BringWindowToTop Lib "user32" process handling... [RESOLVED]

    New to VB and this forum, so excuse me... Anyway:

    I solved what I think is the same problem a different way (WinXP, VB2003).

    I'm controlling the main form from a tray icon:

    Private Sub tray_MouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles tray.MouseDown
    Me.Show() 'Was maybe hidden
    Me.TopMost = True 'Brings to front like TaskManager
    Me.TopMost = False 'No need to stay there if user don't want me
    End Sub

    Private Sub Hide_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Hide.Click
    Me.Hide()
    End Sub

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: BringWindowToTop Lib "user32" process handling... [RESOLVED]

    Quote Originally Posted by belzona
    New to VB and this forum, so excuse me... Anyway:

    I solved what I think is the same problem a different way (WinXP, VB2003).

    I'm controlling the main form from a tray icon:

    Private Sub tray_MouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles tray.MouseDown
    Me.Show() 'Was maybe hidden
    Me.TopMost = True 'Brings to front like TaskManager
    Me.TopMost = False 'No need to stay there if user don't want me
    End Sub

    Private Sub Hide_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Hide.Click
    Me.Hide()
    End Sub
    The API is used to activate any window of any running process, not just your own window.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width