How do you impliement a "stay on top" function in a VB6 Application?
You will need to call SetWindowPos() with the HWND_TOPMOST parameter.
Edit: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/WinUI/WindowsUserInterface/Windowing/Windows/
WindowReference/WindowFunctions/SetWindowPos.asp (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/WinUI/WindowsUserInterface/Windowing/Windows/WindowReference/WindowFunctions/SetWindowPos.asp)
Private Function StayOnTop(ByRef TopPerson As CPerson, ByRef BottomPerson As CPerson) As True
Do While TopPerson.Altitude <= BottomPerson.Altitude
TopPerson.Altitude = TopPerson.Altitude + 1
If BottomPerson.Slap(TopPerson) = REAL_HARD Then
StayOnTop = False
Exit Function
End If
Loop
StayOnTop = True
End Function
Hope this helps.
Usage? And there is a syntax error Grok.
Quote from: Networks on April 09, 2004, 04:44 PM
Usage? And there is a syntax error Grok.
StayOnTop(Grok, Networks)
I am little confused I talking about windows here.
grok's response was a joke. Read K's, it explains what you need to know.
Quote from: iago on April 09, 2004, 04:52 PM
grok's response was a joke. Read K's, it explains what you need to know.
Although if you couldn't figure out that Grok's was a joke, good luck implementing the simple api call ::)
Quote from: Networks on April 09, 2004, 04:44 PM
Usage? And there is a syntax error Grok.
More proof that people don't actually read the code the copy and paste.
Quote from: Networks on April 09, 2004, 04:44 PM
Usage? And there is a syntax error Grok.
Define REAL_HARD as "With Blood" ;)
EDIT -- I totally agree. That is pathetic he didn't catch on to that.
Quote from: Newby on April 09, 2004, 07:49 PM
Quote from: Networks on April 09, 2004, 04:44 PM
Usage? And there is a syntax error Grok.
Define REAL_HARD as "With Blood" ;)
EDIT -- I totally agree. That is pathetic he didn't catch on to that.
Const REAL_HARD as String = "With Blood" '// *
;D
'**************************************
'Windows API/Global Declarations for
'Always On Top
'**************************************
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
Public Sub AlwaysOnTop(myfrm As Form, SetOnTop As Boolean)
If SetOnTop Then
lFlag = HWND_TOPMOST
Else
lFlag = HWND_NOTOPMOST
End If
SetWindowPos myfrm.hwnd, lFlag, _
myfrm.Left / Screen.TwipsPerPixelX, _
myfrm.Top / Screen.TwipsPerPixelY, _
myfrm.Width / Screen.TwipsPerPixelX, _
myfrm.Height / Screen.TwipsPerPixelY, _
SWP_NOACTIVATE Or SWP_SHOWWINDOW
End Sub
'Well, if your for example in a form cal
' led 'Form1' then you'd simply type:
AlwaysOnTop Form1, True
Quote from: Fr0z3N on April 10, 2004, 11:03 PM
'**************************************
'Windows API/Global Declarations for
'Always On Top
'**************************************
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
Public Sub AlwaysOnTop(myfrm As Form, SetOnTop As Boolean)
If SetOnTop Then
lFlag = HWND_TOPMOST
Else
lFlag = HWND_NOTOPMOST
End If
SetWindowPos myfrm.hwnd, lFlag, _
myfrm.Left / Screen.TwipsPerPixelX, _
myfrm.Top / Screen.TwipsPerPixelY, _
myfrm.Width / Screen.TwipsPerPixelX, _
myfrm.Height / Screen.TwipsPerPixelY, _
SWP_NOACTIVATE Or SWP_SHOWWINDOW
End Sub
'Well, if your for example in a form cal
' led 'Form1' then you'd simply type:
AlwaysOnTop Form1, True
I saw something
nearly identical to that on pscode, but I'm sure it's just a coincidence. ;)
Quote from: LoRd[nK] on April 11, 2004, 05:14 AM
I saw something nearly identical to that on pscode, but I'm sure it's just a coincidence. ;)
He never claimed he wrote it, so you could be right.
Also, how different can stay-on-top code BE? I mean, besides Grok's :)
Why re-invent the wheel? Give credit where it is due, and move on.
I didn't write it, I got it off pscode.
Code doesn't work, gives a Type Mismatch RunTime error for me.
'**************************************
'Windows API/Global Declarations for
'Always On Top
'**************************************
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
Public Sub AlwaysOnTop(myfrm As Form, SetOnTop As Boolean)
If SetOnTop Then
lFlag = HWND_TOPMOST
Else
lFlag = HWND_NOTOPMOST
End If
SetWindowPos myfrm.hwnd, lFlag, _
myfrm.Left / Screen.TwipsPerPixelX, _
myfrm.Top / Screen.TwipsPerPixelY, _
myfrm.Width / Screen.TwipsPerPixelX, _
myfrm.Height / Screen.TwipsPerPixelY, _
SWP_NOACTIVATE Or SWP_SHOWWINDOW
End Sub
'Well, if your for example in a form cal
' led 'Form1' then you'd simply type:
AlwaysOnTop Form1, True
SetWindowPos myfrm.hwnd, lFlag, _ had two lines underneath it making it not work this is the correct one ^
Way too much code for just TOPMOST. Send a message instead?
Quote from: Tuberload on April 11, 2004, 02:08 PM
Why re-invent the wheel? Give credit where it is due, and move on.
I mostly give "credit" when I take code from a site and post it here. The most important reason isn't to credit them though, but in case of:
Quote from: Dyndrilliac on April 11, 2004, 10:08 PM
Code doesn't work, gives a Type Mismatch RunTime error for me.
So, that way they know that I'm not to be blamed if the code doesn't work on all computers.... :P
Quote from: Adron on April 12, 2004, 05:31 AM
Quote from: Tuberload on April 11, 2004, 02:08 PM
Why re-invent the wheel? Give credit where it is due, and move on.
I mostly give "credit" when I take code from a site and post it here. The most important reason isn't to credit them though, but in case of:
Quote from: Dyndrilliac on April 11, 2004, 10:08 PM
Code doesn't work, gives a Type Mismatch RunTime error for me.
So, that way they know that I'm not to be blamed if the code doesn't work on all computers.... :P
Never thought of it like that. Hey their not bugs their features, remember. ;)
Quote from: Tuberload on April 12, 2004, 09:43 AM
Quote from: Adron on April 12, 2004, 05:31 AM
So, that way they know that I'm not to be blamed if the code doesn't work on all computers.... :P
Never thought of it like that. Hey their not bugs their features, remember. ;)
Perhaps it's a difference in attitude...
I like my code. It's mostly just the way I want it, and it's good. I wouldn't want to take someone else's code and put my name on it, because then their lousy code could put a smear on my name.
And yes, sometimes my code has more
features than I intended, but it's my code, and I'm proud of it! :P
Quote from: Adron on April 12, 2004, 10:36 AM
Quote from: Tuberload on April 12, 2004, 09:43 AM
Quote from: Adron on April 12, 2004, 05:31 AM
So, that way they know that I'm not to be blamed if the code doesn't work on all computers.... :P
Never thought of it like that. Hey their not bugs their features, remember. ;)
Perhaps it's a difference in attitude...
I like my code. It's mostly just the way I want it, and it's good. I wouldn't want to take someone else's code and put my name on it, because then their lousy code could put a smear on my name.
And yes, sometimes my code has more features than I intended, but it's my code, and I'm proud of it! :P
I have my own style, well an adopted style anyways. I never directly use anyone's code, if I do I re-write it to satisfy my needs, and then give credit to the original author.
It's definitely my code, but I wouldn't go as far as to say it's any good. :) I'll leave that one up to the critics. Kp does an excellent job of pointing out improvements for me.
I use other people's code "snippets" all the time without giving credit, if it's something I could've done just by sitting down and doing it. If it's something that took a significant investment in time or skill, then I'll give credit in my source code.
If I purchase license to use code in libraries (such as ActiveX controls), or in source form, I never give credit and don't feel any is due.
Quote from: Grok on April 12, 2004, 03:32 PM
I use other people's code "snippets" all the time without giving credit, if it's something I could've done just by sitting down and doing it. If it's something that took a significant investment in time or skill, then I'll give credit in my source code.
If I purchase license to use code in libraries (such as ActiveX controls), or in source form, I never give credit and don't feel any is due.
I think that's a very good point. Simple code snippets, as you pointed out, are not original in my opinion so why give credit. I think it is the design and logic behind certain pieces of code that deserves credit.
[Edit: grammar]
Quote from: Tuberload on April 12, 2004, 04:45 PM
I think that's a very good point. Simple code snippets, as you pointed out, are not original in my opinion so why give credit. I think it is the design and logic behind certain pieces of code that deserves credit.
[Edit: grammar]
Bugs is what might make them unique and original... :P
Quote from: Adron on April 12, 2004, 06:58 PM
Quote from: Tuberload on April 12, 2004, 04:45 PM
I think that's a very good point. Simple code snippets, as you pointed out, are not original in my opinion so why give credit. I think it is the design and logic behind certain pieces of code that deserves credit.
[Edit: grammar]
Bugs is what might make them unique and original... :P
Then I will fix them, and notify the original author. From that point on he will have to give me credit. :)
If anyone cares um.. The code fr0z3n provided didn't work any other help?
Quote from: Networks on April 12, 2004, 07:33 PM
If anyone cares um.. The code fr0z3n provided didn't work any other help?
http://forum.valhallalegends.com/phpbbs/index.php?board=2;action=display;threadid=6269 (http://forum.valhallalegends.com/phpbbs/index.php?board=2;action=display;threadid=6269)
This thread might be able to help you find what you are looking for.
Quote from: Networks on April 12, 2004, 07:33 PM
If anyone cares um.. The code fr0z3n provided didn't work any other help?
Here:
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)
Const HWND_WILLUNOTICE as String = "t3h ub3r h4x0r"
Private Declare Function SetWindowText Lib "user32" Alias "SetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String) As Long
Public Sub SetTopMost(TheForm as Form)
SetWindowText TheForm.hWnd, HWND_WILLUNOTICE
SetWindowPos TheForm.hWnd, HWND_TOPMOST, 0, 0, _
0, 0, SWP_NOACTIVATE Or SWP_SHOWWINDOW _
Or SWP_NOMOVE Or SWP_NOSIZE
End Sub