Anti Minimize Window

Share your advanced PureBasic knowledge/code with the community.
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post by netmaestro »

I'm using a beta version of the OS so I wouldn't worry about it if it's working everywhere else. It's not the first time it's let me down :wink:
BERESHEIT
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post by Sparkie »

@rsts: I edited the code above. See if works any better for you now.
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
rsts
Addict
Addict
Posts: 2736
Joined: Wed Aug 24, 2005 8:39 am
Location: Southwest OH - USA

Post by rsts »

Maybe I'm doing something wrong.

I minimize via Win+M

On Rashad's, everything minimizes but a second later his window re-appears.

On yours, everything minimizes and stays minimized.

cheers
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post by netmaestro »

By returning 0 from WM_SYSCOMMAND I was able to get the window to ignore the first win-M but not a subsequent one. Some sleuthing showed that WM_WINDOWPOSCHANGING had to be added to the WM_SIZE code and now it works perfectly here:

Code: Select all

Procedure WinCallback(hwnd, msg, wParam, lParam) 
  result = #PB_ProcessPureBasicEvents 
  Select msg 
    Case #WM_NCDESTROY 
      RemoveProp_(hwnd, "minimize") 
      ;... Allow Minimizing from Window Caption 
    Case #WM_SYSCOMMAND 
      If wParam = #SC_MINIMIZE 
        SetProp_(hwnd, "minimize", 1) 
        result = 0
      EndIf 
      
    Case #WM_SIZE , #WM_WINDOWPOSCHANGING
      min = GetProp_(hwnd, "minimize") 
      ;... Prevnt minimizing with show desktop 
      If wParam = #SIZE_MINIMIZED And min = 0 
        ShowWindow_(hwnd, #SW_RESTORE) 
        SetWindowPos_(hwnd, #HWND_TOPMOST, 0, 0, 0, 0, #SWP_NOSIZE | #SWP_SHOWWINDOW ) 
        
      EndIf 
      SetProp_(hwnd, "minimize", 0) 
  EndSelect 
  ProcedureReturn result 
EndProcedure 
OpenWindow(0, 0, 0, 320, 240, "", #PB_Window_SystemMenu | #PB_Window_MaximizeGadget | #PB_Window_MinimizeGadget ) 
SetProp_(WindowID(0), "minimize", 0) 
SetWindowCallback(@WinCallback()) 
Repeat 
  event = WaitWindowEvent() 
Until event = #PB_Event_CloseWindow 
[edit] hehe, except now it ignores the minimize button! A bit more work is needed here.
BERESHEIT
rsts
Addict
Addict
Posts: 2736
Joined: Wed Aug 24, 2005 8:39 am
Location: Southwest OH - USA

Post by rsts »

That does it here :)

cheers
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4954
Joined: Sun Apr 12, 2009 6:27 am

Post by RASHAD »

This topic is honored by you guys
I can not believe it

RASHAD
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4954
Joined: Sun Apr 12, 2009 6:27 am

Post by RASHAD »

Sparkie / Netmaestro modified

Code: Select all

Procedure WinCallback(hwnd, msg, wParam, lParam)
  Global xpos = WindowX(0)
  Global ypos= WindowY(0)
  result = #PB_ProcessPureBasicEvents
  Select msg
    Case #WM_NCDESTROY
      RemoveProp_(hwnd, "minimize")
      ;... Allow Minimizing from Window Caption
      
    Case #WM_SIZE
      min = GetProp_(hwnd, "minimize")
      ;... Prevnt minimizing with show desktop
      If wParam = #SIZE_MINIMIZED And min = 0
        ShowWindow_(hwnd, #SW_RESTORE)
        SetWindowPos_(hwnd, #HWND_TOPMOST,xpos,ypos, 0, 0, #SWP_NOSIZE | #SWP_SHOWWINDOW)
      EndIf
      SetProp_(hwnd, "minimize", 0)
  EndSelect
  ProcedureReturn result
EndProcedure
OpenWindow(0, 0, 0, 320, 240, "", #PB_Window_ScreenCentered|#PB_Window_SystemMenu | #PB_Window_MaximizeGadget | #PB_Window_MinimizeGadget)
SetProp_(WindowID(0), "minimize", 0)
SetWindowCallback(@WinCallback())
Repeat
  event = WaitWindowEvent()
Until event = #PB_Event_CloseWindow
Modified #2

Code: Select all

Procedure WinCallback(hwnd, msg, wParam, lParam)
  Global xpos = WindowX(0)
  Global ypos= WindowY(0)
  result = #PB_ProcessPureBasicEvents
  Select msg
    Case #WM_NCDESTROY
      RemoveProp_(hwnd, "minimize")
      ;... Allow Minimizing from Window Caption
     
    Case #WM_SIZE,#WM_SYSCOMMAND
      If wParam = #SC_MINIMIZE 
        SetProp_(hwnd, "minimize", 1) 
        result = 0
      Else 
      min = GetProp_(hwnd, "minimize")
      ;... Prevnt minimizing with show desktop
      ;If wParam = #SIZE_MINIMIZED And min = 0
        ShowWindow_(hwnd, #SW_RESTORE)
        SetWindowPos_(hwnd, #HWND_TOPMOST,xpos,ypos, 0, 0, #SWP_NOSIZE | #SWP_SHOWWINDOW)
      EndIf
      SetProp_(hwnd, "minimize", 0)
  EndSelect
  ProcedureReturn result
EndProcedure
OpenWindow(0, 0, 0, 320, 240, "", #PB_Window_ScreenCentered|#PB_Window_SystemMenu | #PB_Window_MaximizeGadget | #PB_Window_MinimizeGadget)
StickyWindow(0,1)
SetProp_(WindowID(0), "minimize", 0)
SetWindowCallback(@WinCallback())
Repeat
  event = WaitWindowEvent()
Until event = #PB_Event_CloseWindow 
User avatar
Le Soldat Inconnu
Enthusiast
Enthusiast
Posts: 306
Joined: Wed Jul 09, 2003 11:33 am
Location: France

Re: Anti Minimize Window

Post by Le Soldat Inconnu »

And if i don't want have StickyWindow ?

Because your code always put window on top. And i don't want this.

I search but .....
Thanks
LSI
User avatar
Joakim Christiansen
Addict
Addict
Posts: 2452
Joined: Wed Dec 22, 2004 4:12 pm
Location: Norway
Contact:

Re: Anti Minimize Window

Post by Joakim Christiansen »

RASHAD wrote:

Code: Select all

Global hwnd,count

Procedure Restoresize(count)
  Delay(count)
  If GetWindowLong_(hwnd, #GWL_STYLE) & #WS_MINIMIZE 
  ShowWindow_(hwnd, #SW_RESTORE	)
  EndIf
  Goto again
EndProcedure

count=2000 
hwnd = OpenWindow(0, 0, 0, 400, 250, "Anti Minimize", #PB_Window_ScreenCentered| #PB_Window_SizeGadget | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget)
again:
Thread = CreateThread(@Restoresize(), count)
Repeat
    EventID.l = WaitWindowEvent()
    If EventID = #PB_Event_CloseWindow
      Quit = 1
    EndIf
  Until Quit = 1
End

Hi RASHAD,

I just want to warn you about the way you coded this, your use of goto like that will mess up the flow of the program if you make it bigger and cause some weird bugs. Since goto will make the program jump away from whatever it was doing.

To repeat a thread over and over again just do like this in the future:

Code: Select all

Procedure Restoresize(count)
  Repeat
    Delay(count)
    If GetWindowLong_(hwnd, #GWL_STYLE) & #WS_MINIMIZE 
      ShowWindow_(hwnd, #SW_RESTORE	)
    EndIf
  ForEver
EndProcedure
Or instead of ForEver you could also use "Until stopThread" where stopThread would be a global variable you set to true when you want to shut down that thread.

Have a nice day!
I like logic, hence I dislike humans but love computers.
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4954
Joined: Sun Apr 12, 2009 6:27 am

Re: Anti Minimize Window

Post by RASHAD »

Hi Joakim
Nice talking to you
You are 100% right but this is a very old thread for me ,the last post is the best
a little mod. to your code to preserve the timing

Code: Select all

Procedure Restoresize(count)
  Repeat    
    If GetWindowLong_(hwnd, #GWL_STYLE) & #WS_MINIMIZE
      Delay(count) 
      ShowWindow_(hwnd, #SW_RESTORE   )
    EndIf
  ForEver
EndProcedure

Have a good day mate and thank you
Egypt my love
Post Reply