qsek Posted September 6, 2009 Share Posted September 6, 2009 So initially my goal was to create a "greyed out" treeview item that would look like a disabled menu item: 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: 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: expandcollapse popup#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 Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted September 6, 2009 Moderators Share Posted September 6, 2009 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 Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area  Link to comment Share on other sites More sharing options...
qsek Posted September 6, 2009 Author Share Posted September 6, 2009 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 Link to comment Share on other sites More sharing options...
Malkey Posted September 9, 2009 Share Posted September 9, 2009 So initially my goal was to create a "greyed out" treeview item that would look like a disabled menu item: 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: 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: expandcollapse popup#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. expandcollapse popup; #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 ; Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now