Page 1 of 2
How to grey/blur screen, while own window is on top?
Posted: Thu Feb 20, 2014 3:36 pm
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...
Re: How to grey/blur screen, while own window is on top?
Posted: Thu Feb 20, 2014 9:10 pm
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
Re: How to grey/blur screen, while own window is on top?
Posted: Thu Feb 20, 2014 10:05 pm
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.
Re: How to grey/blur screen, while own window is on top?
Posted: Fri Mar 07, 2014 5:10 pm
by va!n
Nobody an idea?

Re: How to grey/blur screen, while own window is on top?
Posted: Sat Mar 08, 2014 4:17 am
by PB
Something here?
http://www.purebasic.fr/english/viewtopic.php?t=25616
I tried with no luck with the desktop so far.
Re: How to grey/blur screen, while own window is on top?
Posted: Sat Mar 08, 2014 4:23 am
by Thunder93
Start with
Code: Select all
hWnd.l = OpenWindow(0,0,0,0,0, "", #PB_Window_Maximize | #PB_Window_BorderLess)
Re: How to grey/blur screen, while own window is on top?
Posted: Sat Mar 08, 2014 5:51 am
by PB
Thanks Thunder93, that's perfect!

Re: How to grey/blur screen, while own window is on top?
Posted: Sat Mar 08, 2014 7:46 am
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
Re: How to grey/blur screen, while own window is on top?
Posted: Sat Mar 08, 2014 8:34 am
by Danilo
netmaestro wrote:Code: Select all
Procedure Ask()
hWnd.l = OpenWindow...
Better remove the .l

Re: How to grey/blur screen, while own window is on top?
Posted: Sat Mar 08, 2014 8:42 am
by netmaestro
I copied it from Thunder93... tell
him to remove it!

Re: How to grey/blur screen, while own window is on top?
Posted: Sat Mar 08, 2014 8:51 am
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
Re: How to grey/blur screen, while own window is on top?
Posted: Sat Mar 08, 2014 9:36 am
by netmaestro
; minimum client: Windows Vista
Maximum client: Windows 7. Unfortunately Windows 8 doesn't blur, it just whites out. Aero is gone.
Re: How to grey/blur screen, while own window is on top?
Posted: Sat Mar 08, 2014 9:43 am
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
Re: How to grey/blur screen, while own window is on top?
Posted: Sat Mar 08, 2014 12:33 pm
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!
netmaestro wrote:I copied it from Thunder93... tell
him to remove it!

Re: How to grey/blur screen, while own window is on top?
Posted: Sat Mar 08, 2014 12:50 pm
by TI-994A
netmaestro wrote:I copied it from Thunder93... tell
him to remove it!

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!
