BringWindowToTop and SetWindowPos did not do me good when I am using them to make a window (e.g. Notepad) always on top. I may need to hook the external app but wondering if there is an easier way out there that I probably is just missing.
Printable View
BringWindowToTop and SetWindowPos did not do me good when I am using them to make a window (e.g. Notepad) always on top. I may need to hook the external app but wondering if there is an easier way out there that I probably is just missing.
Somethig like this?
Code:Option Explicit
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 Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA" _
(ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Const HWND_TOPMOST = -1 '-- Bring to top and stay there
Private Const HWND_NOTOPMOST = -2 '-- Put the window into a normal position
Private Const SWP_NOMOVE = &H2 '-- Don't move window
Private Const SWP_NOSIZE = &H1 '-- Don't size window
Private Sub Command1_Click()
'Shell ("c:\windows\notepad.exe")
Dim hWnd As Long
'-- Find hwnd of Notepad
hWnd = FindWindow("Notepad", vbNullString)
'-- Set Notepad on top
Call SetWindowPos(hWnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE Or SWP_NOSIZE)
'-- Set the precious top most form after notepad
Call SetWindowPos(hWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE Or SWP_NOSIZE)
End Sub
Removing the other options in the flags parameter did it as you have demonstrated. Thanks!
Hey, how do you move the window to the top left of the screen? 0 x 0?
Me.Top = 0
Me.Left = 0