Color Picker

Ideas for new features & functions

Moderators: Dorian (MJT support), JRL

Post Reply
User avatar
JRL
Automation Wizard
Posts: 3497
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Color Picker

Post by JRL » Thu Jun 05, 2008 2:27 pm

To enhance the usability of SetDialogObjectFont>, I'd like to see a new Advanced Editor, Tools menu item called something like Color Picker. It could call the Microsoft ChooseColor function and return the color number to the current cursor position in the Editor.

I tried writing my own with limited success. I first tried using the ChooseColor function from comdlg32.dll. The only parameter is "a pointer to a ChooseColor structure". I can never make pointers to structures work so I looked for a VBScript example. I found this HTA on the Microsoft "Scripting Guy" site. Put this in an .HTA file and it will open a dialog that has a "Run Script" button. Whatever color you choose becomes the new background color for the dialog.

Code: Select all

<SCRIPT LANGUAGE="VBScript">
    Sub TestSub
        intColor=dlgHelper.ChooseColorDlg    
        If intColor <> 0 then
            document.body.bgColor=intColor
        End If
    End Sub
</SCRIPT>

<body>
    <OBJECT id=dlgHelper CLASSID="clsid:3050f819-98b5-11cf-bb82-00aa00bdce0b" width="0px" height="0px"></OBJECT> 
    <input id=runbutton type="button" value="Run Script" name="run_button" onClick="TestSub">
</body>
I tried adapting this to a vbscript that could run with VBEval> but I was unsuccessful. So instead I added a couple of lines to write the color value out to a file. This at first seemed to work. but then I noticed that some (most) of the time I got a different color from the one I selected.

The script below is displaying two numbers. The first is the number that comes from the HTA file and the second is one that comes from the GetPixelColor> function. Of course the GetPixelColor> selection is always correct for Macro Scheduler.

I'm hoping that "someone" can do two things based on this script.

1- Write the VBScript version that could eliminate all the Mickey Mouse file writing and window manipulation that my script is performing.

2- Have the vbscript color number be the correct format to use in Macro Scheduler. I've not yet figured out how to convert the HTA script's color output to be correct for Macro Scheduler.

Code: Select all

IfWindowOpen>Color,EOF
OnEvent>KEY_DOWN,VK1,0,CheckColor
OnEvent>KEY_DOWN,VK13,0,CheckColor

SRT>CheckColor
GetActiveWindow>title,WinX,WinY
If>title=Color
  Add>WinX,260
  Add>WinY,240
  GetPixelColor>WinX,WinY,color2
EndIf
END>CheckColor

Let>file1=%temp_dir%color_picker.hta
Let>file2=%temp_dir%color.txt
Let>file3=%temp_dir%Color.scp

IfFileExists>file1
  DeleteFile>file1
EndIf
IfFileExists>file2
  DeleteFile>file2
EndIf
IfFileExists>file3
  DeleteFile>file3
EndIf


Let>filedata=<SCRIPT LANGUAGE="VBScript">%CRLF%
Concat>filedata,    Sub TestSub%CRLF%
Concat>filedata,      Dim fso, ThisFile%CRLF%
Concat>filedata,      Set fso = CreateObject("Scripting.FileSystemObject")%CRLF%
Concat>filedata,      Set ThisFile = fso.CreateTextFile("%file2%", True)%CRLF%
Concat>filedata,        intColor=dlgHelper.ChooseColorDlg%CRLF%
Concat>filedata,        If intColor <> 0 then%CRLF%
Concat>filedata,           ' document.body.bgColor=intColor%CRLF%
Concat>filedata,            ThisFile.Write intColor%CRLF%
Concat>filedata,        End If%CRLF%
Concat>filedata,    End Sub%CRLF%
Concat>filedata,</SCRIPT>%CRLF%

Concat>filedata,<body>%CRLF%
Concat>filedata,    <OBJECT id=dlgHelper CLASSID="clsid:3050f819-98b5-11cf-bb82-00aa00bdce0b" width="0px" height="0px"></OBJECT>%CRLF%
Concat>filedata,    <input id=runbutton type="button" value="Run Script" name="run_button" onClick="TestSub">%CRLF%
Concat>filedata,</body>%CRLF%

WriteLn>file1,wres,filedata

BlockInput>1
ExecuteFile>file1

WaitWindowOpen>%file1%*
SetFocus>%file1%*
GetCursorPos>CurX,CurY
MouseMoveRel>60,55
Lclick


GoSub>WinRemove

