Author Topic: Top of the screen  (Read 1101 times)

0 Members and 1 Guest are viewing this topic.

Offline krovit

  • Forum Regular
  • Posts: 179
Top of the screen
« on: January 15, 2022, 09:57:39 am »
Hello,

Is there a system to maintain or run a window at the top of the screen (instead of buried under 100 windows)?

Nothing is easy, especially when it appears simple (and nothing could be as dangerous as trying to do good to others)

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • Steve’s QB64 Archive Forum
Re: Top of the screen
« Reply #1 on: January 15, 2022, 11:23:23 am »
With windows, you can use the windows declare libraries and set the window mode to TOPMOST, to put it on top.  I think there's examples of this on both the wiki and the forums here, if you search for them.  (Assuming your program is Windows only.)

For Linux and Mac, I have no idea how to do so.
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
Re: Top of the screen
« Reply #2 on: January 15, 2022, 11:31:01 am »
Yes, looks like a couple of examples are here in Wiki:
https://wiki.qb64.org/wiki/Windows_Libraries

Scroll down to Focus topic. @krovit Maybe you can confirm the examples still work.

Offline krovit

  • Forum Regular
  • Posts: 179
Re: Top of the screen
« Reply #3 on: January 15, 2022, 03:14:39 pm »
Thank you bplus and SMcNeill
that part of the wiki resources is a mine of information (I had forgotten).

The code "Top Most Window" seems to be what I was looking for can be reduced by a few lines of explanatory code. For exemple:

Code: QB64: [Select]
  1. CONST SWP_NOSIZE = &H0001      'ignores cx and cy size parameters
  2. CONST SWP_NOMOVE = &H0002      'ignores x and y position parameters
  3. CONST SWP_NOZORDER = &H0004    'keeps z order and ignores hWndInsertAfter parameter
  4. CONST SWP_NOREDRAW = &H0008    'does not redraw window changes
  5. CONST SWP_NOACTIVATE = &H0010  'does not activate window
  6. CONST SWP_FRAMECHANGED = &H0020
  7. CONST SWP_SHOWWINDOW = &H0040  
  8. CONST SWP_HIDEWINDOW = &H0080
  9. CONST SWP_NOCOPYBITS = &H0100
  10. CONST SWP_NOOWNERZORDER = &H0200
  11. CONST SWP_NOSENDCHANGING = &H0400
  12. CONST SWP_DRAWFRAME = SWP_FRAMECHANGED
  13. CONST SWP_NOREPOSITION = SWP_NOOWNERZORDER
  14. CONST SWP_DEFERERASE = &H2000
  15. CONST SWP_ASYNCWINDOWPOS = &H4000
  16. CONST HWND_TOP = 0        'window at top of z order no focus
  17. CONST HWND_BOTTOM = 1     'window at bottom of z order no focus
  18. CONST HWND_TOPMOST = -1   'window above all others no focus unless active
  19. CONST HWND_NOTOPMOST = -2 'window below active no focus
  20.  
  21.         FUNCTION FindWindowA%& (BYVAL lpClassName%&, BYVAL lpWindowName%&)
  22.         FUNCTION SetWindowPos& (BYVAL hWnd%&, BYVAL hWndInsertAfter%&, BYVAL X&, BYVAL Y&, BYVAL cx&, BYVAL cy&, BYVAL uFlags~&)
  23.         FUNCTION GetForegroundWindow%&
  24.  
  25.         FUNCTION GetLastError~& ()
  26.  
  27.  
  28. hWnd = _WINDOWHANDLE 'FindWindowA(0, _OFFSET(t))
  29.  
  30. 'set as topmost window and move without sizing or activation
  31. IF 0 = SetWindowPos(hWnd, HWND_TOPMOST, 200, 200, 0, 0, SWP_NOSIZE OR SWP_NOACTIVATE) THEN
  32.         PRINT "SetWindowPos failed. 0x" + LCASE$(HEX$(GetLastError))
  33.  
  34. x%& = GetForegroundWindow%& 'find currently focused process handle
  35.  
  36.  

I put this part of the code at the head of the program and the window opens on all the others.
Of course it always stays on top (the code wants just that). It would be useful to understand how it can make the window normal again (I could put the command "Stay on top" and "Stay below" (for example) from the drop-down menu.

I guess the solution is before my eyes and already contained in the initial statements but the external calls to QB64 I just can not understand them...

Nothing is easy, especially when it appears simple (and nothing could be as dangerous as trying to do good to others)

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
Re: Top of the screen
« Reply #4 on: January 15, 2022, 03:43:52 pm »
Hi Krovit,

Looks to me that those answers are contained in these constants:
Code: QB64: [Select]
  1. CONST HWND_TOP = 0        'window at top of z order no focus
  2. CONST HWND_BOTTOM = 1     'window at bottom of z order no focus
  3. CONST HWND_TOPMOST = -1   'window above all others no focus unless active
  4. CONST HWND_NOTOPMOST = -2 'window below active no focus
  5.  

Just have to figure where and when to plug-into code?

Offline krovit

  • Forum Regular
  • Posts: 179
Re: Top of the screen
« Reply #5 on: January 15, 2022, 04:20:52 pm »
yes, it's possible, but I don't know how to translate it into code
Nothing is easy, especially when it appears simple (and nothing could be as dangerous as trying to do good to others)

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
Re: Top of the screen
« Reply #6 on: January 15, 2022, 04:30:06 pm »
'set as topmost window and move without sizing or activation
IF 0 = SetWindowPos(hWnd, HWND_TOPMOST, 200, 200, 0, 0, SWP_NOSIZE OR SWP_NOACTIVATE) THEN
   PRINT "SetWindowPos failed. 0x" + LCASE$(HEX$(GetLastError))
END IF

Try change the const colored blue with one of the other, when you dont want on top anymore.

Offline krovit

  • Forum Regular
  • Posts: 179
Re: Top of the screen
« Reply #7 on: January 15, 2022, 04:43:52 pm »
Is that!

For (always) top:

Code: QB64: [Select]
  1. IF 0 = SetWindowPos(hWnd, HWND_TOPMOST, 200, 200, 0, 0, SWP_NOSIZE OR SWP_NOACTIVATE) THEN
  2.        PRINT "SetWindowPos failed. 0x" + LCASE$(HEX$(GetLastError))
  3.  

For belowe:

Code: QB64: [Select]
  1. IF 0 = SetWindowPos(hWnd, HWND_NOTOPMOST, 200, 200, 0, 0, SWP_NOSIZE OR SWP_NOACTIVATE) THEN
  2.        PRINT "SetWindowPos failed. 0x" + LCASE$(HEX$(GetLastError))
  3.  

Now it's easy to link the code to a menu.
Command external calls continue to be a mystery to me...

Thank you bPlus


Nothing is easy, especially when it appears simple (and nothing could be as dangerous as trying to do good to others)