minimize+Restore Loses all my gadgets

Just starting out? Need help? Post your questions and find answers here.
Randy Walker
Addict
Addict
Posts: 1145
Joined: Sun Jul 25, 2004 4:21 pm
Location: USoA

minimize+Restore Loses all my gadgets

Post by Randy Walker »

:oops: I don't think it is me this time. I put a minimize button on the main window of my app. When I minimize with using that button and then restore, all my gadgets are gone. If I minimize and restore using the icon in the taskbar 3 times after the gadgets vanish, the window redraws properly and all the gadgets are back. I don't see this behavior if I minimize using normal conventions so it seems to be some issue related to the ShowWindow_(HWND0,#SW_MINIMIZE) command I'm using. Thought I would try a postmessage or sendmessage equivalent, either cannot figure out the right syntax or it's just not working. Very strange and really annoying. I even tried capturing the #WM_RESTORE so I could un-hide all the gadgets but they cannot be un-hidden. Probably just me. Anyone ever seen anything like that?

Code: Select all

SendMessage_(HWND0,#WM_SHOWWINDOW, #SIZE_MINIMIZED, 0)
PostMessage_(HWND0,#WM_SHOWWINDOW, #SIZE_MINIMIZED, 0)
Don't do anything.
- - - - - - - - - - - - - - - -
Randy
I *never* claimed to be a programmer.
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 5006
Joined: Sun Apr 12, 2009 6:27 am

Re: minimize+Restore Loses all my gadgets

Post by RASHAD »

Hi
How about ShowWindow_() :D
Egypt my love
Randy Walker
Addict
Addict
Posts: 1145
Joined: Sun Jul 25, 2004 4:21 pm
Location: USoA

Re: minimize+Restore Loses all my gadgets

Post by Randy Walker »

RASHAD wrote: Wed Oct 29, 2025 5:11 am Hi
How about ShowWindow_() :D
Yes as I commented above, that is the exact command I was using. Just now I changed that to this and seems to be more stable:
ShowWindow_(HWND0,#SW_SHOWMINIMIZED) << instead of #SW_MINIMIZE
It still minimizes but not going wonky on restore as before. Hopefully this is the fix. Will update here in a day or two after more testing...
- - - - - - - - - - - - - - - -
Randy
I *never* claimed to be a programmer.
Randy Walker
Addict
Addict
Posts: 1145
Joined: Sun Jul 25, 2004 4:21 pm
Location: USoA

Re: minimize+Restore intermittently Loses all my gadgets

Post by Randy Walker »

Spoke too soon... #SW_SHOWMINIMIZED did NOT fix it, Still going blank intermittently on restore.
- - - - - - - - - - - - - - - -
Randy
I *never* claimed to be a programmer.
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 5006
Joined: Sun Apr 12, 2009 6:27 am

Re: minimize+Restore Loses all my gadgets

Post by RASHAD »

Try

Code: Select all

ShowWindow_(WindowID(?),#SW_RESTORE	)
InvalidateRect_(WindowID(?),0,1)
OR
ShowWindow_(WindowID(?),#SW_RESTORE	)
UpdateWindow_(WindowID(?))
OR
SendMessage_(WindowID(?),#WM_SYSCOMMAND,#SC_RESTORE,1)
PostMessage_(GadgetID(0), #WM_LBUTTONDOWN, 0, 0)
PostMessage_(GadgetID(0), #WM_LBUTTONUP, 0, 0)
Egypt my love
Randy Walker
Addict
Addict
Posts: 1145
Joined: Sun Jul 25, 2004 4:21 pm
Location: USoA

Re: minimize+Restore Loses all my gadgets

Post by Randy Walker »

RASHAD wrote: Wed Oct 29, 2025 7:03 am Try

Code: Select all

ShowWindow_(WindowID(?),#SW_RESTORE	)
InvalidateRect_(WindowID(?),0,1)
OR
ShowWindow_(WindowID(?),#SW_RESTORE	)
UpdateWindow_(WindowID(?))
OR
SendMessage_(WindowID(?),#WM_SYSCOMMAND,#SC_RESTORE,1)
PostMessage_(GadgetID(0), #WM_LBUTTONDOWN, 0, 0)
PostMessage_(GadgetID(0), #WM_LBUTTONUP, 0, 0)
I'm not using any code to restore the window. I'm just clicking the icon in the taskbar to do restore. Or using relaunch which tells the current process to restore and take foreground and then the new process terminates. I also tried catching the WM_RESTORE so I could tell it to InvalidateRect_ the window but had no affect.
- - - - - - - - - - - - - - - -
Randy
I *never* claimed to be a programmer.
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 5006
Joined: Sun Apr 12, 2009 6:27 am

Re: minimize+Restore Loses all my gadgets

Post by RASHAD »

If you are using SetWindowCallback(@ProcedureName() [, #Window [, Mode]])
Add the next

Code: Select all

    Case #WM_SYSCOMMAND
      Select wParam 
        Case #SC_RESTORE         
          PostMessage_(WindowID(?), #WM_LBUTTONDOWN, 0, 0)
          PostMessage_(WindowID(?), #WM_LBUTTONUP, 0, 0)   
      EndSelect
If your gadgets inside a Canvas Container

Code: Select all

    Case #WM_SYSCOMMAND
      Select wParam 
        Case #SC_RESTORE         
          PostMessage_(GadgetID(?), #WM_LBUTTONDOWN, 0, 0)
          PostMessage_(GadgetID(?), #WM_LBUTTONUP, 0, 0)   
      EndSelect
Egypt my love
BarryG
Addict
Addict
Posts: 4239
Joined: Thu Apr 18, 2019 8:17 am

Re: minimize+Restore Loses all my gadgets

Post by BarryG »

Why are you using API calls instead of the SetWindowState() command?

And try to post a standalone snippet of code that shows the problem.
User avatar
mk-soft
Always Here
Always Here
Posts: 6363
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: minimize+Restore Loses all my gadgets

Post by mk-soft »

BarryG wrote: Wed Oct 29, 2025 8:47 am Why are you using API calls instead of the SetWindowState() command?

And try to post a standalone snippet of code that shows the problem.
Right 8)
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
Randy Walker
Addict
Addict
Posts: 1145
Joined: Sun Jul 25, 2004 4:21 pm
Location: USoA

Re: minimize+Restore Loses all my gadgets

Post by Randy Walker »

BarryG wrote: Wed Oct 29, 2025 8:47 am Why are you using API calls instead of the SetWindowState() command?
Such a good question! Primarily because I didn't know that was an available option.
Now that I know and have tried it, my new command line to replace the API is:
SetWindowState(#Window_0,#PB_Window_Minimize)
That does indeed minimize the window. Now I just have to wait and see if that is going to make a difference. (Problem being intermittent as it is.) I also added code RASHAD suggested.
- - - - - - - - - - - - - - - -
Randy
I *never* claimed to be a programmer.
Randy Walker
Addict
Addict
Posts: 1145
Joined: Sun Jul 25, 2004 4:21 pm
Location: USoA

Re: minimize+Restore Loses all my gadgets

Post by Randy Walker »

RASHAD wrote: Wed Oct 29, 2025 8:15 am If you are using SetWindowCallback(@ProcedureName() [, #Window [, Mode]])
Add the next

Code: Select all

    Case #WM_SYSCOMMAND
      Select wParam 
        Case #SC_RESTORE         
          PostMessage_(WindowID(?), #WM_LBUTTONDOWN, 0, 0)
          PostMessage_(WindowID(?), #WM_LBUTTONUP, 0, 0)   
      EndSelect
Not using Canvas Container but I did follow the above suggestion, Now just have to wait to see if any improvement. (Problem being intermittent as it is.) I also substituted code suggested by BarryG to replace the minimize API.
- - - - - - - - - - - - - - - -
Randy
I *never* claimed to be a programmer.
Randy Walker
Addict
Addict
Posts: 1145
Joined: Sun Jul 25, 2004 4:21 pm
Location: USoA

Re: minimize+Restore Loses all my gadgets

Post by Randy Walker »

Nope Afraid the issue still exists, so I'll just have to have my minimize button position the mouse over the Window titlebar minimize button and send left click, hoping for the best.
- - - - - - - - - - - - - - - -
Randy
I *never* claimed to be a programmer.
Randy Walker
Addict
Addict
Posts: 1145
Joined: Sun Jul 25, 2004 4:21 pm
Location: USoA

Re: minimize+Restore Loses all my gadgets

Post by Randy Walker »

How goofy is this for a workaround? -- If it even solves the problem. It does minimize the window, so time will tell.

Code: Select all

Procedure MinimizeWin0()
      GetWindowRect_(TOPwh,rw)
      wpx = rw\right -100
      wpy = rw\top+15
      SetCursorPos_(wpx,wpy) ;mouse nicely positioned over the _ minimize button in the titlebar.
  mouse_event_(#MOUSEEVENTF_LEFTDOWN,0,0,0,0)
  mouse_event_(#MOUSEEVENTF_LEFTUP,0,0,0,0)
EndProcedure
- - - - - - - - - - - - - - - -
Randy
I *never* claimed to be a programmer.
Randy Walker
Addict
Addict
Posts: 1145
Joined: Sun Jul 25, 2004 4:21 pm
Location: USoA

Re: minimize+Restore Loses all my gadgets

Post by Randy Walker »

Nope, even goingto that extreme had no affect. Window can still come up blank.

I did notice something though, I create the window invisible and hidewindow(#HWND0,0) after after launch when everything is loaded and initialized. The window shows blank for a few seconds while all that initialization is taking place, and then all the gadgets suddenly appear. So maybe hide unhide will be the solution? Hmmm.
- - - - - - - - - - - - - - - -
Randy
I *never* claimed to be a programmer.
BarryG
Addict
Addict
Posts: 4239
Joined: Thu Apr 18, 2019 8:17 am

Re: minimize+Restore Loses all my gadgets

Post by BarryG »

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.
Post Reply