WaitWindowOpen>Color
SetFocus>Color
MouseMoveRel>30,275
LClick
MouseMove>CurX,CurY
BlockInput>0
DeleteFile>file1
//ExecuteFile>File3

OnEvent>WINDOW_NOTOPEN,Color,1,Finish

Label>Loop
  Wait>0.01
Goto>Loop

SRT>Finish
CloseWindow>%file1%*

ReadFile>file2,color1
DeleteFile>file2

Dialog>Dialog3
   Caption=Chosen Color
   Width=330
   Height=100
   Top=CENTER
   Left=CENTER
   Label=msLabel1,10,8
   Label=msLabel2,10,28
   Label=(In Clipboard),10,48
EndDialog>Dialog3

Show>dialog3

Let>dialog3.mslabel1=%color1% From HTA
Let>dialog3.mslabel2=%color2% From GetPixelColor>
SetDialogObjectFont>Dialog3,msLabel1,Arial,15,1,%Color1%
SetDialogObjectFont>Dialog3,msLabel2,Arial,15,1,%Color2%
PutClipBoard>%Color2%

Label>Loop2
GetDialogAction>dialog3,res3
If>res3=2,EOF
Wait>0.01
Goto>Loop2
SRT>Finish

Label>EOF


SRT>WinRemove
GetWindowHandle>%file1%*,winhndl

//constants
Let>GWL_EXSTYLE=-20
Let>WS_EX_LAYERED=524288
Let>LWA_ALPHA=2

Let>ByteOpacity=0

//get style attributes of dialog1 window
LibFunc>user32,GetWindowLongA,attribs,winhndl,GWL_EXSTYLE
Let>attribs={%attribs% OR %WS_EX_LAYERED%}

//make dialog1 transparent
LibFunc>user32,SetWindowLongA,swl,winhndl,GWL_EXSTYLE,attribs
LibFunc>user32,SetLayeredWindowAttributes,res,winhndl,0,ByteOpacity,LWA_ALPHA
END>WinRemove

Hope this all makes sense,
Dick

User avatar
JRL
Automation Wizard
Posts: 3497
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Thu Feb 26, 2009 2:12 pm

In light of the impending addition of a color dialog for selecting a debug highlight color. Is there any possibility of adding a color chooser dialog for selecting colors to be used when creating Macro Scheduler dialogs? I've been using a script I created (see above) but it is unreliable. Sometimes I have to open it multiple times before it completes correctly and gives me a color number.

Thanks for listening.
Dick

User avatar
JRL
Automation Wizard
Posts: 3497
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Mon Jan 04, 2010 4:18 am

If you want a utility for picking colors to use in Macro Scheduler try this. It has some issues but I'm tired of working with it. I tried posting the .scp on the forum but the script is too large so I put an executable on SkyDrive.

http://cid-5da075bed03597b4.skydrive.li ... =136826943

Once you start the program, press F1 for help and an explanation of how to use it.


Happy holidays!

User avatar
jpuziano
Automation Wizard
Posts: 1085
Joined: Sat Oct 30, 2004 12:00 am

Post by jpuziano » Mon Jan 04, 2010 11:38 pm

Hi JRL,

Yes it has a few quirks but still works great. So many ways to select or change the color... I like the Range section to the right... and what happens when you hit F1... you have a sense of humor.

Hi Marcus,

If something like this will be incorporated into Macro Scheduler, might I add to the wish list that as we adjust the sliders, the color of the dialog (or whatever object on the dialog we’re choosing a color for) changes too... so that way we can see when its just right and stop there... instead of popping back in and out of a picker, manually changing a number, try again, over and over, etc.

Thanks again for sharing this JRL and all the best in 2010 to you and everyone on the forums.
jpuziano

Note: If anyone else on the planet would find the following useful...
[Open] PlayWav command that plays from embedded script data
...then please add your thoughts/support at the above post - :-)

User avatar
Rain
Automation Wizard
Posts: 550
Joined: Tue Aug 09, 2005 5:02 pm
Contact:

Post by Rain » Sun Jun 09, 2013 5:20 pm

Hey JRL,
I think I found a more reliable way. I made some tweaks to the HTA code that eliminates a good chunk of your original code.

Code: Select all


