Valhalla Legends Archive

Programming => General Programming => Visual Basic Programming => Topic started by: Networks on April 09, 2004, 02:12 PM

Title: Stay on Top
Post by: Networks on April 09, 2004, 02:12 PM
How do you impliement a "stay on top" function in a VB6 Application?
Title: Re:Stay on Top
Post by: K on April 09, 2004, 02:31 PM
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)
Title: Re:Stay on Top
Post by: Grok on April 09, 2004, 02:34 PM
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.
Title: Re:Stay on Top
Post by: Networks on April 09, 2004, 04:44 PM
Usage? And there is a syntax error Grok.
Title: Re:Stay on Top
Post by: Spht on April 09, 2004, 04:49 PM
Quote from: Networks on April 09, 2004, 04:44 PM
Usage? And there is a syntax error Grok.

StayOnTop(Grok, Networks)
Title: Re:Stay on Top
Post by: Networks on April 09, 2004, 04:51 PM
I am little confused I talking about windows here.
Title: Re:Stay on Top
Post by: iago on April 09, 2004, 04:52 PM
grok's response was a joke.  Read K's, it explains what you need to know.
Title: Re:Stay on Top
Post by: K on April 09, 2004, 06:01 PM
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  ::)
Title: Re:Stay on Top
Post by: Eli_1 on April 09, 2004, 06:34 PM
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.
Title: Re:Stay on Top
Post by: 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.
Title: Re:Stay on Top
Post by: Eli_1 on April 10, 2004, 08:14 PM
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
Title: Re:Stay on Top
Post by: 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

Title: Re:Stay on Top
Post by: Eric on April 11, 2004, 05:14 AM
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. ;)
Title: Re:Stay on Top
Post by: Spht on April 11, 2004, 11:08 AM
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.
Title: Re:Stay on Top
Post by: iago on April 11, 2004, 01:08 PM
Also, how different can stay-on-top code BE?  I mean, besides Grok's :)
Title: Re:Stay on Top
Post by: Tuberload on April 11, 2004, 02:08 PM
Why re-invent the wheel? Give credit where it is due, and move on.
Title: Re:Stay on Top
Post by: Fr0z3N on April 11, 2004, 09:36 PM
I didn't write it, I got it off pscode.
Title: Re:Stay on Top
Post by: Dyndrilliac on April 11, 2004, 10:08 PM
Code doesn't work, gives a Type Mismatch RunTime error for me.
Title: Re:Stay on Top
Post by: Networks on April 11, 2004, 10:29 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


SetWindowPos myfrm.hwnd, lFlag, _ had two lines underneath it making it not work this is the correct one ^
Title: Re:Stay on Top
Post by: Grok on April 11, 2004, 11:05 PM
Way too much code for just TOPMOST.  Send a message instead?
Title: Re:Stay on Top
Post by: 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
Title: Re:Stay on Top
Post by: Tuberload on April 12, 2004, 09:43 AM
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. ;)
Title: Re:Stay on Top
Post by: 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
Title: Re:Stay on Top
Post by: Tuberload on April 12, 2004, 03:21 PM
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.
Title: Re:Stay on Top
Post by: 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.
Title: Re:Stay on Top
Post by: Tuberload on April 12, 2004, 04:45 PM
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]
Title: Re:Stay on Top
Post by: 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
Title: Re:Stay on Top
Post by: Tuberload on April 12, 2004, 07:05 PM
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. :)
Title: Re:Stay on Top
Post by: Networks on April 12, 2004, 07:33 PM
If anyone cares um.. The code fr0z3n provided didn't work any other help?
Title: Re:Stay on Top
Post by: Tuberload on April 12, 2004, 07:39 PM
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.
Title: Re:Stay on Top
Post by: Eli_1 on April 12, 2004, 07:43 PM
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