Sign in to follow this  
Followers 0
qsek

Draw shadow behind every text

4 posts in this topic

So initially my goal was to create a "greyed out" treeview item that would look like a disabled menu item:

post-23419-12522145927045_thumb.png

I thought it would be cool to create a GDI Macro function which can take any Text in an GUI (with front and backcolor)

and drop a shadow behind it. So for example it would be possible to customise single items in a listview without having to ownerdraw the whole listview etc.

Though i know all GDI functions and read much examples its still very hard to get a picture of the process to deal with DC's, Selecting Objects,

understand the raster operation modes of BitBlt and so on.

With some luck i managed to make a text shadow with a random color:

post-23419-12522152211438_thumb.png

My problem is now that i want to control the color of the shadow. I tried everything to produce a white shadow, which is required for the "greyed out" look i mentioned above.

It looks like i cannot get beyond the brightness level of the background of the text.

Can anyone help me with this please?

Here is my code so far:

#include <WinAPI.au3>
#include <WindowsConstants.au3>
#include <FontConstants.au3>

Global $tRECT, $hFont, $hOldFont, $hDC

HotKeySet("{ins}", "Nexti")
HotKeySet("{home}", "Nextsi")
HotKeySet("{pgup}", "Nextse")

HotKeySet("{pgdn}", "NextiROP")


$hForm = GUICreate('MyGUI', 600, 150)

$Lint = GUICtrlCreateLabel("", 100, 0, 20,15)
$Lsint = GUICtrlCreateLabel("", 270, 0, 20,15)
$Lsent = GUICtrlCreateLabel("", 470, 0, 20,15)
$Pic = GUICtrlCreateLabel("texttotesttherasteroperations", 20, 20, 560, 60)
GUICtrlSetFont(-1, 31, -1, -1, "Arial")
GUICtrlSetColor(-1, 0x808080)


$hPic = GUICtrlGetHandle($Pic)

GUISetState()


$hDC = _WinAPI_GetDC($hForm)


Dim $loop[17] = [$BLACKNESS, _ ;0   
$CAPTUREBLT, _ ;                1
$DSTINVERT, _ ;                 2
$MERGECOPY, _ ;                 3
$MERGEPAINT, _ ;                4
$NOMIRRORBITMAP, _ ;            5
$NOTSRCCOPY, _ ;                6
$NOTSRCERASE, _ ;               7
$PATCOPY, _ ;                   8
$PATINVERT, _ ;                 9
$PATPAINT, _ ;                  10
$SRCAND, _ ;                    11
$SRCCOPY, _ ;                   12
$SRCERASE, _ ;                  13
$SRCINVERT, _ ;                 14
$SRCPAINT, _ ;                  15
$WHITENESS] ;                   16



$hMemDC = _WinAPI_CreateCompatibleDC($hDC)
$memBmp = _WinAPI_CreateCompatibleBitmap($hDC, 150, 100)
$hOldFont = _WinAPI_SelectObject($hMemDC, $memBmp)


_WinAPI_BitBlt($hMemDC, 20, 20, 150, 60, $hDC, 20, 20, $loop[4])

_WinAPI_InvalidateRect($hForm,0)

    $hMemDC1 = _WinAPI_CreateCompatibleDC($hDC)
    $memBmp1 = _WinAPI_CreateCompatibleBitmap($hDC, 150, 100)
    $hOldFont1 = _WinAPI_SelectObject($hMemDC1, $memBmp1)
    $hBrush1 = _WinAPI_CreateSolidBrush(0xFF00FF)
    _WinAPI_SelectObject($hMemDC1, $hBrush1)


    _WinAPI_BitBlt($hMemDC1, 20, 20, 150, 60, $hMemDC, 20, 20, $loop[10])
    _WinAPI_BitBlt($hDC, 23, 23, 150, 60, $hMemDC1, 20, 20, $loop[11])
    

$i = 0
$si = 0
$se = 0

Func NextiROP()

    _WinAPI_InvalidateRect($hForm,0)

    $hMemDC1 = _WinAPI_CreateCompatibleDC($hDC)
    $memBmp1 = _WinAPI_CreateCompatibleBitmap($hDC, 150, 100)
    $hOldFont1 = _WinAPI_SelectObject($hMemDC1, $memBmp1)
    $hBrush1 = _WinAPI_CreateSolidBrush(0xFF00FF)
    _WinAPI_SelectObject($hMemDC1, $hBrush1)

    $hBrush = _WinAPI_CreateSolidBrush(0xFF00FF)
    _WinAPI_SelectObject($hMemDC, $hBrush)

    _WinAPI_BitBlt($hMemDC, 20, 20, 150, 60, $hDC, 20, 20, $loop[$i])




    _WinAPI_BitBlt($hDC, 40, 40, 150, 60, $hMemDC, 20, 20, $SRCCOPY)        ; left
    
    _WinAPI_BitBlt($hDC, 200, 40, 150, 60, $hMemDC, 20, 20, $loop[$si])     ; middle
    
    _WinAPI_BitBlt($hMemDC1, 20, 20, 150, 60, $hMemDC, 20, 20, $loop[$si])
    _WinAPI_BitBlt($hDC, 400, 40, 150, 60, $hMemDC1, 20, 20, $loop[$se])    ; right
    
    
    GUICtrlSetData($Lint, $i)
    GUICtrlSetData($Lsint, $si)
    GUICtrlSetData($Lsent, $se)
    
