|
-
Jan 23rd, 2006, 12:02 PM
#1
Thread Starter
New Member
[RESOLVED] always on top
Hi,
How can I for a form to always stay on top of the other windows ? I tried some code I found on the net such as this link from MSDN .
But I always have the problem that VBA don't recognize the .hwnd properties of the form... Where is my problem ?
Thanks!
-
Jan 23rd, 2006, 12:23 PM
#2
Re: always on top
Use the FindWindow API to get the UserForms handle.
VB Code:
Option Explicit
'Written By VB/Office Guru™
Private Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA" (ByVal lpClassName As String, _
ByVal lpWindowName As String) As Long
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 HWND_TOPMOST = -1
Private Const HWND_NOTOPMOST = -2
Private Const SWP_NOMOVE = &H2
Private Const SWP_NOSIZE = &H1
Private Sub UserForm_Initialize()
Dim lHwnd As Long
lHwnd = FindWindow("ThunderDFrame", "UserForm1") 'Change to match your userforms caption
Do While lHwnd = 0
lHwnd = FindWindow("ThunderDFrame", "UserForm1") 'Change to match your userforms caption
DoEvents
Loop
SetWindowPos lHwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE Or SWP_NOSIZE
End Sub
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jan 23rd, 2006, 01:02 PM
#3
Thread Starter
New Member
Re: always on top
I've changed "userform1" with the name (is it right ? Or I need the caption ?) of my form, but what is "ThunderDFrame" ?
-
Jan 23rd, 2006, 01:18 PM
#4
Re: always on top
"ThunderDFrame" is the class name of the userform. That doesnt change.
UserForm1 is the forms Caption as described in my coment. Change that to whatever your forms caption says exactly.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jan 23rd, 2006, 02:06 PM
#5
Thread Starter
New Member
Re: always on top
Great!
Thanks a lot
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|