Homes32 Posted January 27, 2010 Posted January 27, 2010 Greetings!I'm trying to make my button have a transparent background so that only my icon with rounded edges is visible. the main issue I have is that I need the button to be selectable by using the tab key (hotkeys aren't an option) on my keyboard, so I can't use an image itself as a button. (unless somebody knows how to make an image accept tabstop) I have also tried using ChrisL's function to make the button transparent and draw the image on top, as well as XSkin and ezSkin but these all have the same issue, I can't tab on the button. GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT) is also worthless as it doesn't seem to affect buttons at all.Any ideas on how I can accomplish this?I have attached a link to the code for the above example if anybody wants to have a go at making it work.ButtonTest.rar-Homes32
picea892 Posted January 27, 2010 Posted January 27, 2010 Yes you can add a tabstop using the following Global $pic2 = GUICtrlCreatePic("", 100, $goingdown+40, 50, 25,$WS_TABSTOP) Let me know if doesn't work for you or you need help on the transparency related.
Homes32 Posted January 27, 2010 Author Posted January 27, 2010 (edited) Yes you can add a tabstop using the following Global $pic2 = GUICtrlCreatePic("", 100, $goingdown+40, 50, 25,$WS_TABSTOP) Let me know if doesn't work for you or you need help on the transparency related. hmm. I tried that but I could never get any response when I hit "enter" (the whole point of being able to tab to a control) and no focus dots around the image. is there a test I can use to see if a image control has focus? Edited January 27, 2010 by Homes32
Homes32 Posted January 27, 2010 Author Posted January 27, 2010 ok. I verified that the image control is getting the focus when I use $WS_TABSTOP but it still won't notify on "enter" any ideas? expandcollapse popup#AutoIt3Wrapper_Res_Icon_Add=Lock.ico #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <Constants.au3> ; defines $IMAGE_ICON #include <WinAPI.au3> #Include <Icons.au3> #include <GuiButton.au3> Global Const $sFont = "Tahoma" Global Const $sFontColor = 0xFFFFFF ; load icon resources $hLockIcon = _WinAPI_LoadImage(_WinAPI_GetModuleHandle(0), 201, $IMAGE_ICON, 48, 48, 0) $Form = GUICreate("Button Test", 300, 65, -1, -1, BitOR($WS_DLGFRAME,$WS_POPUP,$DS_SETFOREGROUND), BitOR($WS_EX_TOPMOST,$WS_EX_WINDOWEDGE)) $BackgroundImage = GUICtrlCreatePic("Background.bmp", 0, 0, 300, 65) GUICtrlSetState(-1,$GUI_DISABLE) ; how the button looks with no transparent background $BTN_Lock = GUICtrlCreateButton("BTN_Lock", 240, 8, 48, 48, BitOR($BS_ICON, $BS_FLAT)) ; I use GUICtrlSendMsg so I can pick my custom size from the .ico GUICtrlSendMsg($BTN_Lock, 247, 1, $hLockIcon) ; BM_SETIMAGE = 247, 1 = IMAGE_ICON ; example of how I would like the button to look ; uses Icons.au3 so the icon shows the $BackgroundImage behind it instead of the form backgrond color $LockImage = GUICtrlCreatePic("", 8, 8, 48, 48,BitOR($SS_NOTIFY, $WS_TABSTOP)); $hBitmap = _Icons_Bitmap_CreateFromIcon($hLockIcon) _SetHImage($LockImage, $hBitmap) $LBL_Caption = GUICtrlCreateLabel("",70,10,28,15) GUISetState(@SW_SHOW) ;********************************************************************** ; Main Loop ;********************************************************************** While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $LockImage MsgBox(0,"Test","Lock image pressed") Case $BTN_Lock Exit EndSwitch $ctrl = _GUICtrlStatic_GetFocus($LockImage) GUICtrlSetData($LBL_Caption,$ctrl) WEnd ;Sleep(8000) ; cleanup GUIDelete($Form) If $hBitmap Then _WinAPI_DeleteObject($hBitmap) If $hLockIcon Then _WinAPI_DestroyIcon($hLockIcon) ; #FUNCTION# ==================================================================================================================== ; Name...........: _GUICtrlStatic_GetFocus ; Description ...: Retrieves if the static control has keyboard focus ; Syntax.........: _GUICtrlStatic_GetFocus($hWnd) ; Parameters ....: $hWnd - Handle to the control ; Return values .: True - Object has focus ; False - Object does not have focus ; Author ........: Jonathan Holmgren (Homes32) ; Modified.......: ; Remarks .......: ; Related .......: _GUICtrlStatic_SetFocus ; Link ..........: ; Example .......: Yes ; =============================================================================================================================== Func _GUICtrlStatic_GetFocus($hWnd) If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd) If _WinAPI_IsClassName($hWnd, "Static") Then Return _WinAPI_GetFocus() = $hWnd EndFunc ;==>_GUICtrlStatic_GetFocus
picea892 Posted January 27, 2010 Posted January 27, 2010 Hmm, makes sense that a picture can't receive enter but was surprised. Not really happy with using guictrlsetaccelerators but it seems easy and works....I'm curious now and will keep looking. expandcollapse popup#AutoIt3Wrapper_Res_Icon_Add=Lock.ico #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <Constants.au3> ; defines $IMAGE_ICON #include <WinAPI.au3> #Include <Icons.au3> #include <GuiButton.au3> Global Const $sFont = "Tahoma" Global Const $sFontColor = 0xFFFFFF ; load icon resources $hLockIcon = _WinAPI_LoadImage(_WinAPI_GetModuleHandle(0), 201, $IMAGE_ICON, 48, 48, 0) $Form = GUICreate("Button Test", 300, 65, -1, -1, BitOR($WS_DLGFRAME,$WS_POPUP,$DS_SETFOREGROUND), BitOR($WS_EX_TOPMOST,$WS_EX_WINDOWEDGE)) $BackgroundImage = GUICtrlCreatePic("Background.bmp", 0, 0, 300, 65) GUICtrlSetState(-1,$GUI_DISABLE) ; how the button looks with no transparent background $BTN_Lock = GUICtrlCreateButton("BTN_Lock", 240, 8, 48, 48, BitOR($BS_ICON, $BS_FLAT)) ; I use GUICtrlSendMsg so I can pick my custom size from the .ico GUICtrlSendMsg($BTN_Lock, 247, 1, $hLockIcon) ; BM_SETIMAGE = 247, 1 = IMAGE_ICON ; example of how I would like the button to look ; uses Icons.au3 so the icon shows the $BackgroundImage behind it instead of the form backgrond color $LockImage = GUICtrlCreatePic("", 8, 8, 48, 48,BitOR($SS_NOTIFY, $WS_TABSTOP)); $hBitmap = _Icons_Bitmap_CreateFromIcon($hLockIcon) _SetHImage($LockImage, $hBitmap) $LBL_Caption = GUICtrlCreateLabel("",70,10,28,15) $Dum = GUICtrlCreateDummy() Dim $accels[1][2] = [["{ENTER}", $Dum]] GUISetAccelerators($accels) GUISetState(@SW_SHOW) ;********************************************************************** ; Main Loop ;********************************************************************** While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Dum if _GUICtrlStatic_GetFocus($LockImage)=true then ToolTip("Lock image pressed") sleep(2000) ToolTip("") EndIf Case $BTN_Lock Exit EndSwitch $ctrl = _GUICtrlStatic_GetFocus($LockImage) GUICtrlSetData($LBL_Caption,$ctrl) WEnd ;Sleep(8000) ; cleanup GUIDelete($Form) If $hBitmap Then _WinAPI_DeleteObject($hBitmap) If $hLockIcon Then _WinAPI_DestroyIcon($hLockIcon) ; #FUNCTION# ==================================================================================================================== ; Name...........: _GUICtrlStatic_GetFocus ; Description ...: Retrieves if the static control has keyboard focus ; Syntax.........: _GUICtrlStatic_GetFocus($hWnd) ; Parameters ....: $hWnd - Handle to the control ; Return values .: True - Object has focus ; False - Object does not have focus ; Author ........: Jonathan Holmgren (Homes32) ; Modified.......: ; Remarks .......: ; Related .......: _GUICtrlStatic_SetFocus ; Link ..........: ; Example .......: Yes ; =============================================================================================================================== Func _GUICtrlStatic_GetFocus($hWnd) If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd) If _WinAPI_IsClassName($hWnd, "Static") Then Return _WinAPI_GetFocus() = $hWnd EndFunc ;==>_GUICtrlStatic_GetFocus
Homes32 Posted January 28, 2010 Author Posted January 28, 2010 I was a bit surprised myself. it only stands to reason that a control that is set to notify and tabstop should be able to accept enter. but since when do the good people at Microsoft use reason when designing windows? the accelerators workaround is crude but it does work...one issue i can see with this method is having to add all "real" button controls to the Case $Dum to be checked for enter along with the rest. it will be interesting to see if you I, or anybody else can come up with a method that works better.
picea892 Posted January 28, 2010 Posted January 28, 2010 Hi again, I dug around some of my old test scripts and found one I had made before that might serve as an example. It uses a dllcallbackregister and may be more complicated than what you are looking for. expandcollapse popup#include <Constants.au3> #include <WinAPI.au3> #include <GDIPlus.au3> #include <WindowsConstants.au3> Global Const $VK_RETURN = 0x0D ;Enter key $nth=5 Global $ctrlhwd[2][2], $hOldFunc[2], $focusnumber=1, $input[$nth],$onoff=0, $focussed=0, $actthebut=0 Global $outlook=GUICreate('Outlook', 300, 40*$nth) $hFunc = DllCallbackRegister('InputHandler', 'lparam', 'hwnd;uint;wparam;lparam') $goingdown=20 for $j= 1 to $nth-1 $Input[$j] = GUICtrlCreateInput('', 20, $goingdown, 260, 25) focushandler($Input[$j],1) ;anything that can be tabbed needs to be excluded using a 0 or set to no-tab $goingdown=$goingdown+30 Next Global $pic = GUICtrlCreatePic("", 100, $goingdown, 50, 25,$WS_TABSTOP) GUICtrlSetOnEvent($pic ,"picactions") SetIcon($pic ,64, 25, "0xAA8866", "0x441100", 1,1, "Finish") focushandler($pic,0) ;anything that can be tabbed needs to be excluded using a 0 or set to no-tab ; _WinAPI_RedrawWindow(GUICtrlGetHandle($pic )) GUISetState() Do Sleep(20) hovered() Until GUIGetMsg() = -3 GUIDelete() DllCallbackFree($hFunc) Func InputHandler($hWnd, $iMsg, $wParam, $lParam) for $i =1 to UBound($ctrlhwd)-1 If $hWnd = $ctrlhwd[$i][0] Then $hOldF = $hOldFunc[$i] $include=$ctrlhwd[$i][1] EndIf next If $iMsg = $WM_SETFOCUS Then if $include=1 then GUICtrlSetBkColor(_WinAPI_GetDlgCtrlID($hWnd), 0xE9E9E9) GUICtrlSetBkColor(_WinAPI_GetDlgCtrlID($wParam), 0xFFFFFF) if $hWnd=GUICtrlGetHandle($pic) and $actthebut=0 then SetIcon($pic ,64, 25, "0x331111", "0x662200", 1,1, "Finish",1) $actthebut=1 ElseIf $hWnd<>GUICtrlGetHandle($pic) and $actthebut=1 then SetIcon($pic ,64, 25, "0xAA8866", "0x441100", 1,1, "Finish") $actthebut=0 EndIf elseIf $iMsg = 0x0100 Then ; ToolTip(ControlGetText("Test","",$hWnd)) elseIf $wParam = $VK_RETURN then if $hWnd=GUICtrlGetHandle($pic) then MsgBox(0,"","Execute") ConsoleWrite("RETURN") EndIf Return _WinAPI_CallWindowProc($hOldF, $hWnd, $iMsg, $wParam, $lParam) EndFunc func focushandler($Inpx,$inout) GUICtrlSetFont($Inpx,"",11,400,"Arial") $ctrlhwd[$focusnumber][0] = GUICtrlGetHandle($Inpx) $ctrlhwd[$focusnumber][1] = $inout $hOldFunc[$focusnumber] = _WinAPI_GetWindowLong($ctrlhwd[$focusnumber][0], $GWL_WNDPROC) _WinAPI_SetWindowLong($ctrlhwd[$focusnumber][0], $GWL_WNDPROC, DllCallbackGetPtr($hFunc)) $focusnumber=$focusnumber+1 ReDim $ctrlhwd[ubound($ctrlhwd)+1][2] ReDim $hOldFunc[ubound($hOldFunc)+1] EndFunc func SetIcon($controlID, $iWidth, $iHeight, $iClr1="0x111111", $iClr2="0x999999", $iDirection=2, $pressed=0,$string="", $hovered=0) Local $aFactors[4] = [0.0, 0.6, 0.8, 1.0], $aPositions[4] = [0.0, 0.6, 0.8, 1.0] Local $bGammaCorrection = False const $STM_SETIMAGE = 0x0172 $tIcon = DllStructCreate('hwnd') $tID = DllStructCreate('hwnd') if $hovered=0 then Local $fname="Arial", $fsize=12,$fstyle=0, $fcolour=0xFFCECDB4 local $posedh=3,$posedw=5 Else Local $fname="Arial", $fsize=14,$fstyle=1, $fcolour=0xFFFFFFFF local $posedh=1,$posedw=1 EndIf _GDIPlus_Startup() Local Const $IMAGE_BITMAP = 0 Local $hWnd, $iC1, $iC2, $hBitmap, $hImage, $hGraphic, $hBrushLin, $hbmp, $aBmp $hWnd = GUICtrlGetHandle($controlID) $iC1 = StringReplace($iClr1, "0x", "0xFF") $iC2 = StringReplace($iClr2, "0x", "0xFF") $hBitmap = _WinAPI_CreateBitmap($iWidth, $iHeight, 1, 32) $hImage = _GDIPlus_BitmapCreateFromHBITMAP($hBitmap) $hGraphic = _GDIPlus_ImageGetGraphicsContext($hImage) $hBrushLin = _GDIPlus_CreateLineBrushFromRect(0, 0, $iWidth, $iHeight, $aFactors, $aPositions, $iC1, $iC2, $iDirection) GDIPlus_SetLineGammaCorrection($hBrushLin, $bGammaCorrection) _GDIPlus_GraphicsFillRect($hGraphic, 0+$pressed, 0+$pressed, $iWidth-$pressed*2, $iHeight-$pressed*2, $hBrushLin) $hBrush = _GDIPlus_BrushCreateSolid ($fcolour) $hFormat = _GDIPlus_StringFormatCreate () $hFamily = _GDIPlus_FontFamilyCreate ($fname) $hFont = _GDIPlus_FontCreate ($hFamily, $fsize, $fstyle) $tLayout = _GDIPlus_RectFCreate ($posedw, $posedh, $iWidth, $iHeight) $aInfo = _GDIPlus_GraphicsMeasureString ($hGraphic, $string, $hFont, $tLayout, $hFormat) if not $string="" then _GDIPlus_GraphicsDrawStringEx ($hGraphic, $string, $hFont, $aInfo[0], $hFormat, $hBrush) $hbmp = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage) $aBmp = DllCall("user32.dll", "hwnd", "SendMessage", "hwnd", $hWnd, "int", $STM_SETIMAGE, "int", $IMAGE_BITMAP, "int", $hbmp) If $aBmp[0] <> 0 Then _WinAPI_DeleteObject($aBmp[0]) _GDIPlus_ImageDispose($hImage) _GDIPlus_BrushDispose($hBrushLin) _GDIPlus_FontDispose ($hFont) _GDIPlus_FontFamilyDispose ($hFamily) _GDIPlus_StringFormatDispose ($hFormat) _GDIPlus_BrushDispose ($hBrush) _GDIPlus_GraphicsDispose($hGraphic) ; _WinAPI_DeleteObject($hbmp) _GDIPlus_Shutdown() _WinAPI_DeleteObject($hBitmap) return SetError(0, 0, 1) endfunc; SetIcon ;==== GDIPlus_CreateLineBrushFromRect === Malkey's function ;Description - Creates a LinearGradientBrush object from a set of boundary points and boundary colors. ; $aFactors - If non-array, default array will be used. ; Pointer to an array of real numbers that specify blend factors. Each number in the array ; specifies a percentage of the ending color and should be in the range from 0.0 through 1.0. ;$aPositions - If non-array, default array will be used. ; Pointer to an array of real numbers that specify blend factors' positions. Each number in the array ; indicates a percentage of the distance between the starting boundary and the ending boundary ; and is in the range from 0.0 through 1.0, where 0.0 indicates the starting boundary of the ; gradient and 1.0 indicates the ending boundary. There must be at least two positions ; specified: the first position, which is always 0.0, and the last position, which is always ; 1.0. Otherwise, the behavior is undefined. A blend position between 0.0 and 1.0 indicates a ; line, parallel to the boundary lines, that is a certain fraction of the distance from the ; starting boundary to the ending boundary. For example, a blend position of 0.7 indicates ; the line that is 70 percent of the distance from the starting boundary to the ending boundary. ; The color is constant on lines that are parallel to the boundary lines. ; $iArgb1 - First Top color in 0xAARRGGBB format ; $iArgb2 - Second color in 0xAARRGGBB format ; $LinearGradientMode - LinearGradientModeHorizontal = 0x00000000, ; LinearGradientModeVertical = 0x00000001, ; LinearGradientModeForwardDiagonal = 0x00000002, ; LinearGradientModeBackwardDiagonal = 0x00000003 ; $WrapMode - WrapModeTile = 0, ; WrapModeTileFlipX = 1, ; WrapModeTileFlipY = 2, ; WrapModeTileFlipXY = 3, ; WrapModeClamp = 4 ; GdipCreateLineBrushFromRect(GDIPCONST GpRectF* rect, ARGB color1, ARGB color2, ; LinearGradientMode mode, GpWrapMode wrapMode, GpLineGradient **lineGradient) ; Reference: http://msdn.microsoft.com/en-us/library/ms534043(VS.85).aspx ; Func _GDIPlus_CreateLineBrushFromRect($iX, $iY, $iWidth, $iHeight, $aFactors, $aPositions, _ $iArgb1 = 0xFF0000FF, $iArgb2 = 0xFFFF0000, $LinearGradientMode = 0x00000001, $WrapMode = 0) Local $tRect, $pRect, $aRet, $tFactors, $pFactors, $tPositions, $pPositions, $iCount If $iArgb1 = Default Then $iArgb1 = 0xFF0000FF If $iArgb2 = Default Then $iArgb2 = 0xFFFF0000 If $LinearGradientMode = -1 Or $LinearGradientMode = Default Then $LinearGradientMode = 0x00000001 If $WrapMode = -1 Or $LinearGradientMode = Default Then $WrapMode = 1 $tRect = DllStructCreate("float X;float Y;float Width;float Height") $pRect = DllStructGetPtr($tRect) DllStructSetData($tRect, "X", $iX) DllStructSetData($tRect, "Y", $iY) DllStructSetData($tRect, "Width", $iWidth) DllStructSetData($tRect, "Height", $iHeight) ;Note: Withn _GDIPlus_Startup(), $ghGDIPDll is defined $aRet = DllCall($ghGDIPDll, "int", "GdipCreateLineBrushFromRect", "ptr", $pRect, "int", $iArgb1, _ "int", $iArgb2, "int", $LinearGradientMode, "int", $WrapMode, "int*", 0) If IsArray($aFactors) = 0 Then Dim $aFactors[4] = [0.0, 0.4, 0.6, 1.0] If IsArray($aPositions) = 0 Then Dim $aPositions[4] = [0.0, 0.3, 0.7, 1.0] $iCount = UBound($aPositions) $tFactors = DllStructCreate("float[" & $iCount & "]") $pFactors = DllStructGetPtr($tFactors) For $iI = 0 To $iCount - 1 DllStructSetData($tFactors, 1, $aFactors[$iI], $iI + 1) Next $tPositions = DllStructCreate("float[" & $iCount & "]") $pPositions = DllStructGetPtr($tPositions) For $iI = 0 To $iCount - 1 DllStructSetData($tPositions, 1, $aPositions[$iI], $iI + 1) Next $hStatus = DllCall($ghGDIPDll, "int", "GdipSetLineBlend", "hwnd", $aRet[6], _ "ptr", $pFactors, "ptr", $pPositions, "int", $iCount) Return $aRet[6] ; Handle of Line Brush EndFunc ;==>_GDIPlus_CreateLineBrushFromRect ;=========================================================== ; Description: Specifies whether gamma correction is enabled for this linear gradient brush. ; Parameters ; $hBrush - [in] Pointer to the LinearGradientBrush object. ; $useGammaCorrection - [in] Boolean value that specifies whether gamma correction occurs ; during rendering. TRUE specifies that gamma correction is enabled, ; and FALSE specifies that gamma correction is not enabled. By default, ; gamma correction is disabled during construction of a ; LinearGradientBrush object. ;GdipSetLineGammaCorrection(GpLineGradient *brush, BOOL useGammaCorrection) ; Func GDIPlus_SetLineGammaCorrection($hBrush, $useGammaCorrection = True) Local $aResult $aResult = DllCall($ghGDIPDll, "int", "GdipSetLineGammaCorrection", "hwnd", $hBrush, "int", $useGammaCorrection) Return $aResult[0] EndFunc ;==>GDIPlus_SetLineGammaCorrection Func picactions() EndFunc func hovered() $hov=GUIGetCursorInfo($outlook) if $hov[4]=$pic and $onoff=0 Then $onoff=1 SetIcon($pic ,64, 25, "0x331111", "0x662200", 1,1, "Finish",1) Elseif $hov[4]<>$pic and $onoff=1 then $onoff=0 SetIcon($pic ,64, 25, "0xAA8866", "0x441100", 1,1, "Finish") ConsoleWrite($onoff) EndIf EndFunc func no_tab() _WinAPI_SetWindowLong(GUICtrlGetHandle(-1), $GWL_STYLE, _ BitAND(_WinAPI_GetWindowLong(GUICtrlGetHandle(-1), $GWL_STYLE), BitNOT($WS_TABSTOP))) EndFunc
GEOSoft Posted January 29, 2010 Posted January 29, 2010 I'm not sure if it will help or not but have you looked at _GUICtrlButton_SetImage() to set the image on the button? Ignore the help file description of the function. There are several wrong descriptions that have to be reported when I get time to make a list. George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!"
Homes32 Posted February 3, 2010 Author Posted February 3, 2010 I'm not sure if it will help or not but have you looked at_GUICtrlButton_SetImage()to set the image on the button?Ignore the help file description of the function. There are several wrong descriptions that have to be reported when I get time to make a list._GUICtrlButton_SetImage() can't help me unless it can set the button background transparent like in the picture in the 1st post.
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