EndFunc

Func Nexti()
    $i += 1
    If $i > 16 Then
        $i = 0
    EndIf
    NextiROP()
EndFunc

Func Nextsi()
    $si += 1
    If $si > 16 Then $si = 0
    NextiROP()
EndFunc

Func Nextse()
    $se += 1
    If $se > 16 Then $se = 0
    NextiROP()
EndFunc


While 1
    If GUIGetMsg() = -3 Then _Exit()
WEnd





Func _Exit()
    _WinAPI_SelectObject($hMemDC, $hOldFont)
    _WinAPI_DeleteObject($memBmp)
    _WinAPI_ReleaseDC($hForm, $hMemDC)
    _WinAPI_ReleaseDC($hForm, $hDC)
    
;~  _WinAPI_InvalidateRect(0, 0)
    $tRECT = 0
    Exit
EndFunc   ;==>_Exit

(I know there are a lot of missing ReleaseDC's and DeleteObject's, just want to make it work first)


Teamspeak 3 User Viewer - Quick and functional TS3 Query script, which shows online users.Cached Screenshot Deleter - Deletes older Fraps Screenshots if they exceed a specified limit.Unresolved Topics:Intercept and modify dragdrop text behaviour in scite

Share this post


Link to post
Share on other sites



qsek,

You may find this interesting.

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

Thanks, but you missed my point. I dont want to create a text and its shadow. I want to create the shadow out of any bitmap or device context on my GUI. I can not use DrawShadowText on a treeview item.


Teamspeak 3 User Viewer - Quick and functional TS3 Query script, which shows online users.Cached Screenshot Deleter - Deletes older Fraps Screenshots if they exceed a specified limit.Unresolved Topics:Intercept and modify dragdrop text behaviour in scite

Share this post


Link to post
Share on other sites

So initially my goal was to create a "greyed out" treeview item that would look like a disabled menu item:

post-23419-12522145927045_thumb.png

I thought it would be cool to create a GDI Macro function which can take any Text in an GUI (with front and backcolor)

and drop a shadow behind it. So for example it would be possible to customise single items in a listview without having to ownerdraw the whole listview etc.

Though i know all GDI functions and read much examples its still very hard to get a picture of the process to deal with DC's, Selecting Objects,

understand the raster operation modes of BitBlt and so on.

With some luck i managed to make a text shadow with a random color:

post-23419-12522152211438_thumb.png

My problem is now that i want to control the color of the shadow. I tried everything to produce a white shadow, which is required for the "greyed out" look i mentioned above.

It looks like i cannot get beyond the brightness level of the background of the text.

Can anyone help me with this please?

Here is my code so far:

#include <WinAPI.au3>
#include <WindowsConstants.au3>
#include <FontConstants.au3>

Global $tRECT, $hFont, $hOldFont, $hDC

HotKeySet("{ins}", "Nexti")
HotKeySet("{home}", "Nextsi")
HotKeySet("{pgup}", "Nextse")

HotKeySet("{pgdn}", "NextiROP")


$hForm = GUICreate('MyGUI', 600, 150)

$Lint = GUICtrlCreateLabel("", 100, 0, 20,15)
$Lsint = GUICtrlCreateLabel("", 270, 0, 20,15)
$Lsent = GUICtrlCreateLabel("", 470, 0, 20,15)
$Pic = GUICtrlCreateLabel("texttotesttherasteroperations", 20, 20, 560, 60)
GUICtrlSetFont(-1, 31, -1, -1, "Arial")
GUICtrlSetColor(-1, 0x808080)


$hPic = GUICtrlGetHandle($Pic)

GUISetState()


$hDC = _WinAPI_GetDC($hForm)


Dim $loop[17] = [$BLACKNESS, _ ;0   
$CAPTUREBLT, _ ;                1
$DSTINVERT, _ ;                 2
$MERGECOPY, _ ;                 3
$MERGEPAINT, _ ;                4
$NOMIRRORBITMAP, _ ;            5
$NOTSRCCOPY, _ ;                6
$NOTSRCERASE, _ ;               7
$PATCOPY, _ ;                   8
$PATINVERT, _ ;                 9
$PATPAINT, _ ;                  10
$SRCAND, _ ;                    11
$SRCCOPY, _ ;                   12
$SRCERASE, _ ;                  13
$SRCINVERT, _ ;                 14
$SRCPAINT, _ ;                  15
$WHITENESS] ;                   16



