Page 3 of 3

Re: minimize+Restore Loses all my gadgets

Posted: Fri Oct 31, 2025 5:30 pm
by HeX0R
There is nothing wrong to stay with old PB versions, I also have very old tools, I didn't touch for ages and just am too lazy to get them pushed to the latest updates.
But as a matter of fact, none of my hundreds of tools, no matter how old, "break" when minimizing.
Which means, the reason for the effect is not PB per se, but something in your code.
But without seeing the effect with an example code, no one will be able to help you.

My crystal ball tells me you might make use of SetGadgetColor().

BarryG is right, try to shrink it down to a small example showing the effect, only then you'll receive useful help.

Re: minimize+Restore Loses all my gadgets

Posted: Fri Oct 31, 2025 5:55 pm
by RASHAD
Hi Randy
I have a feeling about your use of #WM_SIZE
Next is my last shoot
Use one of them in your window callback
I wish you luck

Code: Select all

   Case #WM_SYSCOMMAND
      Select wParam
        Case #SC_MAXIMIZE
          Debug WindowX(?)
          Debug WindowWidth(?)
          
        Case #SC_RESTORE
          ShowWindow_(WindowID(?),#SW_HIDE)
          ResizeWindow(?,0,0,400,400)
          ShowWindow_(WindowID(?),#SW_SHOW)
      EndSelect       

    Case #WM_SIZE
      Select wParam 
        Case #SIZE_MINIMIZED 
          Debug "Window was minimized" 
        Case #SIZE_RESTORED
;           ShowWindow_(WindowID(0),#SW_HIDE)
;           ResizeWindow(0,0,0,400,400)
;           ShowWindow_(WindowID(0),#SW_SHOW)
          ;Debug "Window was restored" 
        Case #SIZE_MAXIMIZED 
          ;Debug "Window was maximized" 
      EndSelect

Re: minimize+Restore Loses all my gadgets

Posted: Fri Feb 13, 2026 8:41 pm
by Randy Walker
I tried these two APIs first and both had a problem with restore:

Code: Select all

            ;ShowWindow_(HWND0,#SW_MINIMIZE)
            ;ShowWindow_(HWND0,#SW_SHOWMINIMIZED)
 
Last but not least I tried the native PB command which I didn't know existed until someone pointed it out to me and it seems to have cured the problematic gadget redraw issue for the most part:

Code: Select all

           SetWindowState(#Window_0,#PB_Window_Minimize)

Re: [SOLVED-mostly] minimize+Restore Loses all my gadgets

Posted: Sat Feb 14, 2026 12:21 am
by mk-soft
It goes to 99.9% even without taking Windows API ...

Code: Select all

;-TOP

#ProgramTitle = "Main Window"
#ProgramVersion = "v1.01.2"

Enumeration Windows
  #Main
EndEnumeration

Enumeration MenuBar
  #MainMenu
EndEnumeration

Enumeration MenuItems
  #MainMenuAbout
  #MainMenuExit
EndEnumeration

Enumeration Gadgets
  #MainEdit
  #MainButton1
  #MainButton2
  #MainButton3
EndEnumeration

Enumeration StatusBar
  #MainStatusBar
EndEnumeration

Procedure UpdateWindow()
  Protected dx, dy
  dx = WindowWidth(#Main)
  dy = WindowHeight(#Main) - StatusBarHeight(#MainStatusBar) - MenuHeight()
  ; Resize gadgets
  ResizeGadget(#MainEdit, 5, 5, dx - 10, dy - 45)
  ResizeGadget(#MainButton1, 10, dy - 35, 120, 30)
  ResizeGadget(#MainButton2, 140, dy - 35, 120, 30)
  ResizeGadget(#MainButton3, 270, dy - 35, 120, 30)
EndProcedure

Procedure Main()
  Protected dx, dy
  
  #MainStyle = #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_MaximizeGadget | #PB_Window_MinimizeGadget
  
  If OpenWindow(#Main, #PB_Ignore, #PB_Ignore, 800, 600, #ProgramTitle , #MainStyle)
    ; Menu
    CreateMenu(#MainMenu, WindowID(#Main))
    MenuTitle("&File")
    CompilerIf #PB_Compiler_OS = #PB_OS_MacOS
      MenuItem(#PB_Menu_About, "")
    CompilerElse
      MenuItem(#MainMenuAbout, "About")
    CompilerEndIf
    ; Menu File Items
    
    CompilerIf Not #PB_Compiler_OS = #PB_OS_MacOS
      MenuBar()
      MenuItem(#MainMenuExit, "E&xit")
    CompilerEndIf
    
    ; StatusBar
    CreateStatusBar(#MainStatusBar, WindowID(#Main))
    AddStatusBarField(#PB_Ignore)
    
    ; Gadgets
    dx = WindowWidth(#Main)
    dy = WindowHeight(#Main) - StatusBarHeight(#MainStatusBar) - MenuHeight()
    EditorGadget(#MainEdit, 5, 5, dx -10, dy - 45)
    ButtonGadget(#MainButton1, 10, dy - 35, 120, 30, "Minimize")
    ButtonGadget(#MainButton2, 140, dy - 35, 120, 30, "Maximize")
    ButtonGadget(#MainButton3, 270, dy - 35, 120, 30, "Normal")
    
    ; Bind Events
    BindEvent(#PB_Event_SizeWindow, @UpdateWindow(), #Main)
    
    ; Event Loop
    Repeat
      Select WaitWindowEvent()
        Case #PB_Event_CloseWindow
          Select EventWindow()
            Case #Main
              Break
              
          EndSelect
          
        Case #PB_Event_Menu
          Select EventMenu()
            CompilerIf #PB_Compiler_OS = #PB_OS_MacOS   
              Case #PB_Menu_About
                PostEvent(#PB_Event_Menu, #Main, #MainMenuAbout)
                
              Case #PB_Menu_Preferences
                
              Case #PB_Menu_Quit
                PostEvent(#PB_Event_CloseWindow, #Main, #Null)
                
            CompilerEndIf
            
          Case #MainMenuAbout
            MessageRequester("About", #ProgramTitle + #LF$ + #ProgramVersion, #PB_MessageRequester_Info)
              
          Case #MainMenuExit
            PostEvent(#PB_Event_CloseWindow, #Main, #Null)
            
          EndSelect
          
        Case #PB_Event_Gadget
          Select EventGadget()
            Case #MainEdit
              Select EventType()
                Case #PB_EventType_Change
                  ;
                  
              EndSelect
              
            Case #MainButton1
              SetWindowState(#main, #PB_Window_Minimize)
              
            Case #MainButton2
              SetWindowState(#Main, #PB_Window_Maximize)
              
            Case #MainButton3
              SetWindowState(#Main, #PB_Window_Normal)
            
          EndSelect
          
      EndSelect
    ForEver
    
  EndIf
  
EndProcedure : Main()

Re: minimize+Restore Loses all my gadgets

Posted: Sat Feb 14, 2026 1:12 am
by BarryG
ChatGPT wrote: Thu Oct 30, 2025 2:03 amNow this behavior totally makes sense — several versions of PureBasic (especially around 5.3–5.4) had exactly this issue on Windows 10 and later:
after minimizing and restoring from the taskbar, the window sometimes comes back completely blank until it’s moved, resized, or another window overlaps it.

It’s not you — it’s a combination of how PureBasic wraps the Win32 API and how newer versions of DWM handle paint deferrals.
Sorry, but ChatGPT is just telling you 100% bullsh*t there. It's nothing to do with Win32 API and DWM handle paint deferrals. :lol:

Please show us a standalone snippet that proves the problem.

Re: [SOLVED-mostly] minimize+Restore Loses all my gadgets

Posted: Sat Feb 14, 2026 1:36 am
by Randy Walker
mk-soft wrote: Sat Feb 14, 2026 12:21 am It goes to 99.9% even without taking Windows API ...
Not sure what you what you were trying to show me here.

I was getting extremely bizarre behavior on my main window, occurring randomly if I used my custom minimize button to minimize, following that up with opening and closing another app and the restore my main window again, No matter Hoe I restored it, Gadgets were not being redrawn. It basically just came up a black window not normal title bar.
Yet no redraw issue at all if I used the native Windows _ minimize button up in the title bar.
Don't know if it should matter or not, my main window has 99 gadgets, not including a couple container gadgets.