Bring back #PB_Event_SizeWindow

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
es_91
Enthusiast
Enthusiast
Posts: 298
Joined: Thu Jan 27, 2011 12:00 pm
Location: DE

Bring back #PB_Event_SizeWindow

Post by es_91 »

Code: Select all

myFlags = #pb_window_sizeGadget | #pb_window_screenCentered | #pb_window_systemMenu

openWindow ( #pb_any, 0, 0, 512, 288, "resize me!", myFlags )

procedure boundSizing ( )
	debug "#PB_Event_SizeWindow to handler function"
endProcedure

bindEvent ( #pb_event_sizeWindow, @ boundSizing ( ) )

repeat
	select waitWindowEvent ( )
		case #WM_SIZE
			debug "WM_SIZE event"
		case #PB_Event_SizeWindow
			debug "#PB_Event_SizeWindow in event loop"
		case #PB_Event_CloseWindow
			end
	endSelect
forEver
#PB_Event_SizeWindow does not hit the event loop until the resizing is completely done (mouse button lifted). #WM_SIZE is not available anymore though lots of old codes use this.
:mrgreen:
User avatar
jacdelad
Addict
Addict
Posts: 1993
Joined: Wed Feb 03, 2021 12:46 pm
Location: Riesa

Re: Bring back #PB_Event_SizeWindow

Post by jacdelad »

Afaik #PB_Event_SizeWindow never worked differently and it's intentional to not create an event in the event loop:

Code: Select all

Procedure Resize()
  Debug ElapsedMilliseconds()
EndProcedure

OpenWindow(0,0,0,400,300,"Test",#PB_Window_MaximizeGadget|#PB_Window_MinimizeGadget|#PB_Window_ScreenCentered|#PB_Window_SystemMenu|#PB_Window_SizeGadget)
BindEvent(#PB_Event_SizeWindow,@Resize())
Repeat
Until WaitWindowEvent()=#PB_Event_CloseWindow
Tested with 6.11B2 x64, Windows 10 x64. #WM_SIZE can be used via SetWindowCallBack().
Good morning, that's a nice tnetennba!

PureBasic 6.21/Windows 11 x64/Ryzen 7900X/32GB RAM/3TB SSD
Synology DS1821+/DX517, 130.9TB+50.8TB+2TB SSD
Fred
Administrator
Administrator
Posts: 18162
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: Bring back #PB_Event_SizeWindow

Post by Fred »

It's the way Windows work and we won't change it
Axolotl
Addict
Addict
Posts: 804
Joined: Wed Dec 31, 2008 3:36 pm

Re: Bring back #PB_Event_SizeWindow

Post by Axolotl »

You should never mix up window messages (#WM_Xxxx) with Purebasic Events (#PB_Event_Xxxx).
Never expect that that works.

Even if it currently works, it may no longer work in the next version of PB....
Example: #WM_CLOSE and the many old forum examples where this was used and no longer works today.

my approach: window messages only in Callback or SubClass Procedures and very rarly in (Wait) WindowEvent Loops.
Have a look at #WM_SIZE and #WM_SIZING
The #WM_SIZE message is sent when a window has been resized to allow child windows to be resized, the #WM_SIZING message is sent while the user is resizing it to allow the size to be adjusted. The messages are handled in the WindowProc callback function.
Just because it worked doesn't mean it works.
PureBasic 6.04 (x86) and <latest stable version and current alpha/beta> (x64) on Windows 11 Home. Now started with Linux (VM: Ubuntu 22.04).
mestnyi
Addict
Addict
Posts: 1098
Joined: Mon Nov 25, 2013 6:41 am

Re: Bring back #PB_Event_SizeWindow

Post by mestnyi »

Fred wrote: Wed May 22, 2024 6:53 am It's the way Windows work and we won't change it
may I know why?
Axolotl
Addict
Addict
Posts: 804
Joined: Wed Dec 31, 2008 3:36 pm

Re: Bring back #PB_Event_SizeWindow

Post by Axolotl »

IMHO, this is how windows works....

Code: Select all

Macro RectToStr(R) 
  "" + R\left + ", " + R\top + ", " + R\right + ", " + R\bottom 
EndMacro 

Macro DebugX(Message) 
  AddGadgetItem(0, -1, Message) : SetGadgetState(0, CountGadgetItems(0)-1) 
EndMacro 


Procedure WinCallback(hWnd, uMsg, WParam, LParam) 
  Protected *rc.RECT, w, h, dbg$  
  
  If uMsg = #WM_SIZE 
    dbg$ = "#WM_SIZE -- " 
    Select WParam 
      Case #SIZE_MINIMIZED : dbg$ + "Window was minimized " 
      Case #SIZE_RESTORED  : dbg$ + "Window was restored  " 
      Case #SIZE_MAXIMIZED : dbg$ + "Window was maximized " 
    EndSelect 
    w = LParam & $FFFF
    h = (LParam >> 16) & $FFFF
    Debugx(dbg$ + Str(w) + ", " + Str(h)) 
    ResizeGadget(0, #PB_Ignore, #PB_Ignore, w-4, h-4) 

  ElseIf uMsg = #WM_SIZING  : dbg$ = "#WM_SIZING -- " 

    *rc = LParam 

    Select WParam 
      Case #WMSZ_BOTTOM       : dbg$ + "Bottom edge         " 
      Case #WMSZ_BOTTOMLEFT   : dbg$ + "Bottom-left corner  " 
      Case #WMSZ_BOTTOMRIGHT  : dbg$ + "Bottom-right corner " 
      Case #WMSZ_LEFT         : dbg$ + "Left edge           " 
      Case #WMSZ_RIGHT        : dbg$ + "Right edge          " 
      Case #WMSZ_TOP          : dbg$ + "Top edge            " 
      Case #WMSZ_TOPLEFT      : dbg$ + "Top-left corner     " 
      Case #WMSZ_TOPRIGHT     : dbg$ + "Top-right corner    " 
    EndSelect 
    dbg$ + RectToStr(*rc) 
    DebugX(dbg$) 

    ; you can change the *rc\ values here if you need to 
    ; 
    ; MSDN: 
    ; To change the size or position of the drag rectangle, an application must change the members of this structure. 
    ; An application should return TRUE if it processes this message. 

  EndIf 

  ProcedureReturn #PB_ProcessPureBasicEvents 
EndProcedure 


If OpenWindow(0, 0, 0, 200, 100, "Messages", #PB_Window_SystemMenu | #PB_Window_ScreenCentered | #PB_Window_SizeGadget | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget) 
  StickyWindow(0, 1)  ; don't hide the window behind the IDE :)  

  ListViewGadget(0, 2, 2, 200-4, 100-4, $4000)  ; my debug output list 

  SetWindowCallback(@WinCallback(), 0) ; set the callback

  Repeat 
    Select WaitWindowEvent() 
      Case #PB_Event_CloseWindow 
        Break 
      Case #PB_Event_SizeWindow 
        DebugX("#PB_Event_SizeWindow ") 
    EndSelect 
  ForEver   
EndIf 

Just because it worked doesn't mean it works.
PureBasic 6.04 (x86) and <latest stable version and current alpha/beta> (x64) on Windows 11 Home. Now started with Linux (VM: Ubuntu 22.04).
Post Reply