I've heard it called "floating" a window. So, you know my question. How do you do it?
Printable View
I've heard it called "floating" a window. So, you know my question. How do you do it?
Hey mate! you're in luck I've been using it lately (read: yesterday :)), here it comes!
Gottagosleeping now, see ya!Code:Const HWND_TOPMOST = -1
Const HWND_NOTOPMOST = -2
Const SWP_NOSIZE = &H1
Const SWP_NOMOVE = &H2
Const SWP_NOACTIVATE = &H10
Const SWP_SHOWWINDOW = &H40
Private Declare Sub 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)
'To set on top:
SetWindowPos frmMain.hWnd, HWND_TOPMOST, 0, 0, 0, 0,
SWP_NOACTIVATE Or SWP_SHOWWINDOW Or SWP_NOMOVE Or SWP_NOSIZE
'To undo this:
SetWindowPos frmMain.hWnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOACTIVATE Or SWP_SHOWWINDOW Or SWP_NOMOVE Or SWP_NOSIZE
If you want to set another window as the top most one, all you need is the handle (hwnd) of another program to make that program stay on top of all others. You can use the FindWindow api function to do it.
You can use it like this:Code:Private Declare Function FindWindow Lib "user32.dll" _
Alias "FindWindowA" (ByVal lpClassName As Any, ByVal _
lpWindowName As Any) As Long
Not sure if you wanted this, but you said a window.Code:Private Sub Command1_Click()
'Finds Calculator
hWin = FindWindow(vbNullString, "Calculator")
If hWin <> 0 Then 'If Calculator found...
'Set the Calculator as topmost window
SetWindowPos hWin, HWND_TOPMOST, 0, 0, 0, 0, _
SWP_NOACTIVATE Or SWP_SHOWWINDOW Or SWP_NOMOVE Or SWP_NOSIZE
End If
End Sub
Thanks mate! G'd-reply. You really hit the kangaroo on the head with that one! You're sharp as a boomarang! You deserve a trip to Out Back Steak House where we can kick back and have a couple of Fosters!
hehe
Hey...I kid because I love (in a programmer sort of way)!