BringWindowToTop() API not working

R_K_T_ASHOKA

Active member
Joined
Apr 6, 2006
Messages
33
Programming Experience
3-5
Hi all

I am trying to run this code but its not working..please help


VB.NET:
Private Declare Function BringWindowToTop Lib "user32" (ByVal hwnd As Integer) As Integer
 
 
Private Sub Timer1_Tick(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Timer1.Tick
Call BringWindowToTop(Me.Handle.ToInt32)
End Sub

I even tried InPtr instead of Int32,etc but its not working..

Thanks
 
Cant see much wrong with the api call, although it's preferred to use the dll import rather than the declare statement.

VB.NET:
Imports system.runtime.interopservices
 
<DLLImport("User32.DLL")> _
Private Shared Function BringWindowToTop(byval Hwnd as integer) as integer
end function

Are you sure that the timer event is firing? I take it you have enabled the timer and it is running?

I've heard that the prevent applications from stealing focus in the tweakui can hamper such efforts. Failing that you could just set the topmost property to true.


Edit: Or you could try sending a WM_ACTIVATE message to the window instead.
 
Still its not working

Thanks 4 both

hi vis781..

VB.NET:
<DllImport("User32.DLL")> _
Private Shared Function BringWindowToTop(ByVal Hwnd As Integer) As Integer
End Function
 
Private Sub Timer1_Tick(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Timer1.Tick
Call BringWindowToTop(Me.Handle.ToInt32)
End Sub

this too is not working.. and i am sure the timer is called..

and hi jmcilhinney..

i want to show my form when the VB.Net application is not having focus..i think Activate() will work only when our application has focus.. but i tried using Activate() before itself..its not working..

Ok please try to find some solution

Thanks
 
Ok, have you tried it just in a click event of a button or something to see if it works? Failing that i am at somewhat of a loss....Mmmm I'll have to try it myself to be sure, i'll give it a go this evening. Sorry can't be much more help than that at the moment.
 
How often is this Timer supposed to be Ticking? Are they a fair way apart or are you essentially trying to keep your form on top at all times but not necessarily focused? If that's the case then you would simply set the TopMost property to True wouldn't you?
 
Thanks both

My actual functionality is..

I have a notify icon for my application and when it is clicked i want to show the form, till that time it will be hidden.. i was trying to use the BringWindowToTop() api in a timer with five seconds to find whether the code will work..
 
That makes no sense to me I'm afraid. You set the form's Visible property to False and the NotifyIcon's Visible property to True. In the NotifyIcon's DoubleClick event handler you switch the two values. That's all you need to do.
 
Back
Top