Dialog>Dialog1
object Dialog1: TForm
  Left = 247
  Top = 96
  HelpContext = 5000
  BorderIcons = [biSystemMenu]
  Caption = 'CustomDialog'
  ClientHeight = 212
  ClientWidth = 431
  Color = clWhite
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = True
  ShowHint = True
  OnTaskBar = False
  PixelsPerInch = 96
  TextHeight = 13
  object MSButton1: tMSButton
    Left = 8
    Top = 8
    Width = 89
    Height = 25
    Caption = 'Change Color'
    TabOrder = 0
    DoBrowse = False
    BrowseStyle = fbOpen
  end
  object Edit1: TEdit
    Left = 8
    Top = 40
    Width = 185
    Height = 28
    Font.Charset = DEFAULT_CHARSET
    Font.Color = clWindowText
    Font.Height = -16
    Font.Name = 'MS Sans Serif'
    Font.Style = [fsBold]
    ParentFont = False
    TabOrder = 9
    Text = 'Color: 16777215'
  end
  object Edit2: TEdit
    Left = 8
    Top = 72
    Width = 185
    Height = 28
    Font.Charset = DEFAULT_CHARSET
    Font.Color = clWindowText
    Font.Height = -16
    Font.Name = 'MS Sans Serif'
    Font.Style = [fsBold]
    ParentFont = False
    TabOrder = 10
    Text = 'RBG: 255,255,255'
  end
end
EndDialog>Dialog1

AddDialogHandler>Dialog1,MSButton1,OnClick,PickColor
Show>Dialog1,

SRT>PickColor
DeleteFile>%TEMP_DIR%temp_color_picker.hta
Let>HTAData=<script>window.resizeTo(1, 1);window.moveTo(-1000, -1000);</script>
Concat>HTAData,%CRLF%<head><title>Color Picker</title>
Concat>HTAData,%CRLF%<HTA:APPLICATION ID="oHTA" APPLICATIONNAME="Color Picker" showInTaskbar="no" scroll="no" innerborder="no"/>
Concat>HTAData,%CRLF%<SCRIPT LANGUAGE="VBScript">
Concat>HTAData,%CRLF%    Sub Window_onLoad
Concat>HTAData,%CRLF%    dim odiv, oobjtag
Concat>HTAData,%CRLF%    set odiv=document.createElement("div")
Concat>HTAData,%CRLF%    with odiv
Concat>HTAData,%CRLF%        .id="divid"
Concat>HTAData,%CRLF%    end with
Concat>HTAData,%CRLF%    document.body.appendChild odiv
Concat>HTAData,%CRLF%    set oobjtag=document.createElement("object")
Concat>HTAData,%CRLF%    with oobjtag
Concat>HTAData,%CRLF%        .id="dlg"
Concat>HTAData,%CRLF%        .classid="clsid:3050f819-98b5-11cf-bb82-00aa00bdce0b"
Concat>HTAData,%CRLF%    end with
Concat>HTAData,%CRLF%    document.getElementById("divid").appendChild oobjtag
Concat>HTAData,%CRLF%    intColor =document.getElementById("dlg").choosecolordlg
Concat>HTAData,%CRLF%    Set fso = CreateObject("Scripting.FileSystemObject")
Concat>HTAData,%CRLF%    Set fl = fso.OpenTextFile("%TEMP_DIR%color.txt", 2, True)
Concat>HTAData,%CRLF%    fl.Write intColor
Concat>HTAData,%CRLF%    fl.Close : Set fl = Nothing
Concat>HTAData,%CRLF%    Set fso = Nothing
Concat>HTAData,%CRLF%    window.Close()
Concat>HTAData,%CRLF%    End Sub
Concat>HTAData,%CRLF%</SCRIPT>
Concat>HTAData,%CRLF%</head>

WriteLn>%TEMP_DIR%temp_color_picker.hta,res,%HTAData%
ExecuteFile>%TEMP_DIR%temp_color_picker.hta
WaitWindowOpen>Color
WaitWindowClosed>Color
ReadLn>%TEMP_DIR%color.txt,1,SelectedColor
Let>SelectedColor2={%SelectedColor% MOD 16}
Let>SelectedColor3={(%SelectedColor%-%SelectedColor2%)/16}
Let>SelectedColor4={%SelectedColor3% MOD 16}
Let>red={%SelectedColor2%+(%SelectedColor4%*16)}
Let>SelectedColor5={(%SelectedColor3%-%SelectedColor4%)/16}
Let>SelectedColor6={%SelectedColor5% MOD 16}
Let>SelectedColor7={(%SelectedColor5%-%SelectedColor6%)/16}
Let>SelectedColor8={%SelectedColor7% MOD 16}
Let>green={%SelectedColor6%+(%SelectedColor8%*16)}
Let>SelectedColor9={(%SelectedColor7%-%SelectedColor8%)/16}
Let>SelectedColor10={%SelectedColor9% MOD 16}
Let>SelectedColor11={(%SelectedColor9%-%SelectedColor10%)/16}
Let>SelectedColor12={%SelectedColor11% MOD 16}
Let>blue={%SelectedColor10%+(%SelectedColor12%*16)}
RGB>%blue%,%green%,%red%,PickedColor

