|
-
Nov 9th, 2005, 10:13 PM
#1
Thread Starter
Fanatic Member
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...
Last edited by Ruku; Nov 10th, 2005 at 01:48 PM.
-
Nov 9th, 2005, 10:34 PM
#2
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.
-
Nov 10th, 2005, 01:47 PM
#3
Thread Starter
Fanatic Member
Re: BringWindowToTop Lib "user32" process handling...
 Originally Posted by jmcilhinney
GetMainWindow
THANK YOU.
*RESOLVED*
-
Nov 25th, 2005, 06:17 PM
#4
Member
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
-
Nov 25th, 2005, 07:27 PM
#5
Re: BringWindowToTop Lib "user32" process handling... [RESOLVED]
 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.
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
|