Sign in to follow this  
Followers 0
cyberlive

setforeground with blurred / out of focus background

9 posts in this topic

Good day All -

Before I have the main GUI for an application presented to the user, i have a msgbox with a yesno option for the user to accept or decline.  I have that msgbox set with the setforeground, but I am struggling with how (if possible) to blur out the background of the rest of the screen size so that only the msgbox is in focus.

Thanks as always --

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Try this:

#include <Screencapture.au3>
#include <WindowsConstants.au3>

_GDIPlus_Startup()

Message("Is this what you are looking for?")

_GDIPlus_Shutdown()


Func Message($sText, $sHeader = "Question", $iFlag = 4 + 32 + 262144, $iBlur = 5) ;coded by UEZ
    Local Const $iW = @DesktopWidth, $iH = @DesktopHeight
    Local $hGui = GUICreate("", $iW, $iH, 0, 0, $WS_POPUP, BitOR($WS_EX_TOPMOST, $WS_EX_APPWINDOW))
    Local $hGraphics = _GDIPlus_GraphicsCreateFromHWND($hGui)
    Local $hHBitmap = _ScreenCapture_Capture("", 0, 0, $iW - 1, $iH - 1, 0)
    Local $hBitmap = _GDIPlus_BitmapCreateFromHBITMAP($hHBitmap)
    _WinAPI_DeleteObject($hHBitmap)
    Local $hEffect = _GDIPlus_EffectCreateBlur($iBlur)
    _GDIPlus_BitmapApplyEffect($hBitmap, $hEffect)
    GUISetState(@SW_SHOWNA)
    _GDIPlus_GraphicsDrawImageRect($hGraphics, $hBitmap, 0, 0, $iW, $iH)
    Local $iRet = MsgBox($iFlag, $sHeader, $sText, 0, $hGui)
    _GDIPlus_EffectDispose($hEffect)
    _GDIPlus_BitmapDispose($hBitmap)
    _GDIPlus_GraphicsDispose($hGraphics)
    GUIDelete($hGui)
    Return $iRet
EndFunc

Runs only with MS Vista or higher operating system and latest AutoIt version!

 

 

Br,

UEZ

Edited by UEZ
1 person likes this

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯

Share this post


Link to post
Share on other sites

Thanks UEZ

I just tried that and that is the effect i am after.  A little deeper perhaps, but is there a way to set a 'degree' to which the out of focus effect is displayed?  I am taking a look through the documentation on $hEffect, $hBitmap, etc... but do not see it defined.


Share this post


Link to post
Share on other sites

Look at _GDIPlus_EffectCreateBlur in the help file to set the blur radius. Variables are variables and not documented in the help file - that wouldn't make any sense.

Br,

UEZ


Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯

Share this post


Link to post
Share on other sites

Thank you JohnOne and UEZ.  That did it.

Share this post


Link to post
Share on other sites

UEZ,

Splendid! :thumbsup:

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

Thanks Melba23.

I made some small modifications to the code above.

@cyberlive: you are welcome. The code above doesn't support multi monitors. Homework: modify the code that it supports multi monitors. :)

Br,

UEZ

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

The GDI+ v1.1 built-in blur code is too slow and the effect doesn't look very well at least on my Win 8.1 notebook.

I changed the code a little bit using the blur code from eukalyptus and added an option to blur-in (by default not enabled) the image.

The code doesn't require GDI+ v1.1 and should run also on WinXP (not tested).

#include <GDIPlus.au3>
#include <WindowsConstants.au3>

_GDIPlus_Startup()

MessageBoxBlurBackground("Is this what you are looking for?")

_GDIPlus_Shutdown()


