Page 1 of 1

Bring back #PB_Event_SizeWindow

Posted: Wed May 22, 2024 5:09 am
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.

Re: Bring back #PB_Event_SizeWindow

Posted: Wed May 22, 2024 5:22 am
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().

Re: Bring back #PB_Event_SizeWindow

Posted: Wed May 22, 2024 6:53 am
by Fred
It's the way Windows work and we won't change it

Re: Bring back #PB_Event_SizeWindow

Posted: Wed May 22, 2024 11:39 am
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.

Re: Bring back #PB_Event_SizeWindow

Posted: Wed May 22, 2024 11:41 am
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?

Re: Bring back #PB_Event_SizeWindow

Posted: Wed May 22, 2024 12:26 pm
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