[RESOLVED] Set an external window as always on top
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.
Regards,
™
As a gesture of gratitude please consider rating helpful posts. c",)
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
A good exercise for the Heart is to bend down and help another up...
Please Mark your Thread "Resolved", if the query is solved
MyGear:
★ CPU ★ Ryzen 5 5800X
★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
★ Keyboard ★ TVS Electronics Gold Keyboard
★ Mouse ★ Logitech G502 Hero