Func MessageBoxBlurBackground($sText, $sHeader = "Question", $iFlag = 4 + 32 + 262144, $fBlur = 0.15, $bBlurIn = False, $iTimeOut = 0) ;coded by UEZ
    Local $hFullScreen = WinGetHandle("[TITLE:Program Manager;CLASS:Progman]"), $aFullScreen = WinGetPos($hFullScreen)
    Local Const $iW = $aFullScreen[2], $iH = $aFullScreen[3]
    Local $hGui = GUICreate("", $iW, $iH, $aFullScreen[0], $aFullScreen[1], $WS_POPUP, BitOR($WS_EX_TOPMOST, $WS_EX_APPWINDOW))
    Local $hGraphics = _GDIPlus_GraphicsCreateFromHWND($hGui)

    ;capture full screen
    Local $hWnd = _WinAPI_GetDesktopWindow()
    Local $hDDC = _WinAPI_GetDC($hWnd)
    Local $hCDC = _WinAPI_CreateCompatibleDC($hDDC)
    Local $hHBitmap = _WinAPI_CreateCompatibleBitmap($hDDC, $iW, $iH)
    _WinAPI_SelectObject($hCDC, $hHBitmap)
    _WinAPI_BitBlt($hCDC, 0, 0, $iW, $iH, $hDDC, $aFullScreen[0], $aFullScreen[1], $SRCCOPY) ;copy captured screen to bitmap
    _WinAPI_ReleaseDC($hWnd, $hDDC)
    _WinAPI_DeleteDC($hCDC)

    Local $hBitmap = _GDIPlus_BitmapCreateFromHBITMAP($hHBitmap) ;convert GDI bitmap to GDI+ bitmap
    _WinAPI_DeleteObject($hHBitmap)

    Local $hBmp_GDIPlus_BitmapBlurred, $i
    Switch $bBlurIn
        Case True
            GUISetState(@SW_SHOWNA)
            For $i = 2 To 7 Step 0.5
                $hBmp_GDIPlus_BitmapBlurred = _GDIPlus_BitmapBlur($hBitmap, $iW, $iH, 1 / $i)
                _GDIPlus_GraphicsDrawImageRect($hGraphics, $hBmp_GDIPlus_BitmapBlurred, 0, 0, $iW, $iH) ;copy blurred image to GUI
                _GDIPlus_BitmapDispose($hBmp_GDIPlus_BitmapBlurred)
            Next
        Case Else
            $hBmp_GDIPlus_BitmapBlurred = _GDIPlus_BitmapBlur($hBitmap, $iW, $iH, $fBlur)
            GUISetState(@SW_SHOWNA)
            _GDIPlus_GraphicsDrawImageRect($hGraphics, $hBmp_GDIPlus_BitmapBlurred, 0, 0, $iW, $iH) ;copy blurred image to GUI
            _GDIPlus_BitmapDispose($hBmp_GDIPlus_BitmapBlurred)
    EndSwitch

    Local $iRet = MsgBox($iFlag, $sHeader, $sText, $iTimeOut, $hGui)

    ;cleanup resources
    _GDIPlus_BitmapDispose($hBitmap)
    _GDIPlus_GraphicsDispose($hGraphics)
    GUIDelete($hGui)
    Return $iRet
EndFunc

Func _GDIPlus_BitmapBlur($hBitmap, $iW, $iH, $fScale = 0.15, $qual = 6); by eukalyptus
    Local Const $hGraphics = _GDIPlus_GraphicsCreateFromHWND(_WinAPI_GetDesktopWindow())
    Local Const $hBmpSmall = _GDIPlus_BitmapCreateFromGraphics($iW, $iH, $hGraphics)
    Local Const $hGfxSmall = _GDIPlus_ImageGetGraphicsContext($hBmpSmall)
    _GDIPlus_GraphicsSetPixelOffsetMode($hGfxSmall, $GDIP_PIXELOFFSETMODE_HIGHQUALITY)
    Local Const $hBmpBig = _GDIPlus_BitmapCreateFromGraphics($iW, $iH, $hGraphics)
    Local Const $hGfxBig = _GDIPlus_ImageGetGraphicsContext($hBmpBig)
    _GDIPlus_GraphicsSetPixelOffsetMode($hGfxBig, $GDIP_PIXELOFFSETMODE_HIGHQUALITY)
    _GDIPlus_GraphicsScaleTransform($hGfxSmall, $fScale, $fScale)
    _GDIPlus_GraphicsSetInterpolationMode($hGfxSmall, $qual)

    _GDIPlus_GraphicsScaleTransform($hGfxBig, 1 / $fScale, 1 / $fScale)
    _GDIPlus_GraphicsSetInterpolationMode($hGfxBig, $qual)

    _GDIPlus_GraphicsDrawImageRect($hGfxSmall, $hBitmap, 0, 0, $iW, $iH)
    _GDIPlus_GraphicsDrawImageRect($hGfxBig, $hBmpSmall, 0, 0, $iW, $iH)

    _GDIPlus_GraphicsDispose($hGraphics)
    _GDIPlus_BitmapDispose($hBmpSmall)
    _GDIPlus_GraphicsDispose($hGfxSmall)
    _GDIPlus_GraphicsDispose($hGfxBig)
    Return $hBmpBig
EndFunc   ;==>_GDIPlus_BitmapBlur

Br,

UEZ

Edited by UEZ
3 people like this

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0