bobbintb Posted October 14, 2009 Share Posted October 14, 2009 i saw a thread about this but i cant seem to locate it. i have a button that i want to put an icon on as well as text. i know how to do each individually but from what i remember its rather different to do both. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted October 14, 2009 Moderators Share Posted October 14, 2009 bobbintb, This is Valuater's function for icon & text on a button: #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> $mywin = GUICreate("Images amd Text on Buttons", 210, 240) $btn1 = IconButton("Test 1 - Test 1", 30, 30, 150, 64, 16, "M:\Program\Au3 Scripts\BMP\Icons\BMP_Main.ico") $btn2 = IconButton("Test 2 - Test 2", 30, 110, 150, 64, 32, "M:\Program\Au3 Scripts\BMP\Icons\BMP_Main.ico") GUISetState() While 1 $msg = GUIGetMsg() If $msg = $GUI_EVENT_CLOSE Then Exit WEnd GUIDelete() Exit ; Valuater's UDF Func IconButton($BItext, $BIleft, $BItop, $BIwidth, $BIheight, $BIconSize, $BIDLL, $BIconNum = -1) GUICtrlCreateIcon($BIDLL, $BIconNum, $BIleft + 5, $BItop + (($BIheight - $BIconSize) / 2), $BIconSize, $BIconSize) GUICtrlSetState( -1, $GUI_DISABLE) $XS_btnx = GUICtrlCreateButton($BItext, $BIleft, $BItop, $BIwidth, $BIheight, $WS_CLIPSIBLINGS) Return $XS_btnx EndFunc I hope this is what you are looking for. M23 dzlee 1 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...
picea892 Posted October 14, 2009 Share Posted October 14, 2009 How about this expandcollapse popup#include <GDIPlus.au3> #include <Array.au3> #include <WindowsConstants.au3> #include <GuiConstantsEx.au3> #include <ButtonConstants.au3> #include <Winapi.au3> #include<Misc.au3> #include <Process.au3> #include <StaticConstants.au3> #include <GuiConstants.au3> #include <Constants.au3> #include <GuiMenu.au3> Global $aFactors[4] = [0.0, 0.6, 0.8, 1.0], $aPositions[4] = [0.0, 0.6, 0.8, 1.0] Global $bGammaCorrection = False Opt("GUIOnEventMode", 1) ; Change to OnEvent mode Global $gw=400,$gh=400 $taskbar=GUICreate("example", $gw, $gh,-1,-1,$WS_POPUP, $WS_EX_TOOLWINDOW);,$WS_EX_LAYERED) $a=GUICtrlCreatePic("",0,0) SetIcon($a,"", 0, 400, 400, $aFactors, $aPositions, "0x33CC66", "0x663399", 3,2,"Spruce up your Backgrounds",20,0) $iPid = Run("notepad.exe") Sleep(500); allow notepad to create window Global $a = _ProcessGetIcon("notepad.exe") GUISetIcon($a) $down =10 Global $b=GUICtrlCreatePic("",10,10) SetIcon($b,$a, 0, 80, 40, $aFactors, $aPositions, "0x444444", "0x999999", 2,2) Global $c=GUICtrlCreatePic("",10,60) SetIcon($c,$a, 0, 80, 40, $aFactors, $aPositions, "0xFFFF33", "0x3333FF", 1,2,"Under",12,0) Global $d=GUICtrlCreatePic("",10,110) SetIcon($d,$a, 0, 80, 40, $aFactors, $aPositions, "0x33FF99", "0xFF0033", 0,2,"Over",14,1) GUISetState() While 1 $hover=GUIGetCursorInfo(WinGetHandle("example","")) if _IsPressed("01","user32.dll") and $hover[4]=$b then SetIcon($b,$a, 0, 80, 40, $aFactors, $aPositions, "0x444444", "0x999999", 1,0) _WinAPI_RedrawWindow(GUICtrlGetHandle($b)) sleep(400) SetIcon($b,$a, 0, 80, 40, $aFactors, $aPositions, "0x444444", "0x999999", 2,2) _WinAPI_RedrawWindow(GUICtrlGetHandle($b)) Elseif _IsPressed("01","user32.dll") and $hover[4]=$c then SetIcon($c,$a, 0, 80, 40, $aFactors, $aPositions, "0x3333FF", "0xFFFF33", 1,0,"Under",12,0) _WinAPI_RedrawWindow(GUICtrlGetHandle($c)) sleep(400) SetIcon($c,$a, 0, 80, 40, $aFactors, $aPositions, "0xFFFF33", "0x3333FF", 1,2,"Under",12,0) _WinAPI_RedrawWindow(GUICtrlGetHandle($c)) Elseif _IsPressed("01","user32.dll") and $hover[4]=$d then SetIcon($d,$a, 0, 80, 40, $aFactors, $aPositions, "0xFF0033", "0x33FF99", 0,0,"Over",14,1) _WinAPI_RedrawWindow(GUICtrlGetHandle($d)) sleep(400) SetIcon($d,$a, 0, 80, 40, $aFactors, $aPositions, "0x33FF99", "0xFF0033", 0,2,"Over",14,1) _WinAPI_RedrawWindow(GUICtrlGetHandle($d)) EndIf sleep(100) WEnd Func FillArray($sData) Local $aDataSplit $aDataSplit = StringSplit(StringStripWS($sData, 8), ",") If $aDataSplit[0] < 2 Then MsgBox(0, "Error", "Must have at lease two (2) entries in input box", 2) Return 1 Else Local $aRetArray[$aDataSplit[0]] For $x = 0 To UBound($aRetArray) - 1 $aRetArray[$x] = $aDataSplit[$x + 1] Next Return $aRetArray EndIf EndFunc ;==>FillArray Func SetColor($iD) Local $Clr $Clr = _ChooseColor(2, 0, 2, $hGui) If $Clr <> -1 Then $iColor[$iD] = $Clr If $iD Then GUICtrlSetColor($Label[$iD], $iColor[0]) GUICtrlSetColor($Label[0], $iColor[1]) Else GUICtrlSetColor($Label[$iD], $iColor[1]) GUICtrlSetColor($Label[1], $iColor[0]) EndIf GUICtrlSetData($Label[$iD], $iColor[$iD]) GUICtrlSetBkColor($Label[$iD], $iColor[$iD]) Return 1 EndIf Return 0 EndFunc ;==>SetColor Func PicSetGradient($cID, $iW, $iH, $aFactors, $aPositions, $iClr1, $iClr2, $iDirection) Local Const $STM_SETIMAGE = 0x0172 Local Const $IMAGE_BITMAP = 0 Local $hWnd, $iC1, $iC2, $hBitmap, $hImage, $hGraphic, $hBrushLin, $hbmp, $aBmp $hWnd = GUICtrlGetHandle($cID) $iC1 = StringReplace($iClr1, "0x", "0xFF") $iC2 = StringReplace($iClr2, "0x", "0xFF") $hBitmap = _WinAPI_CreateBitmap($iW, $iH, 1, 32) _GDIPlus_Startup() $hImage = _GDIPlus_BitmapCreateFromHBITMAP($hBitmap) $hGraphic = _GDIPlus_ImageGetGraphicsContext($hImage) $hBrushLin = _GDIPlus_CreateLineBrushFromRect(0, 0, $iW, $iH, $aFactors, $aPositions, $iC1, $iC2, $iDirection) GDIPlus_SetLineGammaCorrection($hBrushLin, $bGammaCorrection) _GDIPlus_GraphicsFillRect($hGraphic, 0, 0, $iW, $iH, $hBrushLin) $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_GraphicsDispose($hGraphic) _WinAPI_DeleteObject($hbmp) _WinAPI_DeleteObject($hBitmap) _GDIPlus_Shutdown() EndFunc ;==>PicSetGradient func SetIcon($controlID, $sIcon, $iIndex, $iWidth, $iHeight, $aFactors, $aPositions, $iClr1="0x111111", $iClr2="0x999999", $iDirection=2, $pressed=2,$string="", $fontsize="12", $over="1") const $STM_SETIMAGE = 0x0172 local $tIcon, $tID, $hDC, $hBackDC, $hBackSv, $hBitmap, $hImage, $hIcon, $hBkIcon Local $w=$iWidth-32, $h=$iHeight-32 $tIcon = DllStructCreate('hwnd') $tID = DllStructCreate('hwnd') _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+$pressed, $iHeight+$pressed, 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, 0, $iWidth, $iHeight, $hBrushLin) if $over=0 and not $string="" then _GDIPlus_GraphicsDrawString($hGraphic,$string,2, $h/2,"arial",$fontsize) EndIf $hbmp = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage) if not $sIcon="" Then $hIcon = DllCall('user32.dll', 'int', 'PrivateExtractIcons', 'str', $sIcon, 'int', $iIndex, 'int', 32, 'int', 32, 'ptr', DllStructGetPtr($tIcon), 'ptr', DllStructGetPtr($tID), 'int', 1, 'int', 0) if (@error) or ($hIcon[0] = 0) then return SetError(1, 0, 0) endif $hIcon = DllStructGetData($tIcon, 1) $tIcon = 0 $tID = 0 $hDC = _WinAPI_GetDC(0) $hBackDC = _WinAPI_CreateCompatibleDC($hDC) ;$hBitmap = _WinAPI_CreateSolidBitmap(0, $iBackground, $iWidth, $iHeight) $hBackSv = _WinAPI_SelectObject($hBackDC, $hbmp) If $hIcon <> 0 Then _WinAPI_DrawIconEx($hBackDC, $w/2, $h/2, $hIcon, 0, 0, 0, 0, $DI_NORMAL) EndIf if $over=1 and not $string="" then $hImage = _GDIPlus_BitmapCreateFromHBITMAP($hbmp) Local $hGraphic = _GDIPlus_ImageGetGraphicsContext($hImage) _GDIPlus_GraphicsDrawString($hGraphic,$string,2, $h/2,"arial",$fontsize) $hbmp = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage) _GDIPlus_GraphicsDispose ($hGraphic) EndIf $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_GraphicsDispose($hGraphic) ; _WinAPI_DeleteObject($hbmp) _GDIPlus_Shutdown() _WinAPI_DeleteObject($hBitmap) _WinAPI_DeleteObject($hIcon) if $sIcon="" Then Return SetError(0, 0, 1) _WinAPI_SelectObject($hBackDC, $hBackSv) _WinAPI_DeleteDC($hBackDC) _WinAPI_ReleaseDC(0, $hDC) return SetError(0, 0, 1) endfunc; SetIcon Func _Quit() Exit EndFunc ;==>_Quit ;==== 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 _ProcessGetIcon($vProcess) Local $iPID = ProcessExists($vProcess) If Not $iPID Then Return SetError(1, 0, -1) Local $aProc = DllCall('kernel32.dll', 'hwnd', 'OpenProcess', 'int', BitOR(0x0400, 0x0010), 'int', 0, 'int', $iPID) If Not IsArray($aProc) Or Not $aProc[0] Then Return SetError(2, 0, -1) Local $vStruct = DllStructCreate('int[1024]') Local $hPsapi_Dll = DllOpen('Psapi.dll') If $hPsapi_Dll = -1 Then $hPsapi_Dll = DllOpen(@SystemDir & '\Psapi.dll') If $hPsapi_Dll = -1 Then $hPsapi_Dll = DllOpen(@WindowsDir & '\Psapi.dll') If $hPsapi_Dll = -1 Then Return SetError(3, 0, '') DllCall($hPsapi_Dll, 'int', 'EnumProcessModules', _ 'hwnd', $aProc[0], _ 'ptr', DllStructGetPtr($vStruct), _ 'int', DllStructGetSize($vStruct), _ 'int_ptr', 0) Local $aRet = DllCall($hPsapi_Dll, 'int', 'GetModuleFileNameEx', _ 'hwnd', $aProc[0], _ 'int', DllStructGetData($vStruct, 1), _ 'str', '', _ 'int', 2048) DllClose($hPsapi_Dll) If Not IsArray($aRet) Or StringLen($aRet[3]) = 0 Then Return SetError(4, 0, '') Return $aRet[3] EndFunc Func processgetstate($process) For $i = 1 To $winlistall[0][0] If $process = $winlistall[$i][0] and WinActive($winlistall[$i][2]) Then return 1 Next Return 0 EndFunc Link to comment Share on other sites More sharing options...
ProgAndy Posted October 14, 2009 Share Posted October 14, 2009 What about the original functions for that? http://www.autoitscript.com/forum/index.php?showtopic=79428&st=0&p=572734&#entry572734 (needs XP or above) *GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes 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