$hMemDC = _WinAPI_CreateCompatibleDC($hDC)
$memBmp = _WinAPI_CreateCompatibleBitmap($hDC, 150, 100)
$hOldFont = _WinAPI_SelectObject($hMemDC, $memBmp)


_WinAPI_BitBlt($hMemDC, 20, 20, 150, 60, $hDC, 20, 20, $loop[4])

_WinAPI_InvalidateRect($hForm,0)

    $hMemDC1 = _WinAPI_CreateCompatibleDC($hDC)
    $memBmp1 = _WinAPI_CreateCompatibleBitmap($hDC, 150, 100)
    $hOldFont1 = _WinAPI_SelectObject($hMemDC1, $memBmp1)
    $hBrush1 = _WinAPI_CreateSolidBrush(0xFF00FF)
    _WinAPI_SelectObject($hMemDC1, $hBrush1)


    _WinAPI_BitBlt($hMemDC1, 20, 20, 150, 60, $hMemDC, 20, 20, $loop[10])
    _WinAPI_BitBlt($hDC, 23, 23, 150, 60, $hMemDC1, 20, 20, $loop[11])
    

$i = 0
$si = 0
$se = 0

Func NextiROP()

    _WinAPI_InvalidateRect($hForm,0)

    $hMemDC1 = _WinAPI_CreateCompatibleDC($hDC)
    $memBmp1 = _WinAPI_CreateCompatibleBitmap($hDC, 150, 100)
    $hOldFont1 = _WinAPI_SelectObject($hMemDC1, $memBmp1)
    $hBrush1 = _WinAPI_CreateSolidBrush(0xFF00FF)
    _WinAPI_SelectObject($hMemDC1, $hBrush1)

    $hBrush = _WinAPI_CreateSolidBrush(0xFF00FF)
    _WinAPI_SelectObject($hMemDC, $hBrush)

    _WinAPI_BitBlt($hMemDC, 20, 20, 150, 60, $hDC, 20, 20, $loop[$i])




    _WinAPI_BitBlt($hDC, 40, 40, 150, 60, $hMemDC, 20, 20, $SRCCOPY)        ; left
    
    _WinAPI_BitBlt($hDC, 200, 40, 150, 60, $hMemDC, 20, 20, $loop[$si])     ; middle
    
    _WinAPI_BitBlt($hMemDC1, 20, 20, 150, 60, $hMemDC, 20, 20, $loop[$si])
    _WinAPI_BitBlt($hDC, 400, 40, 150, 60, $hMemDC1, 20, 20, $loop[$se])    ; right
    
    
    GUICtrlSetData($Lint, $i)
    GUICtrlSetData($Lsint, $si)
    GUICtrlSetData($Lsent, $se)
    
EndFunc

Func Nexti()
    $i += 1
    If $i > 16 Then
        $i = 0
    EndIf
    NextiROP()
EndFunc

Func Nextsi()
    $si += 1
    If $si > 16 Then $si = 0
    NextiROP()
EndFunc

Func Nextse()
    $se += 1
    If $se > 16 Then $se = 0
    NextiROP()
EndFunc


While 1
    If GUIGetMsg() = -3 Then _Exit()
WEnd





Func _Exit()
    _WinAPI_SelectObject($hMemDC, $hOldFont)
    _WinAPI_DeleteObject($memBmp)
    _WinAPI_ReleaseDC($hForm, $hMemDC)
    _WinAPI_ReleaseDC($hForm, $hDC)
    
;~  _WinAPI_InvalidateRect(0, 0)
    $tRECT = 0
    Exit
EndFunc   ;==>_Exit

(I know there are a lot of missing ReleaseDC's and DeleteObject's, just want to make it work first)

I had a little play around with your script.

I never got into the hot keys, but the initial displayed shadow effect on the button control and on the text in the label control is interesting.

;
#include <WinAPI.au3>
#include <WindowsConstants.au3>
#include <FontConstants.au3>

Global $tRECT, $hFont, $hOldFont, $hDC

HotKeySet("{ins}", "Nexti")
HotKeySet("{home}", "Nextsi")
HotKeySet("{pgup}", "Nextse")
HotKeySet("{pgdn}", "NextiROP")

$hForm = GUICreate('MyGUI', 600, 150)
GUISetBkColor(0xFFFFFF, $hForm)
$Lint = GUICtrlCreateLabel("", 100, 0, 20, 15)
$Lsint = GUICtrlCreateLabel("", 270, 0, 20, 15)
$Lsent = GUICtrlCreateLabel("", 470, 0, 20, 15)
$Pic = GUICtrlCreateLabel("Text to test raster operations.", 20, 20, 560, 60)

