Page 2 of 3
Re: minimize+Restore Loses all my gadgets
Posted: Wed Oct 29, 2025 10:10 pm
by Randy Walker
BarryG wrote: Wed Oct 29, 2025 10:03 pm
It's definitely some kind of event with redraw issue. You need to reproduce it with a small standalone version to find out.
That would probably be interesting to see but just how to go about that? I wouldn't know where to get started.
BUT!!!
Here's what my callback is doing now. I added a line to unhide the window on restore and left RASHAD's code in there.
Code: Select all
Case #SIZE_RESTORED
HideWindow(#Window_0,0)
PostMessage_(HWND0, #WM_LBUTTONDOWN, 0, 0)
PostMessage_(HWND0, #WM_LBUTTONUP, 0, 0)
restored = #True
Debug "Window was restored"
InvalidateRect_(HWND0, #Null, #True)
Debug "Restored Restored Restored Restored"
It seems to be more stable now, but I've been fooled before.

Re: minimize+Restore Loses all my gadgets
Posted: Wed Oct 29, 2025 10:13 pm
by Randy Walker
Yep, fooled again. Tested just now and came up blank window again. (headbang)
Re: minimize+Restore Loses all my gadgets
Posted: Wed Oct 29, 2025 10:25 pm
by Randy Walker
Now trying a new line added to the callback:
Code: Select all
Case #SIZE_RESTORED
HideWindow(#Window_0,0)
ShowWindow_(HWND0,#SW_SHOWNORMAL) ; <<<< New line
PostMessage_(HWND0, #WM_LBUTTONDOWN, 0, 0)
PostMessage_(HWND0, #WM_LBUTTONUP, 0, 0)
restored = #True
Debug "Window was restored"
InvalidateRect_(HWND0, #Null, #True)
Debug "Restored Restored Restored Restored"
Re: minimize+Restore Loses all my gadgets
Posted: Wed Oct 29, 2025 11:36 pm
by Randy Walker
BarryG wrote: Wed Oct 29, 2025 10:03 pm
It's definitely some kind of event with redraw issue. You need to reproduce it with a small standalone version to find out. What does your main event loop look like? Can you show us? Make sure it doesn't have any unnecessary delays.
I totally agree about the redraw comment. I just never saw this issue until I added and used that minimize button. Main loop is a procedure so I could fold it down to a single line. No sensitive material there, although I do expect to see a raised eyebrow throughout:
Code: Select all
Procedure MAIN_LOOP() ;- MAIN LOOP
Static engaged.i
Protected jog.i
priorWin.i = #Window_0 ; << Tracking "top window" in this application only.
ClearWindowEvent()
GadgetID = 0
Repeat
_mess = WaitWindowEvent()
; Debug Str(Prvgad)+" "+Str(Prvgad)+" "+Str(Prvgad)
; Debug Str(PrvFocus)+" "+Str(PrvFocus)+" "+Str(PrvFocus)+" "+Str(PrvFocus)+" "+Str(PrvFocus)
If damnCallbackSaysClose.i = #PB_Event_CloseWindow
Vacate()
EndIf
TOPwh = GetActiveWindow()
If IsWindow(TOPwh)
TOPwh = WindowID(TOPwh)
EndIf
GadgetId = GetActiveGadget()
activeGad.i = GetActiveGadget()
Kshifted.W = GetAsyncKeyState_(#VK_SHIFT)
Kcontrold.W = GetAsyncKeyState_(#VK_CONTROL)
Kaltered.W = GetAsyncKeyState_(#VK_MENU)
Kreturn.W = GetAsyncKeyState_(#VK_RETURN)
_wParam.w=EventwParam():_lParam.l=EventlParam()
GadgetId.i = EventGadget()
tmp = GetFocus_()
If tmp <> GadgetID(54) And tmp <> 0
Focus = tmp
EndIf
MenuId.i = EventMenu()
EventType.i = EventType() ;:WindowID=EventWindow()
If _mess.i = #PB_Event_Gadget ;then monitor gadget focus and make sure the
; \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/
ShouldNotHaveToDoThisBut_ApplyWorkaroundGyrationAnywaySoYouCanCatchCarriageReturnOrAnyOtherKeyYouMayNeed()
; /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\
; procedure includes any gadget that requires monitoring.
EndIf
activeW.i = GetActiveWindow()
If IsWindow(activeW) Or EnableF5
If IsWindow(activeW)
hTopWin.i = WindowID(activeW)
Else
activeW = HWND0
EndIf
Select activeW ;hTopWin ; SELECTS "ONLY" ACTIVE WINDOW FOR CONSERVATIVE PROCESSING
Case #Window_0 ;HWND0 ; GO HANDLE
If engaged.i = #Window_0
;Debug "passed by Main Loop"
If (oLnewInp = #True) ;And (GetGadgetText(#CallBox_0) <> "") ; #CallBox_0 SEARCH VALUE CHANGED
If (GetTickCount_() - usrDelay.i > 50) ;/ REGULATE FREQUENCY OF LIST UPDATE
; Debug GetGadgetText(#CallBox_0)
If (Len(activeCypher$) > 0) ;/
pseudoWait()
cypherListing()
lastCypher$ = activeCypher$
If activeCypher$ = GetGadgetText(#CallBox_0)
oLnewInp = #False
EndIf
EndIf
EndIf
usrDelay.i = GetTickCount_()
Else
ScrollUpdate()
If (_mess+_wParam <> 176) And (_wParam.w+_lParam.l <> 1)
; Skips record search during window switching
Handle_HWND0() ;/ ONELOOK
EndIf
usrDelay.i = GetTickCount_()
EndIf
Else
;Debug "Going to Window #0"
;pseudoWait()
;ClearWindowEvent()
;ClearWindowEvent()
engaged.i = #Window_0
EndIf
Case #Window_1 ;HWND1 ; GO HANDLE
Select _mess
Case 49214
Default
If engaged.i = #Window_1
If ShowDebug = #True
;Debug "Enter Win#1 loop"
EndIf
Handle_HWND1() ;/ ONELOG
Else
;Debug "Going to Window #1"
pseudoWait()
If ShowDebug = #True
;Debug "Win#1 check 1"
EndIf
ClearWindowEvent()
If ShowDebug = #True
;Debug "Win#1 check 2"
EndIf
ClearWindowEvent()
If ShowDebug = #True
;Debug "Win#1 check 3"
EndIf
engaged.i = #Window_1
EndIf
EndSelect
Case #Window_2 ;HWND2 ; GO HANDLE
If engaged.i = #Window_2
Handle_HWND2() ;/ CUSTOMER RECORD
Else
;Debug "Going to Window #2"
pseudoWait()
ClearWindowEvent()
ClearWindowEvent()
engaged.i = #Window_2
EndIf
Case #Window_3 ;HWND3 ; GO HANDLE
If engaged.i = #Window_3
Handle_HWND3() ;/ History Manager
Else
;Debug "Going to Window #3"
Handle_HWND3()
; pseudoWait()
; ClearWindowEvent()
; ClearWindowEvent()
engaged.i = #Window_3
EndIf
Case #Window_4 ;HWND4 ; GO HANDLE
If engaged.i = #Window_4
Handle_HWND4() ;/ REPORT VIEW
Else
;Debug "Going to Window #4"
If EventMenu() = 49165
_mess = #PB_Event_Menu
Handle_HWND4()
Else
If F8triggerFrom1Log.i = #False
pseudoWait()
ClearWindowEvent()
ClearWindowEvent()
EndIf
EndIf
engaged.i = #Window_4
EndIf
Case #Window_5 ;HWND5 ; GO HANDLE
Select _Mess
Case #PB_Event_SizeWindow
H_chgTrb.W = WindowHeight(#Window_5,#PB_Window_InnerCoordinate)
ResizeWindow(#Window_5, #PB_Ignore, #PB_Ignore,631,H_chgTrb.W)
h = WindowHeight(#Window_5)-30
;Debug h
ResizeGadget(#HelpText_5, -2, 25, 625,h)
EndSelect
If engaged.i = #Window_5
Handle_HWND5() ;/ TROUBLE
Else
;Debug "Going to Window #5"
pseudoWait()
ClearWindowEvent()
ClearWindowEvent()
engaged.i = #Window_5
EndIf
Case #Window_6 ;hWnd6 ; GO HANDLE
If engaged.i = #Window_6
Handle_HWND6() ;/ PHOTO
Else
;Debug "Going to Window #6"
pseudoWait()
ClearWindowEvent()
ClearWindowEvent()
engaged.i = #Window_6
EndIf
Case #Window_16 ;hWnd16 ; GO HANDLE
Debug "work win 16"
If engaged.i = #Window_16
Handle_HWND16() ;/ NAG ME NOTE
Else
Debug "Going to Window #16"
pseudoWait()
ClearWindowEvent()
ClearWindowEvent()
Debug "FUCK FUCK FUCK FUCK"
engaged.i = #Window_16
EndIf
Case #Window_18 ;hWnd18 ; GO HANDLE
If engaged.i = #Window_18
Handle_HWND18() ;/ 10 DIGIT TIME COVERSION
Else
;Debug "Going to Window #18"
pseudoWait()
ClearWindowEvent()
ClearWindowEvent()
engaged.i = #Window_18
EndIf
Case #Window_19, #Window_20 ; HWND20 ; GO HANDLE
If engaged.i = #Window_20
If AnimateReminder = #True ; Foreground with Sustained inactivity so keep it jogging
;Debug "should be Jogging"
GetLastInputInfo_(@lippi)
timeNow.i = GetTickCount_() ; get current timestamp value for comparison calculations
If timeNow.i - lippi\dwTime > 15000 ; user fell asleep so close this window
If tripTimer1
jog + 1
EndIf
If jog > 1
JogReminder()
jog = 0
EndIf
Else ; Foreground with new recent activity so bring it home to main oneLook window
HideWindow(#Window_20,0)
SetForegroundWindow_(HWND20)
SetActiveWindow(#Window_20)
ResizeWindow(#Window_20, lastLook_xP.W+140,lastLook_yP.W+70, #PB_Ignore,#PB_Ignore)
AnimateReminder.i = #False
EndIf
Else
;Debug "Not Jogging"
Handle_HWND20() ;/ EVENT REMINDER
EndIf
Else
;Debug "Going to Window #20"
pseudoWait()
ClearWindowEvent()
ClearWindowEvent()
engaged.i = #Window_20
EndIf
Case #Window_21 ;hWnd21 ; GO HANDLE
If engaged.i = #Window_21
Handle_HWND21() ;/ package CALCULATOR
Else
;Debug "Going to Window #21"
pseudoWait()
ClearWindowEvent()
ClearWindowEvent()
engaged.i = #Window_21
EndIf
Case #window_22 ;hWnd22 ; GO HANDLE
engaged.i = #window_22
Handle_HWND22() ;/ fingerprint CALCULATOR
Case #window_23 ;hWnd23 ; GO HANDLE
If engaged.i = #window_23
Handle_HWND23() ;/ SETUP -- Trump Foreground on Skype Window
Else
;Debug "Going to Window #23"
pseudoWait()
ClearWindowEvent()
ClearWindowEvent()
engaged.i = #window_23
EndIf
Case #window_24 ;hWnd24 ; GO HANDLE
engaged.i = #window_24
Handle_HWND24() ;/ support-key CALCULATOR
Case #window_25 ;hWnd24 ; GO HANDLE
engaged.i = #window_25
Handle_HWND25() ;/ support-key CALCULATOR
Default
If engaged.i <> #window_22
engaged.i = -1
EndIf
EndSelect
Else
IdleInBackgroundOrOtherAppInUse() ; might be used to trigger auto-updates
EndIf
GlobalTasking() ; might be used to update clocks, monitor file transfers, etc...
If checkCrossover.i = #True
If Date() > crossover.i ; do TopOfDay rollover on personal event reminder
;Debug "Crossover to next day"
; Adjust title date and countdown values in the list
If reList() = #False ; then no need to get in your face...
If engaged.i = -1 ; so make sure window is hidden if outside app had foreground
HideWindow(#Window_20,1)
EndIf
EndIf
crossover.i + 86400 ; increment trigger to next day
checkCrossover.i = #False ; revert to non-aggressive GetTickCount_ monitoring
EndIf
EndIf
tmp = GetDlgCtrlID_(Focus)
If tmp <> 0
Select tmp
Case #Smart_0 To #Clear_0
Default
Prvgad = GetDlgCtrlID_(Focus)
PrvFocus = Focus
EndSelect
EndIf
ForEver
EndProcedure ;-END MAIN LOOP
Re: minimize+Restore Loses all my gadgets
Posted: Wed Oct 29, 2025 11:37 pm
by mk-soft
Why create your own minimise button ??? Every application that its OS standard operation !!! "#PB_Window_MinimizeGadget"
Then the app also works as the users know it.
Basic Template
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
#MainButtonOk
#MainButtonCancel
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(#MainButtonok, 10, dy - 35, 120, 30)
ResizeGadget(#MainButtonCancel, dx - 130, 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(#MainButtonok, 10, dy - 35, 120, 30, "Ok")
ButtonGadget(#MainButtonCancel, dx - 130, dy - 35, 120, 30, "Abbruch")
; 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 #MainButtonOk
;
Case #MainButtonCancel
;
EndSelect
EndSelect
ForEver
EndIf
EndProcedure : Main()
Re: minimize+Restore Loses all my gadgets
Posted: Wed Oct 29, 2025 11:44 pm
by Randy Walker
mk-soft wrote: Wed Oct 29, 2025 11:37 pm
Why create your own minimise button ???
User convenience. Same reason I have always had a [CLOSE] button.
Basic Template
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
#MainButtonOk
#MainButtonCancel
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(#MainButtonok, 10, dy - 35, 120, 30)
ResizeGadget(#MainButtonCancel, dx - 130, 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(#MainButtonok, 10, dy - 35, 120, 30, "Ok")
ButtonGadget(#MainButtonCancel, dx - 130, dy - 35, 120, 30, "Abbruch")
; 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 #MainButtonOk
;
Case #MainButtonCancel
;
EndSelect
EndSelect
ForEver
EndIf
EndProcedure : Main()
Line 98: Constant not found: #PB_MessageRequester_Info.
Re: minimize+Restore Loses all my gadgets
Posted: Wed Oct 29, 2025 11:53 pm
by Randy Walker
BTW... I think you meant:
#MB_OK|#MB_ICONINFORMATION
Instead of:
#PB_MessageRequester_Info
Re: minimize+Restore Loses all my gadgets
Posted: Wed Oct 29, 2025 11:55 pm
by mk-soft
Line 98: Constant not found: #PB_MessageRequester_Info.
There has been a very long time for all OS. PB v5.73+
Re: minimize+Restore Loses all my gadgets
Posted: Thu Oct 30, 2025 2:03 am
by Randy Walker
So, I presented the problem to ChatGPT and it asked if I was using GDI or GPU to which I replied:
Oh hellifIknow. I'm coding in PureBasic version 5.40
And ChatGPT replied:
Ah โ PureBasic!

Excellent, that narrows it way down.
Now 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.
So...
I'm totally screwed. My code is broken beyond comprehension in any release after v5.40.
It also suggested these may help after the restore:
Code: Select all
InvalidateRect_(HWND0, #Null, #True)
UpdateWindow_(HWND0)
They didn't help.
Re: minimize+Restore Loses all my gadgets
Posted: Thu Oct 30, 2025 10:14 am
by Caronte3D
Why do you use that old PB version?
Re: minimize+Restore Loses all my gadgets
Posted: Thu Oct 30, 2025 8:47 pm
by Randy Walker
Caronte3D wrote: Thu Oct 30, 2025 10:14 am
Why do you use that old PB version?
It is the highest version that my code will work on. All releases after that break virtually every feature built into my app. What good is that? 6.21 is the worst. I don't have 5 lifetimes to fix everything that gets broken using v 6.21
Re: minimize+Restore Loses all my gadgets
Posted: Thu Oct 30, 2025 9:17 pm
by Quin
Randy Walker wrote: Thu Oct 30, 2025 8:47 pm
It is the highest version that my code will work on. All releases after that break virtually every feature built into my app. What good is that? 6.21 is the worst. I don't have 5 lifetimes to fix everything that gets broken using v 6.21
What did versions after 5.40 break? I mean ascii-only apps, there were big changes in 6.0 etc., but what does 5.50 for example break?
Re: minimize+Restore Loses all my gadgets
Posted: Thu Oct 30, 2025 10:40 pm
by Caronte3D
Randy Walker wrote: Thu Oct 30, 2025 8:47 pm
I don't have 5 lifetimes to fix everything that gets broken using v 6.21
I know this answer don't help you now, but...
Is better to update your code to the new version each time the version rises.
That way you don't need to change a lot of things, only the ones broken with the next release.
Staying stuck on a very old version is not interesting, unless you just need to keep it as it is.
Re: minimize+Restore Loses all my gadgets
Posted: Thu Oct 30, 2025 11:36 pm
by Randy Walker
Caronte3D wrote: Thu Oct 30, 2025 10:40 pm
Randy Walker wrote: Thu Oct 30, 2025 8:47 pm
I don't have 5 lifetimes to fix everything that gets broken using v 6.21
Staying stuck on a very old version is not interesting, unless you just need to keep it as it is.
Doesm;t need to be interesting. Just needs to work. Should not be so much to ask to Allow the app to minimize without braking, regardless the version.
Re: minimize+Restore Loses all my gadgets
Posted: Fri Oct 31, 2025 12:04 pm
by BarryG
You really need to create a small new app using the same window events as your main app, to see if it fails too. If it does, post that small code here. If not, then you've coded something wrong in your main app and you need to see what the difference is in your main app vs your small working test app.