How to grey/blur screen, while own window is on top?

Windows specific forum
va!n
Addict
Addict
Posts: 1104
Joined: Wed Apr 20, 2005 12:48 pm

How to grey/blur screen, while own window is on top?

Post by va!n »

Some years ago, i had a nice source example but i am not really sure how to search for it and how it exactly worked.

Afaik it was a nice Win32 API, which greyed or blured all the shown elements on your monitor (dektop, all windows, taskbar i.e.) and brining your own window original to the front.
In general it looked something like: Create an 50% black color transparent (and maybe blured) borderless fullscreen window to the top of the screen and bringing your own window to the front of the greyed/blurry one. I think it was a special WIn32 API call with fading in/out. Someone an idea? thanks

PS: I am not sure if it was or required something with DWS or not...
va!n aka Thorsten

Intel i7-980X Extreme Edition, 12 GB DDR3, Radeon 5870 2GB, Windows7 x64,
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4946
Joined: Sun Apr 12, 2009 6:27 am

Re: How to grey/blur screen, while own window is on top?

Post by RASHAD »

Hi

Code: Select all

ExamineDesktops()

Procedure Fake(x,y,WW,WH) 
   CreateImage(0,WW,WH) 
   hDC = StartDrawing(ImageOutput(0)) 
            BitBlt_(hDC,0,0,WW,WH,GetDC_(GetDesktopWindow_()), x,y, #SRCCOPY) 
         StopDrawing()
 StartDrawing(ImageOutput(0))
    For x = 0 To WW - 1
      For y = 0 To WH - 1
        color = Point(x, y)
        gray = (Red(color) + Green(color) + Blue(color)) / 3
        gray = RGB(gray, gray, gray)
        Plot(x, y, gray)
      Next y
    Next x
  StopDrawing()
 EndProcedure
 
  
WW = DesktopWidth(0)
WH = DesktopHeight(0)

OpenWindow(0,0,0,WW,HH,"",#PB_Window_BorderLess)
Fake(0,0,WW,WH)   
ImageGadget(0,0,0,WW,HH,ImageID(0))
;DisableGadget(0,1)
SetWindowState(0,#PB_Window_Maximize)

OpenWindow(1,0,0,800,600,"",#PB_Window_SystemMenu |#PB_Window_MinimizeGadget|#PB_Window_MaximizeGadget| #PB_Window_ScreenCentered,WindowID(0))  
StringGadget(1,10,10, 200,24,"",#ES_CENTER)
ButtonGadget(2,10,40,80,22,"Exit")

SetCursorPos_( WindowX(1,#PB_Window_FrameCoordinate)+100, WindowY(1,#PB_Window_FrameCoordinate)+100)

Repeat
  Select WaitWindowEvent()
      Case #PB_Event_CloseWindow
             Quit = 1
             
      Case #WM_MOUSEMOVE
              x = DesktopMouseX()
              y = DesktopMouseY()
                    If x > WindowX(1,#PB_Window_FrameCoordinate)  And x < WindowX(1,#PB_Window_FrameCoordinate) + WindowWidth(1) And y > WindowY(1,#PB_Window_FrameCoordinate) And y < WindowY(1,#PB_Window_FrameCoordinate) + WindowHeight(1)
                       ResizeWindow(0,0,0,WW,WH)               
                   Else                      
                       ResizeWindow(0,0,0,0,0)         
                   EndIf              
       
      Case #PB_Event_Gadget
          Select EventGadget()
            Case 1
              
            Case 2

              
          EndSelect
  EndSelect 
Until Quit =1
Egypt my love
va!n
Addict
Addict
Posts: 1104
Joined: Wed Apr 20, 2005 12:48 pm

Re: How to grey/blur screen, while own window is on top?

Post by va!n »

@Rashad:
Thanks for the code. Sure, this would be "faked" solution.
But as far as i remember, there was / or still is a Win32 API call / function doing this.

@all
I think the same effect was seen on an older Windows version, when the shutdown-dialog was shown.
However, i can find something on the web until now.

Edited:
I found two screenshots on the web showing something simular to what i am searching for as Win32 API function.
http://winsupersite.com/site-files/wins ... _pre04.gif
http://www.gamepc.com/images/labs/rev-x ... downLG.jpg
http://upload.wikimedia.org/wikipedia/e ... 7_flip.png
http://blogs.windows.com/cfs-file.ashx/ ... 5CE303.png
I think there was a blurry effect version too.
va!n aka Thorsten

Intel i7-980X Extreme Edition, 12 GB DDR3, Radeon 5870 2GB, Windows7 x64,
va!n
Addict
Addict
Posts: 1104
Joined: Wed Apr 20, 2005 12:48 pm

Re: How to grey/blur screen, while own window is on top?

Post by va!n »

Nobody an idea? ;)
va!n aka Thorsten

Intel i7-980X Extreme Edition, 12 GB DDR3, Radeon 5870 2GB, Windows7 x64,
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Re: How to grey/blur screen, while own window is on top?

Post by PB »

Something here?

http://www.purebasic.fr/english/viewtopic.php?t=25616

I tried with no luck with the desktop so far.
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
User avatar
Thunder93
Addict
Addict
Posts: 1788
Joined: Tue Mar 21, 2006 12:31 am
Location: Canada

Re: How to grey/blur screen, while own window is on top?

Post by Thunder93 »

Start with

Code: Select all

hWnd.l = OpenWindow(0,0,0,0,0, "", #PB_Window_Maximize | #PB_Window_BorderLess)
ʽʽSuccess is almost totally dependent upon drive and persistence. The extra energy required to make another effort or try another approach is the secret of winning.ʾʾ --Dennis Waitley
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Re: How to grey/blur screen, while own window is on top?

Post by PB »

Thanks Thunder93, that's perfect! :)
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: How to grey/blur screen, while own window is on top?

Post by netmaestro »

Not sure exactly what you're looking for, here's something to try:

Code: Select all

Global quit = 0

Procedure Ask()
  hWnd.l = OpenWindow(1,0,0,0,0, "", #PB_Window_Maximize | #PB_Window_BorderLess)
  SetWindowLongPtr_(hwnd, #GWL_EXSTYLE, GetWindowLongPtr_(hwnd, #GWL_EXSTYLE)|#WS_EX_LAYERED)
  SetLayeredWindowAttributes_(hwnd, 0, 128, #LWA_ALPHA)
  SetWindowColor(1, #Black)
  StickyWindow(1, 1)
  DisableWindow(1, 1)
  If MessageBox_(hwnd, "Are you sure?", "Closing the application", #MB_OKCANCEL|#MB_SYSTEMMODAL) = #IDOK 
    quit = 1
  Else
    CloseWindow(1)
  EndIf
EndProcedure

OpenWindow(0,0,0,640,480,"Cool Application",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)

Repeat
  ev= WaitWindowEvent()
  Select ev
    Case #PB_Event_CloseWindow
      Ask()
  EndSelect
  
Until quit
BERESHEIT
User avatar
Danilo
Addict
Addict
Posts: 3036
Joined: Sat Apr 26, 2003 8:26 am
Location: Planet Earth

Re: How to grey/blur screen, while own window is on top?

Post by Danilo »

netmaestro wrote:

Code: Select all

Procedure Ask()
  hWnd.l = OpenWindow...
Better remove the .l :wink:
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: How to grey/blur screen, while own window is on top?

Post by netmaestro »

I copied it from Thunder93... tell him to remove it! :D
BERESHEIT
User avatar
TI-994A
Addict
Addict
Posts: 2698
Joined: Sat Feb 19, 2011 3:47 am
Location: Singapore
Contact:

Re: How to grey/blur screen, while own window is on top?

Post by TI-994A »

Here's a simplified toggle-able version of SFSxOI's code, using PureBasic's library functions:

Code: Select all

;********************************
;
; minimum client: Windows Vista
;
;********************************

Structure DWM_BLURBEHIND
  dwFlags.l
  fEnable.b
  hRgnBlur.l
  fTransitionOnMaximized.b
EndStructure

Procedure toggleBlur()
  Static blurOverlay
  If blurOverlay
    CloseWindow(blurOverlay)
    blurOverlay = 0
    ProcedureReturn #False
  EndIf
  wFlags = #PB_Window_Maximize | #PB_Window_BorderLess
  blurOverlay = OpenWindow(#PB_Any, 0, 0, 0, 0, "", wFLags)
  SetWindowColor(blurOverlay, 0) 
  
  blurBehind.DWM_BLURBEHIND 
  blurBehind\dwFlags = 1
  blurBehind\fEnable = #True
  blurBehind\fTransitionOnMaximized = #False

  If OpenLibrary(0, "dwmapi.dll")
    *blurFunc = GetFunction(0, "DwmEnableBlurBehindWindow")
    If *blurFunc
      CallFunctionFast(*blurFunc, WindowID(blurOverlay), @blurBehind)
      CloseLibrary(0)  
      ProcedureReturn #True
    EndIf
  EndIf
  ProcedureReturn #False
EndProcedure

Enumeration
  #MainWindow
  #Button
EndEnumeration

wFLags = #PB_Window_SystemMenu | #PB_Window_ScreenCentered
OpenWindow(#Mainwindow, #PB_Any, #PB_Any, 300, 150, "Blurred Background", wFlags)
ButtonGadget(#Button, 50, 50, 200, 50, "Blur the background...")

Repeat
  Select WaitWindowEvent()
    Case #PB_Event_CloseWindow
      appQuit = 1 
    Case #PB_Event_Gadget
      Select EventGadget()
        Case #Button
          If toggleBlur()
            MessageRequester("Desktop Window Manager", 
                             "Background blurred successfully!",
                             #PB_MessageRequester_Ok)
            toggleBlur()
          EndIf
      EndSelect
  EndSelect
Until appQuit = 1
Texas Instruments TI-99/4A Home Computer: the first home computer with a 16bit processor, crammed into an 8bit architecture. Great hardware - Poor design - Wonderful BASIC engine. And it could talk too! Please visit my YouTube Channel :D
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: How to grey/blur screen, while own window is on top?

Post by netmaestro »

; minimum client: Windows Vista
Maximum client: Windows 7. Unfortunately Windows 8 doesn't blur, it just whites out. Aero is gone.
BERESHEIT
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4946
Joined: Sun Apr 12, 2009 6:27 am

Re: How to grey/blur screen, while own window is on top?

Post by RASHAD »

Hi

Code: Select all

SystemParametersInfo_(#SPI_GETWORKAREA, 0, @r.RECT, 0) 

WW = r\right - r\left
WH = r\bottom - r\top

CreateImage(0,WW,WH)
hDC = StartDrawing(ImageOutput(0))
              BitBlt_(hDC,0,0,WW,WH,GetDC_(GetDesktopWindow_()), r\left,r\top, #SRCCOPY)
          StopDrawing()
          StartDrawing(ImageOutput(0))
              For x = 0 To WW - 1
                For y = 0 To WH - 1
                  color = Point(x, y)
                  gray = (Red(color) + Green(color) + Blue(color)) / 3
                  gray = RGB(gray, gray, gray)
                  Plot(x, y, gray)
                Next y
              Next x
          StopDrawing()   

OpenWindow(0,r\left,r\top,WW,WH,"",#PB_Window_BorderLess|#PB_Window_Invisible)

myBrush = CreatePatternBrush_(ImageID(0))
SetClassLongPtr_(WindowID(0), #GCL_HBRBACKGROUND, myBrush)
;InvalidateRect_(WindowID(0),0,1)
FreeImage(0)

AnimateWindow_(WindowID(0),1500,#AW_BLEND|#AW_ACTIVATE)

OpenWindow(1,0,0,800,600,"",#PB_Window_SystemMenu |#PB_Window_MinimizeGadget|#PB_Window_MaximizeGadget| #PB_Window_ScreenCentered,WindowID(0)) 
StringGadget(1,10,10, 200,24,"",#ES_CENTER)
ButtonGadget(2,10,40,80,22,"Exit")

Repeat
  Select WaitWindowEvent()
      Case #PB_Event_CloseWindow
             Quit = 1
             
      Case #PB_Event_Gadget
          Select EventGadget()
            Case 1
             
            Case 2
             
          EndSelect
  EndSelect
Until Quit =1
Egypt my love
User avatar
Thunder93
Addict
Addict
Posts: 1788
Joined: Tue Mar 21, 2006 12:31 am
Location: Canada

Re: How to grey/blur screen, while own window is on top?

Post by Thunder93 »

No excuses! We were taught at an very early age not to be copying from others. If you do copy from others, then their mistakes becomes yours. You must own up to your mistake! :lol:
netmaestro wrote:I copied it from Thunder93... tell him to remove it! :D
ʽʽSuccess is almost totally dependent upon drive and persistence. The extra energy required to make another effort or try another approach is the secret of winning.ʾʾ --Dennis Waitley
User avatar
TI-994A
Addict
Addict
Posts: 2698
Joined: Sat Feb 19, 2011 3:47 am
Location: Singapore
Contact:

Re: How to grey/blur screen, while own window is on top?

Post by TI-994A »

netmaestro wrote:I copied it from Thunder93... tell him to remove it! :D
netmaestro wrote:
; minimum client: Windows Vista
Maximum client: Windows 7. Unfortunately Windows 8 doesn't blur, it just whites out. Aero is gone.
I copied it from MSDN! :lol:
Texas Instruments TI-99/4A Home Computer: the first home computer with a 16bit processor, crammed into an 8bit architecture. Great hardware - Poor design - Wonderful BASIC engine. And it could talk too! Please visit my YouTube Channel :D
Post Reply