rdwray Posted December 19, 2010 Share Posted December 19, 2010 (edited) On lines 51 and 55 I tried to add color to the buttons and when I do the button comes up blank, why and how to fix? I tried looking for a good WM_CTRCOLORBTN example but could not find one. BTW: this is a working program but probably needs more testing on other systems. Thanks...expandcollapse popup#Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_icon=..\..\Images\ico\Bible48.ico #AutoIt3Wrapper_outfile=ShortCutBar.exe #AutoIt3Wrapper_Run_Obfuscator=y #Obfuscator_Parameters=/so #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #cs ---------------------------------------------------------------------------- AutoIt Version: 3.3.6.1 Author: myName Script Function: Template AutoIt script. #ce ---------------------------------------------------------------------------- ; Script Start - Add your code below here #Include <ButtonConstants.au3> #Include <Misc.au3> #Include <WinAPI.au3> #include <WindowsConstants.au3> #Include <GuiButton.au3> ; Variables Global $ASSOCF_VERIFY = 0x00000040 Global $ASSOCSTR_EXECUTABLE = 2 Global $dll = DllOpen("user32.dll") ; _IsKeypressed events. Global $i, $x, $y, $str, $WinPos ; Generic values Global $ID, $hGuiBar, $bCtrl[27], $sc[27][3], $wOrt, $wLeft, $wTop ; GuiBar window. Global $hGuiOpt, $file, $alias, $key, $showbar, $clear, $orient, $Save, $close, $exit ; Options window. Global $moved, $bID, $teststr ; Misc. HotKeySet("!{F1}", "Help") ;=====================Read in data.===================== LoadData() Func LoadData() For $i = 1 to 26 ; Must have same value as control ID or tooltip crashes program. $sc[$i][1] = IniRead(@ScriptDir & "\ShortCuts.ini", "ShortCuts" & $i, "Program" & $i, "") $sc[$i][2] = IniRead(@ScriptDir & "\ShortCuts.ini", "ShortCuts" & $i, "Alias" & $i, "") Next $wOrt = IniRead(@ScriptDir & "\ShortCuts.ini", "Orientation", "Orient", "") $wLeft = IniRead(@ScriptDir & "\ShortCuts.ini", "Position", "Left", "") $wTop = IniRead(@ScriptDir & "\ShortCuts.ini", "Position", "Top", "") EndFunc ;=====================Create bar.===================== CreateBar() Func CreateBar() $x = 0 $y = 0 If $wOrt = "" Then $wOrt = 4 ; In case .ini is not found. .ini is generated on first save or exit. If $wOrt = 4 Then ; Horizontal. $GUI_SS_DEFAULT_GUI, $WS_EX_TOOLWINDOW $hGuiBar = GUICreate("ShortCutBar", 24 * 26, 24, $wLeft, $wTop, $WS_POPUP, $WS_EX_TOOLWINDOW) ; GUICtrlSetDefBkColor (0xff0000, $hGuiBar ) ; Keeps icons from appearing. GUISetFont(11, 400, 0, "Algerian") For $i = 1 to 26 $bCtrl[$i] = GUICtrlCreateButton("", $x, 0, 24, 24, $BS_ICON + $BS_DEFPUSHBUTTON) ; GUICtrlSetBkColor( $bCtrl[$i], 0xff0000) ; Keeps icons from appearing. LoadIcon($i) $x += 24 Next Else ; Verical. $hGuiBar = GUICreate("ShortCutBar", 24, 24 * 26,$wLeft, $wTop, $WS_POPUP ,$WS_EX_TOOLWINDOW) GUISetFont(11, 400, 0, "Algerian") For $i = 1 to 26 $bCtrl[$i] = GUICtrlCreateButton("", 0, $y, 24, 24, $BS_ICON + $BS_DEFPUSHBUTTON) LoadIcon($i) $y += 24 Next EndIf GUISetState(@SW_SHOW, $hGuiBar) EndFunc ; CreateBar() Func LoadIcon($i) Local $prog, $iconfound, $int ; Full internet string: ".ac",".af",".al",".am",".as",".at",".au",".az",".be",".biz",".bt",".ca",".cc",".ch",".cn",".coop",".cx",".cz",".de",".dk",".dz",".ec",".edu",".ee",".eg",".es",".fo",".fr",".ga",".gf",".gl",".gov",".gr",".gs",".hk",".il",".in",".info",".io",".is",".it",".jp",".kr",".kz",".li",".lu",".ly",".mc",".mil",".mm",".ms",".mx",".net",".nl",".no",".nu",".nz",".org",".pl",".pt",".ro",".ru",".se",".sg",".sg",566".tc",".st",".tc",".tf",".th",".tj",".tm",".to",".uk",".us", Local $http[9] = [".com",".net",".org",".edu",".info",".us",".biz",".gov",".mil"] ; Executable If $sc[$i][1] = "" Then ; No data. GUICtrlSetData($bCtrl[$i], Chr($i + 64)) ElseIf StringRight($sc[$i][1], 4) = ".exe" then ; Executable. GUICtrlSetImage($bCtrl[$i], $sc[$i][1], 1, 0) ElseIf StringMid($sc[$i][1], Stringlen($sc[$i][1]) -3, 1) = "." Then ; Misc files $prog = _FileAssociation(StringRight($sc[$i][1], 4)) ; Get associated program for file type. If $prog ="" Then $prog = "Shell32.dll" ; Generic icon used when program not found. GUICtrlSetImage($bCtrl[$i], $prog, 1, 0) ElseIf StringLeft($sc[$i][1], 6) = "mailto" then ; Mail $var = RegRead("HKEY_CLASSES_ROOT\mailto\DefaultIcon", "") $var = StringLeft($var, Stringlen($var) -2) GUICtrlSetImage($bCtrl[$i], $var, 1, 0) ElseIf StringMid($sc[$i][1], 2, 2) = ":\" And StringMid($sc[$i][1], Stringlen($sc[$i][1]) -3, 1) <> "." Then ; Folders GUICtrlSetImage($bCtrl[$i], "Shell32.dll", 4, 0) ; Folder icon. EndIf ; Internet For $int = 0 to 8 If StringRight($sc[$i][1], StringLen($http[$int])) = $http[$int] Then GUICtrlSetImage($bCtrl[$i], @ProgramFilesDir & "\Internet Explorer\iexplore.exe", 1, 0) EndIf Next EndFunc ; LoadIcon($i) ; _FileAssociation By WideBoyDixon ; http://www.autoitscript.com/forum/topic/96988-winapi-findexecutable-replacement/page__p__697477__hl__assocquerystringw__fromsearch__1#entry697477 Func _FileAssociation($sExt) Local $aCall Local $aCall = DllCall("shlwapi.dll", "int", "AssocQueryStringW", _ "dword", $ASSOCF_VERIFY, _ "dword", $ASSOCSTR_EXECUTABLE, _ "wstr", $sExt, _ "ptr", 0, _ "wstr", "", _ "dword*", 65536) If @error Then Return SetError(1, 0, ""); call failed EndIf If Not $aCall[0] Then Return SetError(0, 0, $aCall[5]) ElseIf $aCall[0] = 0x80070002 Then Return SetError(0, 0, "{unknown}"); COM Error 0x80070002, ?The system cannot find the file specified.' ElseIf $aCall[0] = 0x80004005 Then Return SetError(0, 0, "{fail}"); E_FAIL Else Return SetError(2, $aCall[0], ""); EndIf EndFunc ; _FileAssociation() ;=====================Create Options.===================== $hGuiOpt = GUICreate("Options", 500, 350, (@DesktopWidth / 2) -250, (@DesktopHeight / 2) - 150, $WS_BORDER ) GUISetFont(11, 400, 0, "Tahoma") GUICtrlCreateLabel("Press Alt+F1 for help...", 20, 10) GUICtrlCreateLabel("Enter program path or:", 90, 40) $browse = GUICtrlCreateButton("Browse", 280, 30) $file = GUICtrlCreateInput("", 90, 70, 390, 30) GUICtrlSetData($file, $sc[1][1]) GUICtrlCreateLabel("Enter name for shortcut:", 90, 110) $alias = GUICtrlCreateInput("", 90, 140, 390, 30) $Clear = GUICtrlCreateButton("&Clear", 200, 180, 120) GUICtrlSetData($alias, $sc[1][2]) GUICtrlCreateLabel("Select" & @CRLF & "Key", 20, 45) $key = GUICtrlCreateList("A", 20, 90, 50, 150) For $i = 66 to 89 $str &= Chr($i) & "|" Next $str &= "Z" GUICtrlSetData($key, $str, "A") $orient = GUICtrlCreateCheckbox("Checked = Verticle; Uncheck = Horizontal", 90, 220, 390) GUICtrlSetState($orient, $wOrt) GUICtrlCreateLabel("Save after each change!", 150, 250) $Save = GUICtrlCreateButton("&Save", 65, 280, 120) $close = GUICtrlCreateButton("&Close Options", 189, 280, 120) $exit = GUICtrlCreateButton("&Exit Program", 313, 280, 120) ; ExtractAssociatedIcon Main() Func Main() Local $tPOINT, $hWnd Local $oldBut, $oldkey $moved = False While 1 $ID = GUIGetCursorInfo($hGuiBar) $tPOINT = _WinApi_GetMousePos() $hWnd = _WinApi_WindowFromPoint($tPOINT) $hParent = _WinApi_GetParent($hWnd) If _IsPressed("01", $dll) And WinActive($hGuiBar) Then RunProg() If _IsPressed("02", $dll) And WinActive($hGuiBar) Then MoveBar($hGuiBar) If $moved = False And $ID[4] > 2 Then ; If $moved = true the bar was moved - don't open options. GUICtrlSetData($key, Chr($ID[4] + 62)) GUICtrlSetData($file, $sc[$ID[4]-2][1]) GUICtrlSetData($alias, $sc[$ID[4]-2][2]) $bID = $ID[4] ; Open different window, save ID of button selected. GUISetState(@SW_SHOW, $hGuiOpt) ; Open options window if the shortcur bar has not been moved. _WinAPI_SetFocus($save) EndIf EndIf If $hParent = $hGuiBar And $ID[4] > 2 And $ID[4] <> $oldBut Then If $sc[$ID[4]-2][2] <> "" Then Tooltip($sc[$ID[4]-2][2]) else ToolTip("Press Alt+F1 for help." & @CRLF _ & "Right click to open options." & @CRLF _ & "Right click and hold to move.") EndIf $oldBut = $ID[4] EndIf If $hParent <> $hGuiBar Then ToolTip("") Switch GUIGetMsg(0) Case $browse GUICtrlSetData($file, FileOpenDialog("Select file for shortcut", @HomeDrive, "All (*.*)", 1 )) Case $clear GUICtrlSetData($file, "") GUICtrlSetData($alias, "") Case $key ; Load data based on key value. If GUICtrlRead($key) <> $oldkey Then $oldkey = (Asc(GUICtrlRead($key))-64) GUICtrlSetData($file, $sc[$oldkey][1]) GUICtrlSetData($alias, $sc[$oldkey][2]) $bID = $oldkey + 2 ; Update in case of concurrent save. EndIf Case $orient WriteFile() GUIDelete($hGuiBar) LoadData() CreateBar() Case $save $sc[$bID -2][1] = GUICtrlRead($file) $sc[$bID -2][2] = GUICtrlRead($alias) WriteFile() GUIDelete($hGuiBar) LoadData() CreateBar() Case $close GUISetState(@SW_HIDE, $hGuiOpt) Case $exit WriteFile() ; Save position of window. GUIDelete($hGuiOpt) ; Delete Options window. GUIDelete($hGuiBar) ; Delete Shortcut window. Exit EndSwitch Wend EndFunc ;<<--Main() Func MoveBar($hWnd) Local $PosDiff[2], $WinPos2 While 1 Local $MousePos = MouseGetPos () $WinPos = WinGetPos ($hWnd,"") $PosDiff[0] = $WinPos[0] - $MousePos[0] $PosDiff[1] = $WinPos[1] - $MousePos[1] While _IsPressed ("02", $dll) $MousePos = MouseGetPos () WinMove ($hWnd, "", $MousePos[0] + $PosDiff[0], $MousePos[1] + $PosDiff[1]) WEnd Sleep (10) ExitLoop WEnd $WinPos2 = WinGetPos ($hWnd,"") If $WinPos2[0] < 0 Then WinMove("ShortCutBar", "", 0, $WinPos2[1]) If $WinPos2[1] < 0 Then WinMove("ShortCutBar", "", $WinPos2[0], 0) ; +-3 allows for some movement error when trying to run program. If ($WinPos[0] < $WinPos2[0] - 3) Or ($WinPos[1] < $WinPos2[1] - 3) Or _ ($WinPos[0] > $WinPos2[0] + 3) Or ($WinPos[1] > $WinPos2[1] + 3)Then $moved = True ; If the window was moved, don't run program on return. Else $moved = False EndIf Sleep (10) EndFunc Func WriteFile() For $i = 1 to 26 IniWrite(@ScriptDir & "\ShortCuts.ini", "ShortCuts" & $i, "Key" & $i, Chr($i + 64)) IniWrite(@ScriptDir & "\ShortCuts.ini", "ShortCuts" & $i, "Program" & $i, $sc[$i][1]) IniWrite(@ScriptDir & "\ShortCuts.ini", "ShortCuts" & $i, "Alias" & $i, $sc[$i][2]) Next IniWrite(@ScriptDir & "\ShortCuts.ini", "Orientation", "Orient", GUICtrlRead($orient)) $WinPos = WinGetPos("ShortCutBar") If $WinPos[0] = "" then $WinPos[0] = 0 If $WinPos[1] = "" then $WinPos[1] = 0 IniWrite(@ScriptDir & "\ShortCuts.ini", "Position", "Left", $WinPos[0]) IniWrite(@ScriptDir & "\ShortCuts.ini", "Position", "Top", $WinPos[1]) EndFunc Func RunProg() If $ID[4] > 2 And $sc[$ID[4]-2][1] <> "" then ShellExecuteWait ($sc[$ID[4]-2][1]) Sleep(100) ; Got to give enough time for program to open or more copies will be ran. EndFunc Func Help() Local $help = "Enter entire program path or button will may be blank." & @CRLF & @CRLF _ & "If program does not have an icon and the full path is entered the button will not be changed." & @CRLF & @CRLF _ & "If a file's full is entered in the program box, the associated program's icon will be on the button." & @CRLF & @CRLF _ & "if a website is entered, it must be complete; your browser's icon will be on the button." & @CRLF & @CRLF _ & "Enter anything in the name for shortcut box, it will show up in the tooltip." & @CRLF & @CRLF _ & "Bar can be placed anywhere and it will be remembered."& @CRLF & @CRLF _ & "Right click to open options." & @CRLF & @CRLF _ & "Right click and hold to move bar." MsgBox(0, "Shortcut Bar Help", $help) EndFunc Edited December 19, 2010 by rdwray “No other God have I but Thee; born in a manger, died on a tree.” Martin Luther Link to comment Share on other sites More sharing options...
wakillon Posted December 19, 2010 Share Posted December 19, 2010 (edited) If I test your script nothing happensbut if i try only buttons creation part, red color is well add to buttons ! expandcollapse popup#Include <ButtonConstants.au3> #include <WindowsConstants.au3> Global $ASSOCF_VERIFY = 0x00000040 Global $ASSOCSTR_EXECUTABLE = 2 Global $x=0, $bCtrl[27], $sc[27][3] $hGuiBar = GUICreate("ShortCutBar", 24 * 26, 24, -1, -1, $WS_POPUP, $WS_EX_TOOLWINDOW) GUICtrlSetDefBkColor (0xff0000, $hGuiBar ) ; Keeps icons from appearing. GUISetFont(11, 400, 0, "Algerian") For $i = 1 to 26 $bCtrl[$i] = GUICtrlCreateButton("", $x, 0, 24, 24, $BS_ICON + $BS_DEFPUSHBUTTON) LoadIcon($i) $x += 24 GUICtrlSetBkColor( $bCtrl[$i], 0xff0000) ; Keeps icons from appearing. Next GUISetState() Sleep( 3000 ) Func LoadIcon($i) Local $prog, $iconfound, $int Local $http[9] = [".com",".net",".org",".edu",".info",".us",".biz",".gov",".mil"] ; Executable If $sc[$i][1] = "" Then ; No data. GUICtrlSetData($bCtrl[$i], Chr($i + 64)) ElseIf StringRight($sc[$i][1], 4) = ".exe" then ; Executable. GUICtrlSetImage($bCtrl[$i], $sc[$i][1], 1, 0) ElseIf StringMid($sc[$i][1], Stringlen($sc[$i][1]) -3, 1) = "." Then ; Misc files ;$prog = _FileAssociation(StringRight($sc[$i][1], 4)) ; Get associated program for file type. ;If $prog ="" Then $prog = "Shell32.dll" ; Generic icon used when program not found. ;GUICtrlSetImage($bCtrl[$i], $prog, 1, 0) ElseIf StringLeft($sc[$i][1], 6) = "mailto" then ; Mail $var = RegRead("HKEY_CLASSES_ROOT\mailto\DefaultIcon", "") $var = StringLeft($var, Stringlen($var) -2) GUICtrlSetImage($bCtrl[$i], $var, 1, 0) ElseIf StringMid($sc[$i][1], 2, 2) = ":\" And StringMid($sc[$i][1], Stringlen($sc[$i][1]) -3, 1) <> "." Then ; Folders GUICtrlSetImage($bCtrl[$i], "Shell32.dll", 4, 0) ; Folder icon. EndIf ; Internet For $int = 0 to 8 If StringRight($sc[$i][1], StringLen($http[$int])) = $http[$int] Then GUICtrlSetImage($bCtrl[$i], @ProgramFilesDir & "\Internet Explorer\iexplore.exe", 1, 0) EndIf Next EndFunc ; LoadIcon($i) Edited December 19, 2010 by wakillon AutoIt 3.3.14.2 X86 - SciTE 3.6.0 - WIN 8.1 X64 - Other Example Scripts Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted December 19, 2010 Moderators Share Posted December 19, 2010 (edited) rdwray,Colouring buttons produces all sorts of unpleasant side-effects in AutoIt - for example they trap the "Enter" key regardless of their $BS_DEFPUSHBUTTON state. It is known bug for a long time which cannot be fixed without entirely rewriting the core code - and that is not going to happen any time soon. So, either have coloured buttons or icons - your choice. M23Edit: The earliest ticket about this in Trac: #376 Edited December 19, 2010 by Melba23 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...
Zedna Posted December 19, 2010 Share Posted December 19, 2010 (edited) I can confirm that behaiour Here is small reproducing script: #Include <ButtonConstants.au3> #include <WindowsConstants.au3> #Include <GuiButton.au3> #Include <Guiconstants.au3> Global $bCtrl[100] Global $x $hGuiBar = GUICreate("ShortCutBar", 24 * 26, 24, 10, 10, $WS_POPUP, $WS_EX_TOOLWINDOW) ; GUICtrlSetDefBkColor (0xff0000, $hGuiBar ) ; Keeps icons from appearing. GUISetFont(11, 400, 0, "Algerian") For $i = 1 to 26 $bCtrl[$i] = GUICtrlCreateButton("", $x, 0, 24, 24, $BS_ICON + $BS_DEFPUSHBUTTON) GUICtrlSetBkColor( $bCtrl[$i], 0xff0000) ; Keeps icons from appearing. GUICtrlSetImage($bCtrl[$i], "Shell32.dll", 4, 0) ; Folder icon. $x += 24 Next GUISetState(@SW_SHOW, $hGuiBar) While 1 Switch GUIGetMsg(0) Case $GUI_EVENT_CLOSE Exit EndSwitch Wend Edited December 19, 2010 by Zedna Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
rdwray Posted December 19, 2010 Author Share Posted December 19, 2010 You guys have hurt me badly, I am going to go sulk now... “No other God have I but Thee; born in a manger, died on a tree.” Martin Luther Link to comment Share on other sites More sharing options...
rdwray Posted December 19, 2010 Author Share Posted December 19, 2010 wakillon, what do you mean nothing happens????? “No other God have I but Thee; born in a manger, died on a tree.” Martin Luther 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