Vista: Hide window without animation ?

Windows specific forum
c4s
Addict
Addict
Posts: 1981
Joined: Thu Nov 01, 2007 5:37 pm
Location: Germany

Vista: Hide window without animation ?

Post by c4s »

When I use HideWindow() it takes a while until the window is invisible
because Windows Vista (and 7 too?) makes a transparency fade etc by
default.
I need it to be hidden immediately without any animations.

Is there a way I can temporarily disable this?
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

Try moving the window off-screen before hiding it.
I may look like a mule, but I'm not a complete ass.
c4s
Addict
Addict
Posts: 1981
Joined: Thu Nov 01, 2007 5:37 pm
Location: Germany

Post by c4s »

This looks like a good idea - I don't even have to hide it.

Thanks.
UserOfPure
Enthusiast
Enthusiast
Posts: 469
Joined: Sun Mar 16, 2008 9:18 am

Post by UserOfPure »

If you don't hide it, it will still have a button on the Taskbar.
User avatar
Fluid Byte
Addict
Addict
Posts: 2336
Joined: Fri Jul 21, 2006 4:41 am
Location: Berlin, Germany

Post by Fluid Byte »

First move it then hide it:

Code: Select all

OpenWindow(0,0,0,320,240,"void",#PB_Window_SystemMenu | #PB_Window_ScreenCentered)
ButtonGadget(0,5,5,120,25,"untitled")

Repeat
	EventID = WaitWindowEvent()

	If EventID = #PB_Event_Gadget
		ResizeWindow(0,5000,#PB_Ignore,#PB_Ignore,#PB_Ignore)
		HideWindow(0,1)
	EndIf
Until EventID = #PB_Event_CloseWindow
Windows 10 Pro, 64-Bit / Whose Hoff is it anyway?
c4s
Addict
Addict
Posts: 1981
Joined: Thu Nov 01, 2007 5:37 pm
Location: Germany

Re: Vista: Hide window without animation ?

Post by c4s »

...I don't like that I always find my own posts here when I'm try to find something in the www. :wink:

Anyway, I didn't find an answer for this: Is it save to assume that negative positions are not on the screen? What about multiple monitors/desktops? (can't test it)
If any of you native English speakers have any suggestions for the above text, please let me know (via PM). Thanks!
MachineCode
Addict
Addict
Posts: 1482
Joined: Tue Feb 22, 2011 1:16 pm

Re: Vista: Hide window without animation ?

Post by MachineCode »

c4s wrote:Is it save to assume that negative positions are not on the screen? What about multiple monitors/desktops? (can't test it)
Yes, and yes. Just use a LARGE negative number though, like -999999, because no monitor will have a desktop size of 999999 pixels wide.
Microsoft Visual Basic only lasted 7 short years: 1991 to 1998.
PureBasic: Born in 1998 and still going strong to this very day!
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4997
Joined: Sun Apr 12, 2009 6:27 am

Re: Vista: Hide window without animation ?

Post by RASHAD »

@c4s Hi
You can disable the animation flag before hiding window
It works fine with win 7 and I guess it will be OK too with vista

Code: Select all

OpenWindow(0,0,0,100,100,"Test",#PB_Window_SystemMenu| #PB_Window_ScreenCentered)
ButtonGadget(1,10,10,80,25,"Test",#PB_Button_Toggle)
anm.ANIMATIONINFO\cbSize = SizeOf(ANIMATIONINFO)
anm.ANIMATIONINFO\iMinAnimate = 0                   ;1 to enable
SystemParametersInfo_($0049, SizeOf(ANIMATIONINFO), @anm, 0)

Repeat
  Select WaitWindowEvent()
      
    Case #PB_Event_CloseWindow
      Q = 1   
       
    Case #PB_Event_Gadget
        Select EventGadget()
          Case 1
              HideWindow(0,1)
               Delay(2000)
               HideWindow(0,0)
               
        EndSelect
             
  EndSelect 
Until Q = 1

Good luck mate
Egypt my love
c4s
Addict
Addict
Posts: 1981
Joined: Thu Nov 01, 2007 5:37 pm
Location: Germany

Re: Vista: Hide window without animation ?

Post by c4s »

@MachineCode
What do you mean by large negative number? I mean the window width plus some pixels for shadows etc. should be enough if a negative is always invisible?!


@Rashad
Thanks for your help. But I don't want to mess with the users system settings, so I rather stick with moving the window to a negative value and then hiding it.
Too bad that there doesn't seem to be a flag that allows to dynamically set the animation state just for the current window...
If any of you native English speakers have any suggestions for the above text, please let me know (via PM). Thanks!
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4997
Joined: Sun Apr 12, 2009 6:27 am

Re: Vista: Hide window without animation ?

Post by RASHAD »

@c4s
If it works with Vista and the timing is fine with you
So no problem with the user settings
See next

Code: Select all

Global Animflag

;Get minanimation flag
anm.ANIMATIONINFO\cbSize = SizeOf(ANIMATIONINFO)
SystemParametersInfo_($0048, SizeOf(ANIMATIONINFO), @anm, 0)
Animflag = anm.ANIMATIONINFO\iMinAnimate

OpenWindow(0,0,0,100,100,"Test",#PB_Window_SystemMenu| #PB_Window_ScreenCentered)
ButtonGadget(1,10,10,80,25,"Test",#PB_Button_Toggle)

Repeat
  Select WaitWindowEvent()
     
    Case #PB_Event_CloseWindow
      Q = 1   
       
    Case #PB_Event_Gadget
        Select EventGadget()
          Case 1              
              anm.ANIMATIONINFO\iMinAnimate = 0
              SystemParametersInfo_($0049, SizeOf(ANIMATIONINFO), @anm, 0)
              HideWindow(0,1)
              If Animflag = 1
                anm.ANIMATIONINFO\iMinAnimate = 1
                SystemParametersInfo_($0049, SizeOf(ANIMATIONINFO), @anm, 0)
              EndIf
               
        EndSelect
             
  EndSelect
Until Q = 1

Egypt my love
MachineCode
Addict
Addict
Posts: 1482
Joined: Tue Feb 22, 2011 1:16 pm

Re: Vista: Hide window without animation ?

Post by MachineCode »

c4s wrote:What do you mean by large negative number? I mean the window width plus some pixels for shadows etc. should be enough if a negative is always invisible?!
A negative number isn't going to hide the window unless it's a large negative number. Look:

Code: Select all

OpenWindow(0,0,0,150,50,"Test",#PB_Window_SystemMenu)
ButtonGadget(1,10,10,120,20,"Click to move to -50")

Repeat
  Event=WaitWindowEvent()
  If Event=#PB_Event_Gadget
    ResizeWindow(0,-50,#PB_Ignore,#PB_Ignore,#PB_Ignore)
  EndIf
Until Event=#PB_Event_CloseWindow
When you click the button, the window moves 50 pixels to the left, but it's still visible. But surely you knew that?

So what you do is use a LARGE negative number, like -999999, to ensure that no monitors (or dual monitors!) will show the window. Because if you have dual monitors and both are 2048 pixels wide, and the window opens on the right-hand one and moves -1000 pixels to the left, then it will be shown on the left-hand one (that is, still visible). So using something insanely large like -999999 gets rid of that possibility, because it's unlikely that the user will be using a monitor that is 999999 pixels wide. :)
Microsoft Visual Basic only lasted 7 short years: 1991 to 1998.
PureBasic: Born in 1998 and still going strong to this very day!
c4s
Addict
Addict
Posts: 1981
Joined: Thu Nov 01, 2007 5:37 pm
Location: Germany

Re: Vista: Hide window without animation ?

Post by c4s »

I just wanted to know if negative values can be visible in general.
I think I'm going to use ResizeWindow(0, -WindowWidth(0) - 50, WindowHeight(0) - 50, #PB_Ignore, #PB_Ignore) because I don't feel good about using something like -999999...
If any of you native English speakers have any suggestions for the above text, please let me know (via PM). Thanks!
User avatar
nco2k
Addict
Addict
Posts: 1344
Joined: Mon Sep 15, 2003 5:55 am

Re: Vista: Hide window without animation ?

Post by nco2k »

if the user has a second monitor attached left from his primary monitor, he might see your window. yes, desktop values can be negative.

WindowWidth/Height() return the size of the window client area, so WindowHeight(0) - 50 might not be enough, since you dont know how large the titlebar+borders of the user is. yes, the size of the titlebar can be changed.

if you need the real width/height of a window, use something like this:

Code: Select all

Procedure WindowRealWidth(WindowID)
  Protected Result, WinRect.RECT
  If GetWindowRect_(WindowID, @WinRect)
    Result = WinRect\right - WinRect\left
  EndIf
  ProcedureReturn Result
EndProcedure
Procedure WindowRealHeight(WindowID)
  Protected Result, WinRect.RECT
  If GetWindowRect_(WindowID, @WinRect)
    Result = WinRect\bottom - WinRect\top
  EndIf
  ProcedureReturn Result
EndProcedure
but there is nothing wrong with -99999 though.

c ya,
nco2k
If OSVersion() = #PB_OS_Windows_ME : End : EndIf
User avatar
Fluid Byte
Addict
Addict
Posts: 2336
Joined: Fri Jul 21, 2006 4:41 am
Location: Berlin, Germany

Re: Vista: Hide window without animation ?

Post by Fluid Byte »

Clean solution:

Code: Select all

OpenWindow(0,0,0,320,240,"void",#PB_Window_SystemMenu | #PB_Window_ScreenCentered)
ButtonGadget(0,5,5,120,25,"Test")

Repeat
   EventID = WaitWindowEvent()

   If EventID = #PB_Event_Gadget
   	HideWindow(0,1)
   	SendMessage_(WindowID(0),#WM_SETREDRAW,1,0)
   EndIf
Until EventID = #PB_Event_CloseWindow
Works fine on Windows 7
Windows 10 Pro, 64-Bit / Whose Hoff is it anyway?
MachineCode
Addict
Addict
Posts: 1482
Joined: Tue Feb 22, 2011 1:16 pm

Re: Vista: Hide window without animation ?

Post by MachineCode »

c4s wrote:I just wanted to know if negative values can be visible in general
If you ran my example, you'd have your answer. That's why I posted it.
c4s wrote:I don't feel good about using something like -999999
Why not? X and Y values for window positions, and gadgets, can be anything. It won't crash. When you think about, the desktop area that you see is just a small part of an insanely huge "virtual" desktop, with the top-left of your desktop being co-ordinates 0,0. You can position a window anywhere on the visible desktop, or anywhere outside it in the "virtual" unseen area around it (above, below, left or right).

Here's a visual example which assumes your Windows desktop is 1024x768 pixels:

Code: Select all

-999999,-999999
       +----------------------------------+
       |                                  |
       |                                  |
       |                                  |
       |          0,0                     |
       |           +---------+            |
       |           | Desktop |            |
       |           | display |            |
       |           +---------+            |
       |                 1024,768         |
       |                                  |
       |                                  |
       |                                  |
       +----------------------------------+
                                    999999,999999
Microsoft Visual Basic only lasted 7 short years: 1991 to 1998.
PureBasic: Born in 1998 and still going strong to this very day!
Post Reply