GUICtrlSetFont(-1, 31, -1, -1, "Arial")
$But = GUICtrlCreateButton("Press", 90, 90, 110, 40)
GUICtrlSetColor(-1, 0xBBBBBB)

$hPic = GUICtrlGetHandle($Pic)

GUISetState()

$hDC = _WinAPI_GetDC($hForm)

Global $loop[17] = [$BLACKNESS, _     ;                0
                    $CAPTUREBLT, _ ;                1
                    $DSTINVERT, _ ;                 2
                    $MERGECOPY, _ ;                 3
                    $MERGEPAINT, _ ;                4
                    $NOMIRRORBITMAP, _ ;            5
                    $NOTSRCCOPY, _ ;                6
                    $NOTSRCERASE, _ ;               7
                    $PATCOPY, _ ;                   8
                    $PATINVERT, _ ;                 9
                    $PATPAINT, _ ;                  10
                    $SRCAND, _ ;                    11
                    $SRCCOPY, _ ;                   12
                    $SRCERASE, _ ;                  13
                    $SRCINVERT, _ ;                 14
                    $SRCPAINT, _ ;                  15
                    $WHITENESS] ;                   16

$hMemDC = _WinAPI_CreateCompatibleDC($hDC)
$memBmp = _WinAPI_CreateCompatibleBitmap($hDC, 550, 130)
$hOldFont = _WinAPI_SelectObject($hMemDC, $memBmp)

_WinAPI_BitBlt($hMemDC, 20, 20, 550, 130, $hDC, 20, 20, $loop[4])

_WinAPI_InvalidateRect($hForm, 0)

$hMemDC1 = _WinAPI_CreateCompatibleDC($hDC)
$memBmp1 = _WinAPI_CreateCompatibleBitmap($hDC, 550, 130)
$hOldFont1 = _WinAPI_SelectObject($hMemDC1, $memBmp1)
$hBrush1 = _WinAPI_CreateSolidBrush(0xCCCCCC)
_WinAPI_SelectObject($hMemDC1, $hBrush1)

_WinAPI_BitBlt($hMemDC1, 20, 20, 550, 130, $hMemDC, 20, 20, $loop[10])
_WinAPI_BitBlt($hDC, 23, 23, 550, 130, $hMemDC1, 20, 20, $loop[11])

$i = 0
$si = 0
$se = 0

While 1
    If GUIGetMsg() = -3 Then _Exit()
WEnd

Func _Exit()
    _WinAPI_SelectObject($hMemDC, $hOldFont)
    _WinAPI_DeleteObject($memBmp)
    _WinAPI_ReleaseDC($hForm, $hMemDC)
    _WinAPI_ReleaseDC($hForm, $hDC)
;~  _WinAPI_InvalidateRect(0, 0)
    $tRECT = 0
    Exit
EndFunc   ;==>_Exit

Func NextiROP()
    _WinAPI_InvalidateRect($hForm,0)
    $hMemDC1 = _WinAPI_CreateCompatibleDC($hDC)
    $memBmp1 = _WinAPI_CreateCompatibleBitmap($hDC, 150, 100)
    $hOldFont1 = _WinAPI_SelectObject($hMemDC1, $memBmp1)
    $hBrush1 = _WinAPI_CreateSolidBrush(0xFF00FF)
    _WinAPI_SelectObject($hMemDC1, $hBrush1)

    $hBrush = _WinAPI_CreateSolidBrush(0xFF00FF)
    _WinAPI_SelectObject($hMemDC, $hBrush)

    _WinAPI_BitBlt($hMemDC, 20, 20, 150, 60, $hDC, 20, 20, $loop[$i])

    _WinAPI_BitBlt($hDC, 40, 40, 150, 60, $hMemDC, 20, 20, $SRCCOPY)        ; left

    _WinAPI_BitBlt($hDC, 200, 40, 150, 60, $hMemDC, 200, 20, $loop[$si])     ; middle

    _WinAPI_BitBlt($hMemDC1, 20, 20, 150, 60, $hMemDC, 20, 20, $loop[$si])
    _WinAPI_BitBlt($hDC, 400, 40, 150, 60, $hMemDC1, 400, 20, $loop[$se])    ; right

    GUICtrlSetData($Lint, $i)
    GUICtrlSetData($Lsint, $si)
    GUICtrlSetData($Lsent, $se)
EndFunc

Func Nexti()
    $i += 1
    If $i > 16 Then
        $i = 0
    EndIf
    NextiROP()
EndFunc   ;==>Nexti

Func Nextsi()
    $si += 1
    If $si > 16 Then $si = 0
    NextiROP()
EndFunc   ;==>Nextsi

Func Nextse()
    $se += 1
    If $se > 16 Then $se = 0
    NextiROP()
EndFunc   ;==>Nextse
;

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