SetDialogProperty>Dialog1,Edit1,Text,Color: %PickedColor%
SetDialogProperty>Dialog1,Edit2,Text,RGB: %blue%,%green%,%red%
SetDialogProperty>Dialog1,,Color,%PickedColor%
END>PickColor

User avatar
Marcus Tettmar
Site Admin
Posts: 7378
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Mon Jun 10, 2013 9:03 am

Try this:

1. Under Cursor Monitor, select "Follow Cursor"
2. Point at colour you want
3. Click Left and Right mouse buttons together
4. You'll see the yellow monitor say "Copied!"
5. Go back to the editor and Paste (Edit/Paste or CTRL-V)
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

User avatar
CyberCitizen
Automation Wizard
Posts: 721
Joined: Sun Jun 20, 2004 7:06 am
Location: Adelaide, South Australia

Post by CyberCitizen » Tue Jun 11, 2013 3:25 am

Marcus Tettmar wrote:Try this:

1. Under Cursor Monitor, select "Follow Cursor"
2. Point at colour you want
3. Click Left and Right mouse buttons together
4. You'll see the yellow monitor say "Copied!"
5. Go back to the editor and Paste (Edit/Paste or CTRL-V)
That Copies The Position Of The Mouse Cursor, Not The Color Its Over Unless I Am Missing Something.

Image
FIREFIGHTER

User avatar
JRL
Automation Wizard
Posts: 3497
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Tue Jun 11, 2013 4:06 am

Before you pick Tools > Cursor Monitor. Pick the arrow next to the cursor monitor that is already running at the top of the editor window ( I believe its the arrow in the top right of your posted animated GIF) . You'll see a menu that has:

Relative
Follow Cursor
Pixel Color

Select "Pixel Color". The color number will then be included in the paste.

armsys
Automation Wizard
Posts: 1108
Joined: Wed Dec 04, 2002 10:28 am
Location: Hong Kong

Post by armsys » Tue Jun 11, 2013 4:13 am

Hi CyberCitizen,
How do you create the .gif animation?
CyberCitizen wrote:Image

User avatar
CyberCitizen
Automation Wizard
Posts: 721
Joined: Sun Jun 20, 2004 7:06 am
Location: Adelaide, South Australia

Post by CyberCitizen » Tue Jun 11, 2013 4:38 am

JRL wrote:Before you pick Tools > Cursor Monitor. Pick the arrow next to the cursor monitor that is already running at the top of the editor window (I believe its the arrow in the top right of your posted animated GIF) . You'll see a menu.
Thanks JRL,

I Can't Believe I Missed That. Thanks For That & Thanks Marcus For That Handy Tip.
armsys wrote:Hi CyberCitizen,
How do you create the .gif animation?
It Was A Tool Suggested By Phil Pendlebury. The Program Is Called LiceCap. I Created A Portable Version Of It & Have It On My Hard Drive Useful For Recording Small Issues.
FIREFIGHTER

User avatar
JRL
Automation Wizard
Posts: 3497
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Tue Jun 11, 2013 4:50 am

@Rain
Oops. Didn't read up far enough. Nice update. though Marcus' editor pixel color picker is convenient, it still has the limitation that you can only select colors that exist on the screen. Very handy if you are scripting a process that is displayed while you are creating the script. Not so handy if you are creating a dialog and want just the right color for a background.

@armsys
How did you reference Cy's GIF?

@CyberCitizen
You're welcome.

User avatar
CyberCitizen
Automation Wizard
Posts: 721
Joined: Sun Jun 20, 2004 7:06 am
Location: Adelaide, South Australia

Post by CyberCitizen » Tue Jun 11, 2013 4:53 am

JRL wrote:How did you reference Cy's GIF?
He just quoted it.
FIREFIGHTER

armsys
Automation Wizard
Posts: 1108
Joined: Wed Dec 04, 2002 10:28 am
Location: Hong Kong

Post by armsys » Tue Jun 11, 2013 6:38 am

Hi CyberCitizen,
CyberCitizen wrote:It Was A Tool Suggested By Phil Pendlebury. The Program Is Called LiceCap. I Created A Portable Version Of It & Have It On My Hard Drive Useful For Recording Small Issues.
Thanks for your useful tips. It works brilliantly.
Image

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts