CyberSlug Posted November 28, 2004 Share Posted November 28, 2004 (edited) Only tested on an English version of Windows XP. Simulate Font and Color dialogs by polling the dialogs of WordPad and MsPaint .... Better workarounds--or someone adding native AutoIt support!--are encouraged. I tried all sorts of things, and this was the best I came up with without using "third-party" programs: expandcollapse popup; CyberSlug - 27 Nov 2004 ; Font and Color dialog windows ;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> #include <GuiConstants.au3> GuiCreate("Examples") $label = GuiCtrlCreateLabel("This is a a label", 10, 10, 400, 100) $buttonFont = GUICtrlCreateButton("Set Font", 10, 300, 100, 50) $buttonColor = GUICtrlCreateButton("Set Color", 210, 300, 100, 50) GuiSetState() While 1 $msg = GuiGetMsg() If $msg = $GUI_EVENT_CLOSE Then ExitLoop If $msg = $buttonFont Then $ret = FontDialog() If Not @error Then GuiCtrlSetfont($label, $ret[1], $ret[2], $ret[3], $ret[4]) EndIf If $msg = $buttonColor Then $ret = ColorDialog() If Not @error Then GuiCtrlSetColor($label, $ret) EndIf WEnd ;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> ;Runs MSPaint.exe hidden in order to obtain a blocking "Edit Colors" dialog ; Returns the selected color (RGB); sets @error to 1 if you click close/cancel ; ;NOTE: Function as written will only work with English ... You must change ; $PaintTile ... $dialogTitle for other languages. ;You might want to trap the Enter and Esc keys.... ;I tried Graying out the close button on the dialog, but the DllCall did not work on ; that window style even after I changed the window style with other DllCall's.... ;NOTE: Hex(-1, 6) returns a valid color, so it's a good idea to check @error ;Known bugs: If the OK button has focus and you click the "x" or press Alt+F4, then ; the error flag is not set Func ColorDialog() Local $PaintTitle = "untitled - Paint" Local $menuName = "&Colors" Local $menuItem = "&Edit Colors..." Local $dialogTitle = "Edit Colors" If Not StringInStr("0409,0809,0c09,1009,1409,1809,1c09,2009," & _ "2409,2809,2c09,3009,3409", @OSLang) Then MsgBox(4096,"Sorry", "This function only works on English versions of Windows...") SetError(1) Return EndIf Local $optDelay = Opt("WinWaitDelay", 5) Run("mspaint", "", @SW_HIDE) WinWait($paintTitle) WinGetHandle($paintTitle) WinMenuSelectItem($paintTitle, "", $menuName, $menuItem) WinWait($dialogTitle) WinActivate($dialogTitle) ControlClick($dialogTitle, "", "Button1");expands the "define custom colors" ControlFocus($dialogTitle,"","Static2") ControlSend($dialogTitle,"","Static2", " {Up 4}{Space}");select red color by default ControlFocus($dialogTitle,"","Button3") ; I select red so that the Luminosty slider is not on zero.... ControlDisable($dialogTitle, "", "Button6") WinSetOnTop($dialogTitle, "", 1) Local $focus = "";control that has focus; Button2 is the OK button Local $red, $green, $blue While 1 If WinExists($dialogTitle) Then If Not WinActive($dialogTitle) Then DllCall("user32.dll", "int", "MessageBeep", "int", 0x0) WinActivate($dialogTitle) EndIf Else ExitLoop EndIf ; Read Red=Edit4 Green=Edit5, Blue=Edit 6 ; using $tRed and later comparing to "" seems to be more reliable than directly setting $red Local $tRed = ControlGetText($dialogTitle, "", "Edit4") Local $tGreen = ControlGetText($dialogTitle, "", "Edit5") Local $tBlue = ControlGetText($dialogTitle, "", "Edit6") If ControlGetFocus($dialogTitle) <> "" Then $focus = ControlGetFocus($dialogTitle) If $tRed <> "" Then $red = $tRed If $tGreen <> "" Then $green = $tGreen If $tBlue <> "" Then $blue = $tBlue sleep(1) Local $color = Dec(Hex($red,2) & Hex($green,2) & Hex($blue,2)) ;;;;ToolTip("0x" & Hex($color, 6) & " " & $focus , 0, 0);for debugging Wend WinClose($PaintTitle) Opt("WinWaitDelay", $optDelay);restore winWaitDelay If $focus <> "Button2" Then SetError(1) Return Else Return $color EndIf EndFunc ;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> ;Runs Write.exe hidden in order to obtain a blocking "Edit Colors" dialog ; If user clicks close/cancel, sets @error to 1. Otherwise returns an array: ; [1]Size [2]Weight [3]Attribute [4]FontName see GUICtrlSetFont for info... ;NOTE: Function as written will only work with English ... You must change ; $PaintTile ... $dialogTitle for other languages. ;You might want to trap the Enter and Esc keys.... ;I tried Graying out the close button on the dialog, but the DllCall did not work on ; that window style even after I changed the window style with other DllCall's.... ;Known bugs: If the OK button has focus and you click the "x" or press Alt+F4, then ; the error flag is not set Func FontDialog() Local $WordpadTitle = "Document - WordPad" Local $menuName = "F&ormat" Local $menuItem = "&Font..." Local $dialogTitle = "Font" If Not StringInStr("0409,0809,0c09,1009,1409,1809,1c09,2009," & _ "2409,2809,2c09,3009,3409", @OSLang) Then MsgBox(4096,"Sorry", "This function only works on English versions of Windows...") SetError(1) Return EndIf Local $optDelay = Opt("WinWaitDelay", 5) Run("write", "", @SW_HIDE) WinWait($WordpadTitle) WinGetHandle($WordpadTitle) WinMenuSelectItem($WordpadTitle, "", $menuName, $menuItem) WinWait($dialogTitle) WinActivate($dialogTitle) ControlHide($dialogTitle,"", "Static7") ;hide the script label ControlHide($dialogTitle,"", "ComboBox5");hide the script combobox ControlHide($dialogTitle,"", "ComboBox4");hide the color combobox ControlFocus($dialogTitle,"","Button6") ;focus on the Cancel button WinSetOnTop($dialogTitle, "", 1) ; Local $focus = "";control that has focus; Button5 is the OK button Local $font, $style, $size, $strikeout, $underline While 1 If WinExists($dialogTitle) Then If Not WinActive($dialogTitle) Then DllCall("user32.dll", "int", "MessageBeep", "int", 0x0) WinActivate($dialogTitle) EndIf Else ExitLoop EndIf ; using $tFont and later comparing to "" seems to be more reliable than directly setting $font Local $tFont = ControlGetText($dialogTitle, "", "Edit1") Local $tStyle = ControlGetText($dialogTitle, "", "Edit2") Local $tSize = ControlGetText($dialogTitle, "", "Edit3") Local $tStrikeout = ControlCommand($dialogtitle,"", "Button2", "IsChecked","") If @error Then $tStrikeout = 0 Local $tUnderline = ControlCommand($dialogtitle,"", "Button3", "IsChecked","") If @error Then $tUnderline = 0 If ControlGetFocus($dialogTitle) <> "" Then $focus = ControlGetFocus($dialogTitle) If $tFont <> "" Then $font = $tFont If $tStyle <> "" Then $style = $tStyle If $tSize <> "" Then $size = $tSize If $tStrikeout <> "" Then $strikeout = $tStrikeout If $tUnderline <> "" Then $underline = $tUnderline sleep(1) ;;;;ToolTip($font & $style & $Size & $focus & $strikeout & $underline , 0, 0);for debugging Wend WinClose($WordpadTitle) Opt("WinWaitDelay", $optDelay);restore winWaitDelay Local $attribute = 0, $weight = 400 If StringInStr($style, "Italic") Then $attribute = $attribute + 2 If $underline Then $attribute = $attribute + 4 If $strikeout Then $attribute = $attribute + 8 If StringInStr($style, "Bold") Then $weight = 800 If $focus <> "Button5" Then SetError(1) Return Else Return StringSplit($size & "," & $weight & "," & $attribute & "," & $font, ",") EndIf EndFunc Edited November 28, 2004 by CyberSlug Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig! Link to comment Share on other sites More sharing options...
this-is-me Posted November 28, 2004 Share Posted November 28, 2004 (edited) There was an autoit-only editor that had fake versions of this. I think it was called NotepadNG. I would imagine an au3gui interface would do the same. EDIT: that was only for the font, though. Edited November 28, 2004 by this-is-me Who else would I be? Link to comment Share on other sites More sharing options...
alawoona Posted November 28, 2004 Share Posted November 28, 2004 Could these dll's be a solution ? (I certainly don't know enough yet to figure out if ithey can be used in AutoIt) CHOOSECOLOR The ChooseColor function creates a Color common dialog box that enables the user to select a color. VB4-32,5,6 Declare Function ChooseColor Lib "comdlg32.dll" Alias "ChooseColorA" (pChoosecolor As CHOOSECOLOR) As Long VB.NET System.Windows.ColorDialog.RunDialog Operating Systems Supported Requires Windows NT 3.1 or later; Requires Windows 95 or later Library Comdlg32 Parameter Information · lpcc Pointer to a CHOOSECOLOR structure that contains information used to initialize the dialog box. When ChooseColor returns, this structure contains information about the users color selection. Return Values If the user clicks the OK button of the dialog box, the return value is nonzero. The rgbResult member of the CHOOSECOLOR structure contains the RGB color value of the color selected by the user. If the user cancels or closes the Color dialog box or an error occurs, the return value is zero. To get extended error information, call the CommDlgExtendedError function, which can return one of the following values: CDERR_FINDRESFAILURE, CDERR_MEMLOCKFAILURE, CDERR_INITIALIZATION, CDERR_NOHINSTANCE, CDERR_LOCKRESFAILURE, CDERR_NOHOOK, CDERR_LOADRESFAILURE, CDERR_NOTEMPLATE, CDERR_LOADSTRFAILURE, CDERR_STRUCTSIZE, CDERR_MEMALLOCFAILURE =============================================== CHOOSEFONT The ChooseFont function creates a Font common dialog box that enables the user to choose attributes for a logical font. These attributes include a typeface name, style (bold, italic, or regular), point size, effects (underline, strikeout, and text color), and a script (or character set). VB4-32,5,6 Declare Function ChooseFont Lib "comdlg32.dll" Alias "ChooseFontA" (pChoosefont As CHOOSEFONT) As Long VB.NET System.Windows.FontDialog.RunDialog Operating Systems Supported Requires Windows NT 3.1 or later; Requires Windows 95 or later Library Comdlg32 Parameter Information · lpcf Pointer to a CHOOSEFONT structure that contains information used to initialize the dialog box. When ChooseFont returns, this structure contains information about the users font selection. Return Values If the user clicks the OK button of the dialog box, the return value is nonzero. The members of the CHOOSEFONT structure indicate the users selections. If the user cancels or closes the Font dialog box or an error occurs, the return value is zero. To get extended error information, call the CommDlgExtendedError function, which can return one of the following values: CDERR_FINDRESFAILURE, CDERR_NOHINSTANCE, CDERR_INITIALIZATION, CDERR_NOHOOK, CDERR_LOCKRESFAILURE, CDERR_NOTEMPLATE, CDERR_LOADRESFAILURE, CDERR_STRUCTSIZE, CDERR_LOADSTRFAILURE, CFERR_MAXLESSTHANMIN, CDERR_MEMALLOCFAILURE, CFERR_NOFONTS, CDERR_MEMLOCKFAILURE Link to comment Share on other sites More sharing options...
Developers Jos Posted November 28, 2004 Developers Share Posted November 28, 2004 (edited) CyberSlug, I had the same challenge with SciteConfig.au3 and wrote 2 helper programs to accomplish this called SelectFont and SelectColor ... They communicate via the hidden autoit window.... EDIT: here are the details: Just copy the 2 programs from your SciTE program directory. WHen they are not there, just run SciTEConfig to fileinstall them. Here a demo script how it works: expandcollapse popup; autoit version: 3.0 ; language: english ; platform: win2k/xp ; author: jos van der zande ; Date: November 28, 2004 ; ; script function: Demo Font and color selectionbox ; ;Install the 2 needed helper apps FileInstall("lcc\selectcolor.exe", @ScriptDir & "\", 1) FileInstall("lcc\selectfont.exe", @ScriptDir & "\", 1) ; set default font $FontType = "Courier New" $FontSize = "10" MsgBox(0,'Color','New color is:' & SelectColor("Demo","0x0a0b0c")) SelectFont($FontType,$FontSize) MsgBox(0,'Font','New Font is:' & $FontType & " Size:" & $FontSize) SelectFont2($FontType,$FontSize) MsgBox(0,'Font','New Font is:' & $FontType & " Size:" & $FontSize) ;***************************************************************************** ; Font Selection part simple ;***************************************************************************** Func SelectFont(ByRef $S_FontType, ByRef $S_FontSize) $Ahnd = WinGetHandle(AutoItWinGetTitle()) AutoItWinSetTitle("getFont") $Whnd = RunWait(@ScriptDir & '\selectfont ' & $Ahnd & ' "' & $S_FontType & '" ' & $S_FontSize & '') If AutoItWinGetTitle() <> "getFont" Then $S_FontType = StringTrimLeft(AutoItWinGetTitle(), 1) $S_FontSize = StringStripWS(StringTrimLeft($S_FontType, StringInStr($S_FontType, '"') + 1), 3) $S_FontType = StringStripWS(StringLeft($S_FontType, StringInStr($S_FontType, '"') - 1), 3) Return 1 EndIf Return 0 EndFunc ;==>Select_Font ;***************************************************************************** ; Font Selection part advanced: changes the Font prompt menu ;***************************************************************************** Func SelectFont2(ByRef $S_FontType, ByRef $S_FontSize) $Ahnd = WinGetHandle(AutoItWinGetTitle()) $Whnd = Run(@ScriptDir & '\selectfont ' & $Ahnd & ' "' & $S_FontType & '" ' & $S_FontSize & '') WinWait("Font", '', 5) If $Whnd = 0 Then $Whnd = WinGetHandle("Font") AutoItWinSetTitle("getFont") WinSetTitle("Font", '', "Select Scite Font") $wpos = WinGetPos("Select Scite Font", "") WinMove("Select Scite Font", "", $wpos[0], $wpos[1] + 45, $wpos[2], $wpos[3] - 90) ControlDisable("Select Scite Font", "", "Edit2") ControlDisable("Select Scite Font", "", "ComboLBox2") WinWaitClose("Select Scite Font") If AutoItWinGetTitle() <> "getFont" Then $S_FontType = StringTrimLeft(AutoItWinGetTitle(), 1) $S_FontSize = StringStripWS(StringTrimLeft($S_FontType, StringInStr($S_FontType, '"') + 1), 3) $S_FontType = StringStripWS(StringLeft($S_FontType, StringInStr($S_FontType, '"') - 1), 3) Return 1 EndIf EndFunc ;==>Select_Font ;***************************************************************************** ; Color Selection Part ;***************************************************************************** Func SelectColor($Type, $CurColor) Local $R = Dec(StringMid($CurColor, 3, 2)) Local $G = Dec(StringMid($CurColor, 5, 2)) Local $B = Dec(StringMid($CurColor, 7, 2)) $Ahnd = WinGetHandle(AutoItWinGetTitle()) $Whnd = Run(@ScriptDir & '\selectcolor ' & $Ahnd & ' ' & $R & ' ' & $G & ' ' & $B & '') WinWait("Color", '', 2) WinSetTitle("Color", '', "Select Color for " & $Type) WinWaitClose("Select Color for " & $Type) Return StringReplace(AutoItWinGetTitle(), "#", "0X") EndFunc ;==>SelectColor Edited October 21, 2013 by Jos SciTE4AutoIt3 Full installer Download page  - Beta files    Read before posting   How to post scriptsource   Forum etiquette Forum Rules  Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
this-is-me Posted November 28, 2004 Share Posted November 28, 2004 Phooey... I was about to upload a wip version of an autoit-only fake color picker. Here is a screenshot of the current progress: Who else would I be? Link to comment Share on other sites More sharing options...
CyberSlug Posted November 28, 2004 Author Share Posted November 28, 2004 @alawoona: I saw that earlier, but the function requires some sort of LPCHOOSECOLOR type paramter which AutoIt doesn't support (as far as I know). @JdeB: Thanks for the info. It's not as satisfying as a 100% AutoIt solution, but I'll try it until I write my own color choosing GUI. Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig! Link to comment Share on other sites More sharing options...
this-is-me Posted November 28, 2004 Share Posted November 28, 2004 I can upload the current progress if you need it Sluggie. Who else would I be? Link to comment Share on other sites More sharing options...
CyberSlug Posted November 28, 2004 Author Share Posted November 28, 2004 Phooey... I was about to upload a wip version of an autoit-only fake color picker.Here is a screenshot of the current progress:<{POST_SNAPBACK}>If you can get that to work, I'd be interested Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig! Link to comment Share on other sites More sharing options...
this-is-me Posted November 28, 2004 Share Posted November 28, 2004 I'll be working on this later tonight and upload. Who else would I be? Link to comment Share on other sites More sharing options...
this-is-me Posted November 29, 2004 Share Posted November 29, 2004 Oh, fiddlesticks. I worked on it last night, was too tired to upload, put it all on a USB stick to bring with me this morning, and left it at home. *mumble* Anyway, I will get it again when I get home and try to upload then. Until then, anyone have an autoit-only HSL to RGB converter? Who else would I be? Link to comment Share on other sites More sharing options...
this-is-me Posted November 30, 2004 Share Posted November 30, 2004 (edited) hsl to rgb is not working, but color picking functions are as are rgb to hsl conversions. Try this one. (not finished, but looking good so far) colorpicker.zip Edited November 30, 2004 by this-is-me Who else would I be? Link to comment Share on other sites More sharing options...
Lazycat Posted November 30, 2004 Share Posted November 30, 2004 Very nice. And interesting side effect - while holding mouse button you can pick color from any other place of desktop Koda homepage ([s]Outdated Koda homepage[/s]) (Bug Tracker)My Autoit script page ([s]Outdated mirror[/s]) Link to comment Share on other sites More sharing options...
this-is-me Posted November 30, 2004 Share Posted November 30, 2004 Not a side effect - a feature. I wanted it to be that way. Who else would I be? 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