Author Topic: TopMost Window  (Read 1182 times)

0 Members and 1 Guest are viewing this topic.

Nicola

  • Guest
TopMost Window
« on: December 04, 2020, 08:27:59 AM »
Hi.
I wanted a form that is always visible, above any other, always.
I was betting like this, but it didn't work for me.
WS_EX_TOPMOST did not give the desired result.
Help please ...  :)

Code: [Select]
uses WINUTIL
MainWindow 271,133,WS_SYSMENU | WS_MINIMIZEBOX | WS_EX_TOPMOST


JRS

  • Guest
Re: TopMost Window
« Reply #1 on: December 04, 2020, 01:08:53 PM »
« Last Edit: December 05, 2020, 10:34:26 AM by John »

Charles Pegge

  • Guest
Re: TopMost Window
« Reply #2 on: December 05, 2020, 02:58:56 PM »
A run-time solution: WM_SIZE is always called after the main window is created.

Code: [Select]
  case WM_SIZE
 
  'https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-setwindowpos
  sys hw=-1 'HWND_TOPMOST 'hw must be sys as a window handle
  SetWindowPos(hwnd,hw,0,0,0,0,0x3)

Nicola

  • Guest
Re: TopMost Window
« Reply #3 on: December 06, 2020, 03:03:11 PM »
Hi Charles.
Thank you. You are very precious.
I searched the various files and found this: % HWND_TOPMOST = -1

and then using the command:  SetWindowPos (hWin, HWND_TOPMOST ...

Then I saw you wrote your post ... and I was glad I figured out how. But I put the command in WM_CREATE and it seems to be fine.
One question: what does the last parameter, 0x3, mean?
Greetings

Brian Alvarez

  • Guest
Re: TopMost Window
« Reply #4 on: December 06, 2020, 07:19:08 PM »
I think 0x3 is hexadecimal for decimal 3, perhaps Charles used it because hexadecimals are interpreted as sys? maybe.

 Charles, would this work too?

Code: [Select]
case WM_SIZE
    SetWindowPos(hwnd, sys -1,0,0,0,0, sys 3)

JRS

  • Guest
Re: TopMost Window
« Reply #5 on: December 07, 2020, 01:05:27 AM »
Casting constants is news to me.

Arnold

  • Guest
Re: TopMost Window
« Reply #6 on: December 07, 2020, 02:50:04 AM »
You can find the arguments of SetWindowPos e.g. here:

https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-setwindowpos

BOOL SetWindowPos(
  HWND hWnd,
  HWND hWndInsertAfter,
  int  X,
  int  Y,
  int  cx,
  int  cy,
  UINT uFlags
);

Probably 0x03 is the value of the combined uFlags SWP_NOSIZE (1) + SWP_NOMOVE (2). I think the type of uFlags is uint.

JRS

  • Guest
Re: TopMost Window
« Reply #7 on: December 07, 2020, 03:02:35 AM »
In ScriptBasic hex notation is view by the interpreter as an unsigned long.

Brian Alvarez

  • Guest
Re: TopMost Window
« Reply #8 on: December 07, 2020, 12:19:32 PM »
In ScriptBasic hex notation is view by the interpreter as an unsigned long.

 I think in Oxygen a sys is a signed long when compiled for 32 bits.

Quote
https://www.oxygenbasic.org/o2manual1/sys.htm

JRS

  • Guest
Re: TopMost Window
« Reply #9 on: December 07, 2020, 01:14:45 PM »
When using AND, OR, XOR unsigned integers/longs tend to produce the expected results.

The MD5 routine Charles did in ScriptBasic for the ARM CPU realy shows off the power of hex notation.

Nicola

  • Guest
Re: TopMost Window
« Reply #10 on: December 13, 2020, 05:05:01 AM »
Hi everyone.
The solution to my request was found thanks to your help, especially from Charles.
The little program below is proof.

SetWindowPos (hWin, HWND_TOPMOST, 1,1,271,118)

Code: OxygenBasic
  1. $ filename "Prova_Button.exe"
  2. $ EscapeKeyEnd
  3.  
  4.   uses WinUtil
  5.  
  6.   MainWindow 271,118,WS_SYSMENU|WS_MINIMIZEBOX|WS_EX_TOPMOST
  7.  
  8.  'costants x windows
  9. % SWP_NOZORDER=4
  10.  % HWND_TOPMOST= -1
  11.  % DS_SETFONT=0x40
  12.                                                        
  13.  % IDD_MAIN = 1000
  14.  % IDC_LBL1 = 1001         ' LABEL
  15. % IDC_BTN  = 1002
  16.  
  17.  
  18. global hWin As sys
  19. global ac as int
  20.  
  21.  
  22. function WndProc(sys hWin, uMsg, wParam, lParam) as long callback
  23.   ================================================================
  24.   sys style
  25.    
  26.   select umsg
  27.  
  28.   case WM_CREATE
  29.  
  30.    style=WS_CHILD | WS_VISIBLE | ES_CENTER | DS_SETFONT
  31.    sys Lbl1=CreateWindowEx(0,"Static", "Hello", style, 0, 5, 264, 50, hWin, IDC_LBL1, inst, null)
  32.  
  33.    style=WS_CHILD | BS_TEXT ! BS_PUSHBOX | WS_VISIBLE
  34.    sys hBtn=CreateWindowEx(0,"Button", "Start", style,8, 58, 79, 24, hWin, IDC_BTN, inst, null)
  35.         print SetBkColor   hBtn,0x00FF0000 'blue
  36.        
  37.         SetWindowText hWin,"Nicola 12/2020"
  38.         SetWindowPos(hWin, sys HWND_TOPMOST,1,1,271,118)
  39.  
  40.     case WM_COMMAND
  41.  
  42.             select loword(wParam)
  43.                            
  44.                 case IDC_BTN   'start
  45.                                                 if ac=0 then
  46.                                                         ac=1
  47.                                                 else
  48.                                                         ac=0
  49.                                                 end if
  50.              
  51.             end select
  52.  
  53.     case WM_CLOSE
  54.       DestroyWindow(hWin)
  55.  
  56.     case WM_DESTROY:
  57.                 DestroyWindow(hWin)
  58.       PostQuitMessage 0
  59.  
  60.     case else
  61.  
  62.       return DefWindowProc(hWin, uMsg, wParam, lParam)
  63.     end select
  64.  
  65.         return 0
  66. end function
  67.  

22-dic-2020
Modified with the designation of Charles ...  It is ok in 32 and 64-bit
« Last Edit: December 22, 2020, 12:52:23 PM by Nicola »

Nicola

  • Guest
Re: TopMost Window
« Reply #11 on: December 21, 2020, 09:29:30 AM »
Hi.
I found an anomaly. I tried to compile the little program in 32 and 64 bit. 32-bit works correctly, while if compiled 64-bit it no longer stays on top, it loses this feature.
Sure I'm wrong something, but what?
Hello.

Charles Pegge

  • Guest
Re: TopMost Window
« Reply #12 on: December 21, 2020, 11:43:22 PM »
Hi Nicola,

It needs the explicit 64bit handle type:

        SetWindowPos(hWin, HWND_TOPMOST,1,1,271,118)

        SetWindowPos(hWin, sys HWND_TOPMOST,1,1,271,118)

Nicola

  • Guest
Re: TopMost Window
« Reply #13 on: December 22, 2020, 12:46:25 PM »
Hi Charles,
wonderful solution ... you are a magician !!!
Could you please tell me the reason for explicit use of "sys".
Hello