Ooops
November 25, 2020, 08:47:46 AM

Author Topic: [bb] Keep A Window On Top by SebHoll [ 1+ years ago ]  (Read 512 times)

Offline BlitzBot

  • Jr. Member
  • **
  • Posts: 1
[bb] Keep A Window On Top by SebHoll [ 1+ years ago ]
« on: June 29, 2017, 12:28:38 AM »
Title : Keep A Window On Top
Author : SebHoll
Posted : 1+ years ago

Description : In short, this script makes a basic window and calls the function "MakeWindowOnTop()" which sets the windows attributes to always be on top. I've tried the code on Windows XP and it works fine.

Syntax for the "MakeWindowOnTop()" function is:

MakeWindowOnTop(blitzwindowhandle,ontop)

blitzwindowhandle = The Gadget Handle For The Window Given By Blitz
ontop = Either 1 or 0. 1 makes the window "always on top". 0 Removes the "always on top" attribute.

Really easy to follow and use - just thought someone might need it. I've tried to document as best as I can.

Please post any suggestions...

Seb
Userlib Declaration:
Code: [Select]
.lib "user32.dll"
SetWindowPos%(hwnd%,hWndInsertAfter%,x%,y%,cx%,cy%,wFlags%):"SetWindowPos"

Sample Code: (Thanks to Hip Teen and TomToad for suggestions) [/i]

Code :
Code: BlitzBasic
  1. wndMain = CreateWindow("Hello",100,100,400,300,0,5)
  2. MakeWindowOnTop(wndMain)
  3.  
  4. Repeat
  5.  
  6. If WaitEvent() = $803 Then End
  7.  
  8. Forever
  9.  
  10. ;+++++++++++++++++++++++++++++++++++++
  11. ;FUNCTION
  12. ;+++++++++++++++++++++++++++++++++++++
  13.  
  14. Function MakeWindowOnTop(wndBlitzHandle,ontop=1)        ;Windows gadget handle and switch to be set. Defaults to 1. E.g. make ontop.
  15.  
  16. wndHandle = QueryObject(wndBlitzHandle,1)               ;Gets the actual handle of the window to be used with API call.
  17. SetWindowPos(wndHandle,ontop-2,0,0,0,0,1+2+40)          ;Applies setting to window with constants at end (see below).
  18.  
  19. ;1: Keep Original Window Size
  20. ;2: Keep Orginal Pos.
  21. ;40: Keep Original Z-Order
  22.  
  23. End Function


Comments :


Hip Teen(Posted 1+ years ago)

 Just a little thing, but you can replace
Code: [Select]
Select ontop

Case 1:ontop = -1
Case 0:ontop = -2

End Select
by this line:
Code: [Select]
ontop = -2 + ontopbut as I said, just a little thing ;-)


TomToad(Posted 1+ years ago)

 What about
Code: [Select]
ontop = ontop - 2or eliminate the check altogether and just use
Code: [Select]
SetWindowPos(wndHandle,ontop-2,0,0,0,0,1+2+40)


SebHoll(Posted 1+ years ago)

 Good point! - That makes much more sense. Is there anyway I can edit the code I've put down or not?


SebHoll(Posted 1+ years ago)

 Found out how to edit it. :PThanksSeb [/i]

 

SimplePortal 2.3.6 © 2008-2014, SimplePortal