AlmarM Posted April 26, 2010 Share Posted April 26, 2010 Hi, How comes my button changes when I set the text color? See the difference: $GUI = GUICreate("", 100, 100) $Button = GUICtrlCreateButton("Test", 25, 20, 50, 25) $Button2 = GUICtrlCreateButton("Test", 25, 50, 50, 25) GUICtrlSetColor($Button, 0xFF00FF) GUISetState() While 1 Switch GUIGetMsg() Case -3 Exit EndSwitch WEnd Minesweeper A minesweeper game created in autoit, source available. _Mouse_UDF An UDF for registering functions to mouse events, made in pure autoit. 2D Hitbox Editor A 2D hitbox editor for quick creation of 2D sphere and rectangle hitboxes. Link to comment Share on other sites More sharing options...
PsaltyDS Posted April 26, 2010 Share Posted April 26, 2010 The button text color changes, because you changed the button text color. What did you expect? How does your button change? Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
AlmarM Posted April 26, 2010 Author Share Posted April 26, 2010 Well, see for yourself. Provided with a screenshot: Minesweeper A minesweeper game created in autoit, source available. _Mouse_UDF An UDF for registering functions to mouse events, made in pure autoit. 2D Hitbox Editor A 2D hitbox editor for quick creation of 2D sphere and rectangle hitboxes. Link to comment Share on other sites More sharing options...
PsaltyDS Posted April 26, 2010 Share Posted April 26, 2010 And if you comment out the GUICtrlSetColor() it looks exactly the same, but with black text. So what did you expect? What am I missing? Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
AlmarM Posted April 26, 2010 Author Share Posted April 26, 2010 (edited) And if you comment out the GUICtrlSetColor() it looks exactly the same, but with black text. So what did you expect? What am I missing?It makes the button look flat (2D).Can you see the difference now? Edited April 26, 2010 by AlmarM Minesweeper A minesweeper game created in autoit, source available. _Mouse_UDF An UDF for registering functions to mouse events, made in pure autoit. 2D Hitbox Editor A 2D hitbox editor for quick creation of 2D sphere and rectangle hitboxes. Link to comment Share on other sites More sharing options...
PsaltyDS Posted April 26, 2010 Share Posted April 26, 2010 (edited) Yeah, I see that now, but I don't know if/how you can fix it. I seem to recall that once you change something about the button, the style becomes BS_OWNERDRAW and none of the default Windows styles, like the 3D background image are applied any more. You could create a 3D gradient and apply it yourself with GuiCtrlSetImage(), I guess. There are smarter people here who might know a better way. (Edit: Like Yashied; see below!) Edited April 28, 2010 by PsaltyDS Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
funkey Posted April 26, 2010 Share Posted April 26, 2010 (edited) You could use transparent labels for the text. Edit: Sorry, then there is no hover effect for the button. Edited April 26, 2010 by funkey Programming today is a race between software engineers striving tobuild bigger and better idiot-proof programs, and the Universetrying to produce bigger and better idiots.So far, the Universe is winning. Link to comment Share on other sites More sharing options...
AlmarM Posted April 26, 2010 Author Share Posted April 26, 2010 (edited) Isnt their any wat to get those default buttons styles? http://www.google.nl/#hl=nl&q=windows+vista+default+button+styles&meta=&aq=f&aqi=&aql=&oq=&gs_rfai=&fp=69c3d546787043f8 EDIT: Default Style (I guess): 0x50010000 (Makes it 3D after GUICtrlSetColor() again, loses color though) Flat Button Style: 0x5001000B Anyway to combine Default style with color? Edited April 26, 2010 by AlmarM Minesweeper A minesweeper game created in autoit, source available. _Mouse_UDF An UDF for registering functions to mouse events, made in pure autoit. 2D Hitbox Editor A 2D hitbox editor for quick creation of 2D sphere and rectangle hitboxes. Link to comment Share on other sites More sharing options...
Andreik Posted April 26, 2010 Share Posted April 26, 2010 Maybe you can use _WinAPI_DrawEdge() to draw normally look of the button. Link to comment Share on other sites More sharing options...
Yashied Posted April 26, 2010 Share Posted April 26, 2010 One way. expandcollapse popup#Include <Constants.au3> #Include <GUIConstantsEx.au3> #Include <StaticConstants.au3> #Include <WindowsConstants.au3> #Include <WinAPI.au3> Dim $Button[4] $hForm = GUICreate('MyGUI', 350, 63) $Button[0] = GUICtrlCreateButton('', 20, 20, 70, 23) GUICtrlCreateLabel('Button1', 20, 20, 70, 23, BitOR($SS_CENTER, $SS_CENTERIMAGE)) GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT) GUICtrlSetFont(-1, 11, -1, -1, 'Times') GUICtrlSetColor(-1, 0xFF00FF) $Button[1] = GUICtrlCreateButton('', 100, 20, 70, 23) GUICtrlCreateLabel('Button2', 100, 20, 70, 23, BitOR($SS_CENTER, $SS_CENTERIMAGE)) GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT) GUICtrlSetFont(-1, 11, -1, -1, 'Comic Sans MS') GUICtrlSetColor(-1, 0xFF0000) $Button[2] = GUICtrlCreateButton('', 180, 20, 70, 23) GUICtrlCreateLabel('Button1', 180, 20, 70, 23, BitOR($SS_CENTER, $SS_CENTERIMAGE)) GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT) GUICtrlSetFont(-1, 10, -1, 2) GUICtrlSetColor(-1, 0x00FF00) $Button[3] = GUICtrlCreateButton('', 260, 20, 70, 23) GUICtrlCreateLabel('Button1', 260, 20, 70, 23, BitOR($SS_CENTER, $SS_CENTERIMAGE)) GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT) GUICtrlSetFont(-1, -1, -1, 4) GUICtrlSetColor(-1, 0x0000FF) $hDll = DllCallbackRegister('_WinProc', 'ptr', 'hwnd;uint;wparam;lparam') $pDll = DllCallbackGetPtr($hDll) For $i = 0 To UBound($Button) - 1 $hProc = _WinAPI_SetWindowLong(GUICtrlGetHandle($Button[$i]), $GWL_WNDPROC, $pDll) Next GUISetState() While 1 $Msg = GUIGetMsg() Switch $Msg Case -3 ExitLoop Case $Button[0], $Button[1], $Button[2], $Button[3] MsgBox(0, 'Message', 'Button is pressed.', 0, $hForm) EndSwitch WEnd For $i = 0 To UBound($Button) - 1 _WinAPI_SetWindowLong(GUICtrlGetHandle($Button[$i]), $GWL_WNDPROC, $hProc) Next DllCallbackFree($hDll) Func _WinProc($hWnd, $iMsg, $wParam, $lParam) Switch $iMsg Case $WM_PAINT Local $tRECT = DllStructCreate($tagRECT) Local $Ret = DllCall('user32.dll', 'int', 'GetUpdateRect', 'hwnd', $hWnd, 'ptr', DllStructGetPtr($tRECT), 'int', 1) If $Ret[0] Then _WinAPI_InvalidateRect(GUICtrlGetHandle(_WinAPI_GetDlgCtrlID($hWnd) + 1), $tRECT) EndIf EndSwitch Return _WinAPI_CallWindowProc($hProc, $hWnd, $iMsg, $wParam, $lParam) EndFunc ;==>_WinProc Norm73 1 My UDFs: iKey | FTP Uploader | Battery Checker | Boot Manager | Font Viewer | UDF Keyword Manager | Run Dialog Replacement | USBProtect | 3D Axis | Calculator | Sleep | iSwitcher | TM | NetHelper | File Types Manager | Control Viewer | SynFolders | DLL Helper Animated Tray Icons UDF Library | Hotkeys UDF Library | Hotkeys Input Control UDF Library | Caret Shape UDF Library | Context Help UDF Library | Most Recently Used List UDF Library | Icons UDF Library | FTP UDF Library | Script Communications UDF Library | Color Chooser UDF Library | Color Picker Control UDF Library | IPHelper (Vista/7) UDF Library | WinAPI Extended UDF Library | WinAPIVhd UDF Library | Icon Chooser UDF Library | Copy UDF Library | Restart UDF Library | Event Log UDF Library | NotifyBox UDF Library | Pop-up Windows UDF Library | TVExplorer UDF Library | GuiHotKey UDF Library | GuiSysLink UDF Library | Package UDF Library | Skin UDF Library | AITray UDF Library | RDC UDF Library Appropriate path | Button text color | Gaussian random numbers | Header's styles (Vista/7) | ICON resource enumeration | Menu & INI | Tabbed string size | Tab's skin | Pop-up circular menu | Progress Bar without animation (Vista/7) | Registry export | Registry path jumping | Unique hardware ID | Windows alignment More... Link to comment Share on other sites More sharing options...
AlmarM Posted April 27, 2010 Author Share Posted April 27, 2010 (edited) One way. expandcollapse popup#Include <Constants.au3> #Include <GUIConstantsEx.au3> #Include <StaticConstants.au3> #Include <WindowsConstants.au3> #Include <WinAPI.au3> Dim $Button[4] $hForm = GUICreate('MyGUI', 350, 63) $Button[0] = GUICtrlCreateButton('', 20, 20, 70, 23) GUICtrlCreateLabel('Button1', 20, 20, 70, 23, BitOR($SS_CENTER, $SS_CENTERIMAGE)) GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT) GUICtrlSetFont(-1, 11, -1, -1, 'Times') GUICtrlSetColor(-1, 0xFF00FF) $Button[1] = GUICtrlCreateButton('', 100, 20, 70, 23) GUICtrlCreateLabel('Button2', 100, 20, 70, 23, BitOR($SS_CENTER, $SS_CENTERIMAGE)) GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT) GUICtrlSetFont(-1, 11, -1, -1, 'Comic Sans MS') GUICtrlSetColor(-1, 0xFF0000) $Button[2] = GUICtrlCreateButton('', 180, 20, 70, 23) GUICtrlCreateLabel('Button1', 180, 20, 70, 23, BitOR($SS_CENTER, $SS_CENTERIMAGE)) GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT) GUICtrlSetFont(-1, 10, -1, 2) GUICtrlSetColor(-1, 0x00FF00) $Button[3] = GUICtrlCreateButton('', 260, 20, 70, 23) GUICtrlCreateLabel('Button1', 260, 20, 70, 23, BitOR($SS_CENTER, $SS_CENTERIMAGE)) GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT) GUICtrlSetFont(-1, -1, -1, 4) GUICtrlSetColor(-1, 0x0000FF) $hDll = DllCallbackRegister('_WinProc', 'ptr', 'hwnd;uint;wparam;lparam') $pDll = DllCallbackGetPtr($hDll) For $i = 0 To UBound($Button) - 1 $hProc = _WinAPI_SetWindowLong(GUICtrlGetHandle($Button[$i]), $GWL_WNDPROC, $pDll) Next GUISetState() While 1 $Msg = GUIGetMsg() Switch $Msg Case -3 ExitLoop Case $Button[0], $Button[1], $Button[2], $Button[3] MsgBox(0, 'Message', 'Button is pressed.', 0, $hForm) EndSwitch WEnd For $i = 0 To UBound($Button) - 1 _WinAPI_SetWindowLong(GUICtrlGetHandle($Button[$i]), $GWL_WNDPROC, $hProc) Next DllCallbackFree($hDll) Func _WinProc($hWnd, $iMsg, $wParam, $lParam) Switch $iMsg Case $WM_PAINT Local $tRECT = DllStructCreate($tagRECT) Local $Ret = DllCall('user32.dll', 'int', 'GetUpdateRect', 'hwnd', $hWnd, 'ptr', DllStructGetPtr($tRECT), 'int', 1) If $Ret[0] Then _WinAPI_InvalidateRect(GUICtrlGetHandle(_WinAPI_GetDlgCtrlID($hWnd) + 1), $tRECT) EndIf EndSwitch Return _WinAPI_CallWindowProc($hProc, $hWnd, $iMsg, $wParam, $lParam) EndFunc ;==>_WinProc Oh, thank you. Still a pain in the ass to create this for all my buttons. Edited April 27, 2010 by AlmarM Minesweeper A minesweeper game created in autoit, source available. _Mouse_UDF An UDF for registering functions to mouse events, made in pure autoit. 2D Hitbox Editor A 2D hitbox editor for quick creation of 2D sphere and rectangle hitboxes. Link to comment Share on other sites More sharing options...
Yashied Posted April 28, 2010 Share Posted April 28, 2010 (edited) Another way. expandcollapse popup#Include <GUIConstantsEx.au3> #Include <GUIButton.au3> #Include <GUIImageList.au3> #Include <WinAPI.au3> #Include <WindowsConstants.au3> GUICreate('MyGUI', 200, 200) GUICtrlCreateButton('', 65, 170, 70, 23) _GUIButtonSetTextColor(-1, 'OK', 0xFF0000) GUISetState() Do Until GUIGetMsg() = -3 Func _GUIButtonSetTextColor($iCtrlID, $sText, $iTextColor) Local $hWnd, $hTheme, $hImageList, $hBitmap, $hObj, $hDC, $hMemDC, $tRect, $pRect, $Data, $Width, $Height, $Prev = -1 $hWnd = GUICtrlGetHandle($iCtrlID) If Not $hWnd Then Return 0 EndIf $hTheme = DllCall('uxtheme.dll', 'ptr', 'OpenThemeData', 'hwnd', $hWnd, 'wstr', 'Button') If (@error) Or (Not $hTheme[0]) Then GUICtrlSetColor($iCtrlID, $iTextColor) GUICtrlSetData($iCtrlID, $sText) Return 1 EndIf $hTheme = $hTheme[0] $Width = _WinAPI_GetClientWidth($hWnd) $Height = _WinAPI_GetClientHeight($hWnd) $hImageList = _GUIImageList_Create($Width - 8, $Height - 8, 4, 4) $hBitmap = _WinAPI_CreateBitmap($Width - 8, $Height - 8, 1, 32) $tRect = DllStructCreate('int[4]') DllStructSetData($tRect, 1, -4, 1) DllStructSetData($tRect, 1, -4, 2) DllStructSetData($tRect, 1, $Width - 4, 3) DllStructSetData($tRect, 1, $Height - 4, 4) $pRect = DllStructGetPtr($tRect) $hDC = _WinAPI_GetDC(0) $hMemDC = _WinAPI_CreateCompatibleDC($hDC) _WinAPI_ReleaseDC(0, $hDC) _WinAPI_SelectObject($hMemDC, _SendMessage($hWnd, $WM_GETFONT)) _WinAPI_SetTextColor($hMemDC, BitOR(BitAND($iTextColor, 0x00FF00), BitShift(BitAND($iTextColor, 0x0000FF), -16), BitShift(BitAND($iTextColor, 0xFF0000), 16))) _WinAPI_SetBkMode($hMemDC, $TRANSPARENT) ; PBS_NORMAL $hObj = _WinAPI_SelectObject($hMemDC, $hBitmap) DllCall('uxtheme.dll', 'int', 'DrawThemeBackground', 'ptr', $hTheme, 'hwnd', $hMemDC, 'int', 1, 'int', 1, 'ptr', $pRect, 'ptr', 0) _WinAPI_DrawText($hMemDC, $sText, $tRect, BitOR($DT_CENTER, $DT_SINGLELINE, $DT_VCENTER)) _WinAPI_SelectObject($hMemDC, $hObj) _GUIImageList_Add($hImageList, $hBitmap) ; PBS_HOT $hObj = _WinAPI_SelectObject($hMemDC, $hBitmap) DllCall('uxtheme.dll', 'int', 'DrawThemeBackground', 'ptr', $hTheme, 'hwnd', $hMemDC, 'int', 1, 'int', 2, 'ptr', $pRect, 'ptr', 0) _WinAPI_DrawText($hMemDC, $sText, $tRect, BitOR($DT_CENTER, $DT_SINGLELINE, $DT_VCENTER)) _WinAPI_SelectObject($hMemDC, $hObj) _GUIImageList_Add($hImageList, $hBitmap) ; PBS_PRESSED $hObj = _WinAPI_SelectObject($hMemDC, $hBitmap) DllCall('uxtheme.dll', 'int', 'DrawThemeBackground', 'ptr', $hTheme, 'hwnd', $hMemDC, 'int', 1, 'int', 3, 'ptr', $pRect, 'ptr', 0) _WinAPI_DrawText($hMemDC, $sText, $tRect, BitOR($DT_CENTER, $DT_SINGLELINE, $DT_VCENTER)) _WinAPI_SelectObject($hMemDC, $hObj) _GUIImageList_Add($hImageList, $hBitmap) ; PBS_DISABLED $hObj = _WinAPI_SelectObject($hMemDC, $hBitmap) DllCall('uxtheme.dll', 'int', 'DrawThemeBackground', 'ptr', $hTheme, 'hwnd', $hMemDC, 'int', 1, 'int', 4, 'ptr', $pRect, 'ptr', 0) $Data = DllCall('uxtheme.dll', 'int', 'GetThemeColor', 'ptr', $hTheme, 'int', 1, 'int', 4, 'int', 3803, 'dword*', 0) If (Not @error) And (Not $Data[0]) Then $Prev = _WinAPI_SetTextColor($hMemDC, $Data[5]) EndIf _WinAPI_DrawText($hMemDC, $sText, $tRect, BitOR($DT_CENTER, $DT_SINGLELINE, $DT_VCENTER)) If $Prev > -1 Then _WinAPI_SetTextColor($hMemDC, $Prev) EndIf _WinAPI_SelectObject($hMemDC, $hObj) _GUIImageList_Add($hImageList, $hBitmap) ; PBS_DEFAULTED $hObj = _WinAPI_SelectObject($hMemDC, $hBitmap) DllCall('uxtheme.dll', 'int', 'DrawThemeBackground', 'ptr', $hTheme, 'hwnd', $hMemDC, 'int', 1, 'int', 5, 'ptr', $pRect, 'ptr', 0) _WinAPI_DrawText($hMemDC, $sText, $tRect, BitOR($DT_CENTER, $DT_SINGLELINE, $DT_VCENTER)) _WinAPI_SelectObject($hMemDC, $hObj) _GUIImageList_Add($hImageList, $hBitmap) _WinAPI_DeleteDC($hMemDC) _WinAPI_DeleteObject($hBitmap) DllCall('uxtheme.dll', 'int', 'CloseThemeData', 'ptr', $hTheme) $Data = _GUICtrlButton_GetImageList($hWnd) If $Data[0] Then _GUIImageList_Destroy($Data[0]) EndIf GUICtrlSetData($iCtrlID, '') If Not _GUICtrlButton_SetImageList($hWnd, $hImageList, 4) Then _GUIImageList_Destroy($hImageList) Return 0 EndIf Return 1 EndFunc ;==>_GUIButtonSetTextColor Edited April 28, 2010 by Yashied MrVietA2 1 My UDFs: iKey | FTP Uploader | Battery Checker | Boot Manager | Font Viewer | UDF Keyword Manager | Run Dialog Replacement | USBProtect | 3D Axis | Calculator | Sleep | iSwitcher | TM | NetHelper | File Types Manager | Control Viewer | SynFolders | DLL Helper Animated Tray Icons UDF Library | Hotkeys UDF Library | Hotkeys Input Control UDF Library | Caret Shape UDF Library | Context Help UDF Library | Most Recently Used List UDF Library | Icons UDF Library | FTP UDF Library | Script Communications UDF Library | Color Chooser UDF Library | Color Picker Control UDF Library | IPHelper (Vista/7) UDF Library | WinAPI Extended UDF Library | WinAPIVhd UDF Library | Icon Chooser UDF Library | Copy UDF Library | Restart UDF Library | Event Log UDF Library | NotifyBox UDF Library | Pop-up Windows UDF Library | TVExplorer UDF Library | GuiHotKey UDF Library | GuiSysLink UDF Library | Package UDF Library | Skin UDF Library | AITray UDF Library | RDC UDF Library Appropriate path | Button text color | Gaussian random numbers | Header's styles (Vista/7) | ICON resource enumeration | Menu & INI | Tabbed string size | Tab's skin | Pop-up circular menu | Progress Bar without animation (Vista/7) | Registry export | Registry path jumping | Unique hardware ID | Windows alignment More... Link to comment Share on other sites More sharing options...
Fantastic Posted April 28, 2010 Share Posted April 28, 2010 Another way.Very nice example. [u]My current project:[/u] [size="1"]A bootable USB[/size]Webpage:*http://mylittlesoft.blogspot.com/ Link to comment Share on other sites More sharing options...
AlmarM Posted April 28, 2010 Author Share Posted April 28, 2010 Another way. expandcollapse popup#Include <GUIConstantsEx.au3> #Include <GUIButton.au3> #Include <GUIImageList.au3> #Include <WinAPI.au3> #Include <WindowsConstants.au3> GUICreate('MyGUI', 200, 200) GUICtrlCreateButton('', 65, 170, 70, 23) _GUIButtonSetTextColor(-1, 'OK', 0xFF0000) GUISetState() Do Until GUIGetMsg() = -3 Func _GUIButtonSetTextColor($iCtrlID, $sText, $iTextColor) Local $hWnd, $hTheme, $hImageList, $hBitmap, $hObj, $hDC, $hMemDC, $tRect, $pRect, $Data, $Width, $Height, $Prev = -1 $hWnd = GUICtrlGetHandle($iCtrlID) If Not $hWnd Then Return 0 EndIf $hTheme = DllCall('uxtheme.dll', 'ptr', 'OpenThemeData', 'hwnd', $hWnd, 'wstr', 'Button') If (@error) Or (Not $hTheme[0]) Then GUICtrlSetColor($iCtrlID, $iTextColor) GUICtrlSetData($iCtrlID, $sText) Return 1 EndIf $hTheme = $hTheme[0] $Width = _WinAPI_GetClientWidth($hWnd) $Height = _WinAPI_GetClientHeight($hWnd) $hImageList = _GUIImageList_Create($Width - 8, $Height - 8, 4, 4) $hBitmap = _WinAPI_CreateBitmap($Width - 8, $Height - 8, 1, 32) $tRect = DllStructCreate('int[4]') DllStructSetData($tRect, 1, -4, 1) DllStructSetData($tRect, 1, -4, 2) DllStructSetData($tRect, 1, $Width - 4, 3) DllStructSetData($tRect, 1, $Height - 4, 4) $pRect = DllStructGetPtr($tRect) $hDC = _WinAPI_GetDC(0) $hMemDC = _WinAPI_CreateCompatibleDC($hDC) _WinAPI_ReleaseDC(0, $hDC) _WinAPI_SelectObject($hMemDC, _SendMessage($hWnd, $WM_GETFONT)) _WinAPI_SetTextColor($hMemDC, BitOR(BitAND($iTextColor, 0x00FF00), BitShift(BitAND($iTextColor, 0x0000FF), -16), BitShift(BitAND($iTextColor, 0xFF0000), 16))) _WinAPI_SetBkMode($hMemDC, $TRANSPARENT) ; PBS_NORMAL $hObj = _WinAPI_SelectObject($hMemDC, $hBitmap) DllCall('uxtheme.dll', 'int', 'DrawThemeBackground', 'ptr', $hTheme, 'hwnd', $hMemDC, 'int', 1, 'int', 1, 'ptr', $pRect, 'ptr', 0) _WinAPI_DrawText($hMemDC, $sText, $tRect, BitOR($DT_CENTER, $DT_SINGLELINE, $DT_VCENTER)) _WinAPI_SelectObject($hMemDC, $hObj) _GUIImageList_Add($hImageList, $hBitmap) ; PBS_HOT $hObj = _WinAPI_SelectObject($hMemDC, $hBitmap) DllCall('uxtheme.dll', 'int', 'DrawThemeBackground', 'ptr', $hTheme, 'hwnd', $hMemDC, 'int', 1, 'int', 2, 'ptr', $pRect, 'ptr', 0) _WinAPI_DrawText($hMemDC, $sText, $tRect, BitOR($DT_CENTER, $DT_SINGLELINE, $DT_VCENTER)) _WinAPI_SelectObject($hMemDC, $hObj) _GUIImageList_Add($hImageList, $hBitmap) ; PBS_PRESSED $hObj = _WinAPI_SelectObject($hMemDC, $hBitmap) DllCall('uxtheme.dll', 'int', 'DrawThemeBackground', 'ptr', $hTheme, 'hwnd', $hMemDC, 'int', 1, 'int', 3, 'ptr', $pRect, 'ptr', 0) _WinAPI_DrawText($hMemDC, $sText, $tRect, BitOR($DT_CENTER, $DT_SINGLELINE, $DT_VCENTER)) _WinAPI_SelectObject($hMemDC, $hObj) _GUIImageList_Add($hImageList, $hBitmap) ; PBS_DISABLED $hObj = _WinAPI_SelectObject($hMemDC, $hBitmap) DllCall('uxtheme.dll', 'int', 'DrawThemeBackground', 'ptr', $hTheme, 'hwnd', $hMemDC, 'int', 1, 'int', 4, 'ptr', $pRect, 'ptr', 0) $Data = DllCall('uxtheme.dll', 'int', 'GetThemeColor', 'ptr', $hTheme, 'int', 1, 'int', 4, 'int', 3803, 'dword*', 0) If (Not @error) And (Not $Data[0]) Then $Prev = _WinAPI_SetTextColor($hMemDC, $Data[5]) EndIf _WinAPI_DrawText($hMemDC, $sText, $tRect, BitOR($DT_CENTER, $DT_SINGLELINE, $DT_VCENTER)) If $Prev > -1 Then _WinAPI_SetTextColor($hMemDC, $Prev) EndIf _WinAPI_SelectObject($hMemDC, $hObj) _GUIImageList_Add($hImageList, $hBitmap) ; PBS_DEFAULTED $hObj = _WinAPI_SelectObject($hMemDC, $hBitmap) DllCall('uxtheme.dll', 'int', 'DrawThemeBackground', 'ptr', $hTheme, 'hwnd', $hMemDC, 'int', 1, 'int', 5, 'ptr', $pRect, 'ptr', 0) _WinAPI_DrawText($hMemDC, $sText, $tRect, BitOR($DT_CENTER, $DT_SINGLELINE, $DT_VCENTER)) _WinAPI_SelectObject($hMemDC, $hObj) _GUIImageList_Add($hImageList, $hBitmap) _WinAPI_DeleteDC($hMemDC) _WinAPI_DeleteObject($hBitmap) DllCall('uxtheme.dll', 'int', 'CloseThemeData', 'ptr', $hTheme) $Data = _GUICtrlButton_GetImageList($hWnd) If $Data[0] Then _GUIImageList_Destroy($Data[0]) EndIf GUICtrlSetData($iCtrlID, '') If Not _GUICtrlButton_SetImageList($hWnd, $hImageList, 4) Then _GUIImageList_Destroy($hImageList) Return 0 EndIf Return 1 EndFunc ;==>_GUIButtonSetTextColor Nice, only my button color will always be white Minesweeper A minesweeper game created in autoit, source available. _Mouse_UDF An UDF for registering functions to mouse events, made in pure autoit. 2D Hitbox Editor A 2D hitbox editor for quick creation of 2D sphere and rectangle hitboxes. Link to comment Share on other sites More sharing options...
Yashied Posted April 28, 2010 Share Posted April 28, 2010 (edited) Nice, only my button color will always be white Fixed. expandcollapse popup#Include <GUIButton.au3> #Include <GUIImageList.au3> #Include <WinAPI.au3> #Include <WindowsConstants.au3> GUICreate('MyGUI', 200, 200) GUICtrlCreateButton('', 65, 170, 70, 23) _GUICtrlButton_SetTextColor(-1, 'OK', 0xFF0000) GUISetState() Do Until GUIGetMsg() = -3 Func _GUICtrlButton_SetTextColor($iCtrlID, $sText, $iTextColor) Local $hWnd, $hTheme, $hImageList, $hBitmap, $hBack, $hDC, $hMemDC, $hSrcDC, $tRect, $pRect, $Width, $Height, $Prev, $Flags = BitOR($DT_CENTER, $DT_SINGLELINE, $DT_VCENTER) $hWnd = GUICtrlGetHandle($iCtrlID) If Not $hWnd Then Return 0 EndIf $hTheme = DllCall('uxtheme.dll', 'ptr', 'OpenThemeData', 'hwnd', $hWnd, 'wstr', 'BUTTON') If (@error) Or (Not $hTheme[0]) Then GUICtrlSetColor($iCtrlID, $iTextColor) GUICtrlSetData($iCtrlID, $sText) Return 1 EndIf $Width = _WinAPI_GetClientWidth($hWnd) $Height = _WinAPI_GetClientHeight($hWnd) $hImageList = _GUIImageList_Create($Width - 8, $Height - 8, 4, 4) $tRect = DllStructCreate('int[4]') DllStructSetData($tRect, 1, -4, 1) DllStructSetData($tRect, 1, -4, 2) DllStructSetData($tRect, 1, $Width - 4, 3) DllStructSetData($tRect, 1, $Height - 4, 4) $pRect = DllStructGetPtr($tRect) $hDC = _WinAPI_GetDC(0) $hMemDC = _WinAPI_CreateCompatibleDC($hDC) $hSrcDC = _WinAPI_CreateCompatibleDC($hDC) $hBitmap = _WinAPI_CreateCompatibleBitmap($hDC, $Width - 8, $Height - 8) $hBack = _WinAPI_CreateCompatibleBitmap($hDC, $Width - 8, $Height - 8) _WinAPI_ReleaseDC(0, $hDC) _WinAPI_SelectObject($hSrcDC, $hBack) _WinAPI_SelectObject($hMemDC, _SendMessage($hWnd, $WM_GETFONT)) _WinAPI_SetTextColor($hMemDC, BitOR(BitAND($iTextColor, 0x00FF00), BitShift(BitAND($iTextColor, 0x0000FF), -16), BitShift(BitAND($iTextColor, 0xFF0000), 16))) _WinAPI_SetBkMode($hMemDC, $TRANSPARENT) ; PBS_NORMAL, PBS_HOT, PBS_PRESSED, PBS_DISABLED, PBS_DEFAULTED For $i = 1 To 5 $Prev = _WinAPI_SelectObject($hMemDC, $hBitmap) DllCall('uxtheme.dll', 'int', 'DrawThemeBackground', 'ptr', $hTheme[0], 'hwnd', $hSrcDC, 'int', 1, 'int', $i, 'ptr', $pRect, 'ptr', 0) _WinAPI_BitBlt($hMemDC, 0, 0, $Width - 8, $Height - 8, $hSrcDC, 0, 0, $MERGECOPY) If $i = 4 Then DllCall('uxtheme.dll', 'int', 'DrawThemeText', 'ptr', $hTheme[0], 'hwnd', $hMemDC, 'int', 1, 'int', 4, 'wstr', $sText, 'int', -1, 'dword', $Flags, 'dword', 0, 'ptr', $pRECT) Else _WinAPI_DrawText($hMemDC, $sText, $tRect, $Flags) EndIf _WinAPI_SelectObject($hMemDC, $Prev) _GUIImageList_Add($hImageList, $hBitmap) Next ; PBS_HOT (Stylus Hot) _GUIImageList_SetImageCount($hImageList, 6) _GUIImageList_Copy($hImageList, 1, 5) _WinAPI_DeleteDC($hMemDC) _WinAPI_DeleteDC($hSrcDC) _WinAPI_DeleteObject($hBitmap) _WinAPI_DeleteObject($hBack) DllCall('uxtheme.dll', 'int', 'CloseThemeData', 'ptr', $hTheme[0]) $Prev = _GUICtrlButton_GetImageList($hWnd) If $Prev[0] Then _GUIImageList_Destroy($Prev[0]) EndIf GUICtrlSetData($iCtrlID, '') If Not _GUICtrlButton_SetImageList($hWnd, $hImageList, 4) Then _GUIImageList_Destroy($hImageList) Return 0 EndIf Return 1 EndFunc ;==>_GUICtrlButton_SetTextColor Edited April 30, 2010 by Yashied MrVietA2 1 My UDFs: iKey | FTP Uploader | Battery Checker | Boot Manager | Font Viewer | UDF Keyword Manager | Run Dialog Replacement | USBProtect | 3D Axis | Calculator | Sleep | iSwitcher | TM | NetHelper | File Types Manager | Control Viewer | SynFolders | DLL Helper Animated Tray Icons UDF Library | Hotkeys UDF Library | Hotkeys Input Control UDF Library | Caret Shape UDF Library | Context Help UDF Library | Most Recently Used List UDF Library | Icons UDF Library | FTP UDF Library | Script Communications UDF Library | Color Chooser UDF Library | Color Picker Control UDF Library | IPHelper (Vista/7) UDF Library | WinAPI Extended UDF Library | WinAPIVhd UDF Library | Icon Chooser UDF Library | Copy UDF Library | Restart UDF Library | Event Log UDF Library | NotifyBox UDF Library | Pop-up Windows UDF Library | TVExplorer UDF Library | GuiHotKey UDF Library | GuiSysLink UDF Library | Package UDF Library | Skin UDF Library | AITray UDF Library | RDC UDF Library Appropriate path | Button text color | Gaussian random numbers | Header's styles (Vista/7) | ICON resource enumeration | Menu & INI | Tabbed string size | Tab's skin | Pop-up circular menu | Progress Bar without animation (Vista/7) | Registry export | Registry path jumping | Unique hardware ID | Windows alignment More... Link to comment Share on other sites More sharing options...
PsaltyDS Posted April 28, 2010 Share Posted April 28, 2010 Wow, that's a lot of code for such a basic (seeming) function! I'm amazed there isn't a simpler API available for that. Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
AlmarM Posted April 28, 2010 Author Share Posted April 28, 2010 Fixed. expandcollapse popup#Include <GUIButton.au3> #Include <GUIImageList.au3> #Include <WinAPI.au3> #Include <WindowsConstants.au3> GUICreate('MyGUI', 200, 200) GUICtrlCreateButton('', 65, 170, 70, 23) _GUICtrlButton_SetTextColor(-1, 'OK', 0xFF0000) GUISetState() Do Until GUIGetMsg() = -3 Func _GUICtrlButton_SetTextColor($iCtrlID, $sText, $iTextColor) Local $hWnd, $hTheme, $hImageList, $hBitmap, $hBack, $hObj, $hDC, $hMemDC, $hSrcDC, $tRect, $pRect, $Data, $Width, $Height, $Prev = -1 $hWnd = GUICtrlGetHandle($iCtrlID) If Not $hWnd Then Return 0 EndIf $hTheme = DllCall('uxtheme.dll', 'ptr', 'OpenThemeData', 'hwnd', $hWnd, 'wstr', 'Button') If (@error) Or (Not $hTheme[0]) Then GUICtrlSetColor($iCtrlID, $iTextColor) GUICtrlSetData($iCtrlID, $sText) Return 1 EndIf $hTheme = $hTheme[0] $Width = _WinAPI_GetClientWidth($hWnd) $Height = _WinAPI_GetClientHeight($hWnd) $hImageList = _GUIImageList_Create($Width - 8, $Height - 8, 4, 4) $tRect = DllStructCreate('int[4]') DllStructSetData($tRect, 1, -4, 1) DllStructSetData($tRect, 1, -4, 2) DllStructSetData($tRect, 1, $Width - 4, 3) DllStructSetData($tRect, 1, $Height - 4, 4) $pRect = DllStructGetPtr($tRect) $hDC = _WinAPI_GetDC(0) $hMemDC = _WinAPI_CreateCompatibleDC($hDC) $hSrcDC = _WinAPI_CreateCompatibleDC($hDC) $hBitmap = _WinAPI_CreateCompatibleBitmap($hDC, $Width - 8, $Height - 8) $hBack = _WinAPI_CreateCompatibleBitmap($hDC, $Width - 8, $Height - 8) _WinAPI_ReleaseDC(0, $hDC) _WinAPI_SelectObject($hSrcDC, $hBack) _WinAPI_SelectObject($hMemDC, _SendMessage($hWnd, $WM_GETFONT)) _WinAPI_SetTextColor($hMemDC, BitOR(BitAND($iTextColor, 0x00FF00), BitShift(BitAND($iTextColor, 0x0000FF), -16), BitShift(BitAND($iTextColor, 0xFF0000), 16))) _WinAPI_SetBkMode($hMemDC, $TRANSPARENT) ; PBS_NORMAL DllCall('uxtheme.dll', 'int', 'DrawThemeBackground', 'ptr', $hTheme, 'hwnd', $hSrcDC, 'int', 1, 'int', 1, 'ptr', $pRect, 'ptr', 0) $hObj = _WinAPI_SelectObject($hMemDC, $hBitmap) _WinAPI_BitBlt($hMemDC, 0, 0, $Width - 8, $Height - 8, $hSrcDC, 0, 0, $MERGECOPY) _WinAPI_DrawText($hMemDC, $sText, $tRect, BitOR($DT_CENTER, $DT_SINGLELINE, $DT_VCENTER)) _WinAPI_SelectObject($hMemDC, $hObj) _GUIImageList_Add($hImageList, $hBitmap) ; PBS_HOT DllCall('uxtheme.dll', 'int', 'DrawThemeBackground', 'ptr', $hTheme, 'hwnd', $hSrcDC, 'int', 1, 'int', 2, 'ptr', $pRect, 'ptr', 0) $hObj = _WinAPI_SelectObject($hMemDC, $hBitmap) _WinAPI_BitBlt($hMemDC, 0, 0, $Width - 8, $Height - 8, $hSrcDC, 0, 0, $MERGECOPY) _WinAPI_DrawText($hMemDC, $sText, $tRect, BitOR($DT_CENTER, $DT_SINGLELINE, $DT_VCENTER)) _WinAPI_SelectObject($hMemDC, $hObj) _GUIImageList_Add($hImageList, $hBitmap) ; PBS_PRESSED DllCall('uxtheme.dll', 'int', 'DrawThemeBackground', 'ptr', $hTheme, 'hwnd', $hSrcDC, 'int', 1, 'int', 3, 'ptr', $pRect, 'ptr', 0) $hObj = _WinAPI_SelectObject($hMemDC, $hBitmap) _WinAPI_BitBlt($hMemDC, 0, 0, $Width - 8, $Height - 8, $hSrcDC, 0, 0, $MERGECOPY) _WinAPI_DrawText($hMemDC, $sText, $tRect, BitOR($DT_CENTER, $DT_SINGLELINE, $DT_VCENTER)) _WinAPI_SelectObject($hMemDC, $hObj) _GUIImageList_Add($hImageList, $hBitmap) ; PBS_DISABLED DllCall('uxtheme.dll', 'int', 'DrawThemeBackground', 'ptr', $hTheme, 'hwnd', $hSrcDC, 'int', 1, 'int', 4, 'ptr', $pRect, 'ptr', 0) $hObj = _WinAPI_SelectObject($hMemDC, $hBitmap) _WinAPI_BitBlt($hMemDC, 0, 0, $Width - 8, $Height - 8, $hSrcDC, 0, 0, $MERGECOPY) $Data = DllCall('uxtheme.dll', 'int', 'GetThemeColor', 'ptr', $hTheme, 'int', 1, 'int', 4, 'int', 3803, 'dword*', 0) If (Not @error) And (Not $Data[0]) Then $Prev = _WinAPI_SetTextColor($hMemDC, $Data[5]) EndIf _WinAPI_DrawText($hMemDC, $sText, $tRect, BitOR($DT_CENTER, $DT_SINGLELINE, $DT_VCENTER)) If $Prev > -1 Then _WinAPI_SetTextColor($hMemDC, $Prev) EndIf _WinAPI_SelectObject($hMemDC, $hObj) _GUIImageList_Add($hImageList, $hBitmap) ; PBS_DEFAULTED DllCall('uxtheme.dll', 'int', 'DrawThemeBackground', 'ptr', $hTheme, 'hwnd', $hSrcDC, 'int', 1, 'int', 5, 'ptr', $pRect, 'ptr', 0) $hObj = _WinAPI_SelectObject($hMemDC, $hBitmap) _WinAPI_BitBlt($hMemDC, 0, 0, $Width - 8, $Height - 8, $hSrcDC, 0, 0, $MERGECOPY) _WinAPI_DrawText($hMemDC, $sText, $tRect, BitOR($DT_CENTER, $DT_SINGLELINE, $DT_VCENTER)) _WinAPI_SelectObject($hMemDC, $hObj) _GUIImageList_Add($hImageList, $hBitmap) ; PBS_HOT (Stylus Hot) _GUIImageList_SetImageCount($hImageList, 6) _GUIImageList_Copy($hImageList, 1, 5) _WinAPI_DeleteDC($hMemDC) _WinAPI_DeleteDC($hSrcDC) _WinAPI_DeleteObject($hBitmap) _WinAPI_DeleteObject($hBack) DllCall('uxtheme.dll', 'int', 'CloseThemeData', 'ptr', $hTheme) $Data = _GUICtrlButton_GetImageList($hWnd) If $Data[0] Then _GUIImageList_Destroy($Data[0]) EndIf GUICtrlSetData($iCtrlID, '') If Not _GUICtrlButton_SetImageList($hWnd, $hImageList, 4) Then _GUIImageList_Destroy($hImageList) Return 0 EndIf Return 1 EndFunc ;==>_GUICtrlButton_SetTextColor Thank you. AnonymousX 1 Minesweeper A minesweeper game created in autoit, source available. _Mouse_UDF An UDF for registering functions to mouse events, made in pure autoit. 2D Hitbox Editor A 2D hitbox editor for quick creation of 2D sphere and rectangle hitboxes. Link to comment Share on other sites More sharing options...
borsTiHD Posted April 16, 2018 Share Posted April 16, 2018 (edited) ah, ignore me. Greetings borsTiHD Edited April 20, 2018 by borsTiHD 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