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:
Module modWindow
'Declare API Function
Private Declare Function BringWindowToTop Lib "user32" (ByVal hwnd As Long) As Long
Public Sub SelectWindow(ByVal hwnd As Long)
'Bring target window to front
BringWindowToTop(hwnd)
End Sub
Public Sub proTst(ByVal AppID As Integer)
Dim p As System.Diagnostics.Process
SelectWindow(Convert.ToInt32(p.GetProcessById(AppID).Handle))
End Sub
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... :ehh:
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.
Re: BringWindowToTop Lib "user32" process handling...
Quote:
Originally Posted by jmcilhinney
GetMainWindow
:eek:
THANK YOU.
*RESOLVED*
:wave:
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
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.