PDA

Click to See Complete Forum and Search --> : BringWindowToTop API


lleemon
Feb 2nd, 2001, 02:41 PM
Can anyone explain how to use this?

I am using the Winsock control and I want my app to pop to the top of the screen if in the background. Is this the right API to use? If so how do I use it?
Thanks in advance.

Here is some sample code that I was thinking of using.

Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)

If Not Me.hwnd = GetActiveWindow Then
BringWindowToTop hwnd
'FlashWindow Me.hwnd, CLng(True)
End If

........

Feb 2nd, 2001, 02:58 PM
Yes, your code should work perfectly fine.

lleemon
Feb 2nd, 2001, 03:35 PM
I can't seem to get it to work so I decided to try it with a timer. Here is my code:

Private Declare Function FlashWindow Lib "user32" (ByVal hwnd As Long, ByVal bInvert As Long) As Long
Private Declare Function GetActiveWindow Lib "user32" () As Long

Private Declare Function BringWindowToTop Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function GetTopWindow Lib "user32" (ByVal hwnd As Long) As Long

Private Sub Command1_Click()
Timer1.Enabled = True
End Sub

Private Sub Form_GotFocus()
FlashWindow Me.hwnd, CLng(False)
End Sub

Private Sub Timer1_Timer()
If Not Me.hwnd = GetActiveWindow Then
BringWindowToTop hwnd
FlashWindow Me.hwnd, CLng(True)
GetTopWindow hwnd
End If
End Sub

------
my timer is set for 5 seconds. That gives me time to minimize everything. After the 5 seconds I see it on the bottom but nothing pops up. Am I doing something wrong?

Thanks.

lleemon
Feb 3rd, 2001, 06:48 AM
For anyone that is interested to what I found out.

To test it out I have a timer and command button:

'minimize the window after you click the button.
Private Declare Function SetForegroundWindow Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function FlashWindow Lib "user32" (ByVal hwnd As Long, ByVal bInvert As Long) As Long

Private Sub cmdGo_Click()
Timer1.Enabled = True
End Sub

Private Sub Timer1_Timer()
FlashWindow hwnd, CLng(True)
SetForegroundWindow hwnd
Form1.WindowState = 0
End Sub

Feb 3rd, 2001, 12:54 PM
Add the following to a Form with a CommandButton and a Timer.

When you want the Form to minimize and flash, press the button.

Private Declare Function FlashWindow Lib "user32" (ByVal hwnd As Long, ByVal bInvert As Long) As Long
Private bState As Boolean

Private Sub Command1_Click()
WindowState = vbMinimized
DoEvents
Timer1.Enabled = True
End Sub

Private Sub Form_Load()
Timer1.Interval = 250
Timer1.Enabled = False
End Sub

Private Sub Timer1_Timer()
bState = Not bState
Static icount As Integer

If bState = True Then
FlashWindow hwnd, 1
Else
FlashWindow hwnd, 0
End If

icount = icount + 1
If icount = 10 Then Timer1.Enabled = False
End Sub

Wak
Feb 3rd, 2001, 06:26 PM
Just use the SetWindowPos API ok?


option explicit
'Keep onTop
Private Declare Function SetWindowPos Lib "user32" _
(ByVal hWnd As Long, _
ByVal hWndInsertAfter _
As Long, ByVal X As Long, _
ByVal Y As Long, _
ByVal cx As Long, _
ByVal cy As Long, _
ByVal wFlags As Long) As Long

Private Const SWP_NOMOVE = 2
Private Const SWP_NOSIZE = 1
Private Const FLAGS = SWP_NOMOVE Or SWP_NOSIZE
Private Const HWND_TOPMOST = -1
Private Const HWND_NOTOPMOST = -2

Private Sub cmdTriggerOn_Click()
SetWindowPos Me.hWnd, HWND_NOTOPMOST, 0, 0, 0, 0, FLAGS

end sub

Private Sub cmdTriggerOff_Click()
SetWindowPos Me.hWnd, HWND_TOPMOST, 0, 0, 0, 0, FLAGS

end sub


I think this is what you want.
Hope it works :):):):):):):):):):):)

KrishnaSantosh
Feb 7th, 2001, 05:26 AM
Hi,

My Email Is : santoshkrishna@santoshsmail.com

You can use the more stable and widely used WinAPI function for this. Here Is The Code :

private declare function SetWindowPos lib "user32" ( _
byval hWnd as long,byval hWndInsertAfter as long, _
byval x as long, byval y as long, byval cx as long, _
byval cy as long, byval wFlags as long) as long

private const SWP_NOSIZE = &H1
private const SWP_NOMOVE =&H2
private const HWND_TOPMOST=-1 'Always on top
private const HWND_NOTOPMOST=-2 'no Always on Top

public sub SetFormOnTop(myForm as object)
SetWindowPos myForm.hWnd,HWND_TOPMOST,0,0, _
0,0,SWP_NOMOVE or SWP_NOSIZE
End Sub

Wak
Feb 9th, 2001, 03:15 AM
KrishnaSantosh,
I'm not too sure, but I'm pretty sure. I took a look at both the code you wrote, and the code I wrote, just before you. And they look pretty damn similar, if not the same. What gives?? I'm not angry, but I see stax of ppl, sending useless messages just to get their posts up.




:):):):):):):):):):):):):):):):):):):):):)

Feb 9th, 2001, 08:15 AM
When you use SetWindowPos in this respect, you don't need to declare all the constants, because you only need to '3' as the flag. This can shorten your by a lot.

Private Declare Function SetWindowPos Lib "user32" (ByVal hWnd As Long, ByVal hWndInsertAfter As Long, ByVal X As Long, ByVal Y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long

Private Sub Command1_Click()
SetWindowPos hWnd, -1, 0, 0, 0, 0, 3
End Sub