Subscribe Bookmark RSS Feed

Open color selection window by script / use Windows choosecolor dll

cis_pete

Community Trekker

Joined:

Jan 26, 2015

I would like to have the JMP color selection window to be opened by script. The color that is selected by the user should be returned (RGB-values).

So I would like to open these windows by script:

10628_pastedImage_0.png10629_pastedImage_1.png

Is this possible? So far I did not find a way to do it (with JMP 12.1).

So I thought you could use a Windows dll. My problem is that I have no clue about how to use dlls ...

With the JMP scripting guide and syntax reference book and the internet pages mentioned below I created the following code:

/*

user32 = Load Dll( "User32" );

user32 << DeclareFunction(

    "FindWindowA",

    Convention( STDCALL ),

    Alias( "FindWindow2" ),

    Arg( UInt32, input, "lpClassName" ),

    Arg( AnsiString( 200 ), input, "lpCaption" ),

    Returns( UIntPtr )

);

lpCaption = "Script - JMP";

hWnd = user32 << FindWindow2( 0, lpCaption );

user32 << UnloadDLL();

*/

dll = LoadDLL("C:\Windows\System32\comdlg32.dll");

dll << Declare Function(

    "ChooseColorA",

    Convention(STDCALL),

    Alias("ColorPalette"),

    StructArg(

        Arg(UInt32, "lStructSize"),

        Arg(Int64, "hwndOwner"),

        Arg(Int64, "hInstance"),

        Arg(UInt32, update, "rgbResult"),

        Arg(AnsiString, "lpCustColors"),

        Arg(UInt32, "Flags"),

        Arg(Int64, "lCustData"),

        Arg(Int64, "lpfnHook"),

        Arg(AnsiString, "lpTemplateName"),

        update

    ),

    Returns(Int8)

);

selected_color = 5;

hwnd = 0;

size = 36    ;

result = dll << ColorPalette(

    size,        // lStructSize

    hwnd,        // hwndOwner

    0,            // hInstance

    selected_color,    // rgbResult

    "",            // lpCustColors

    2,            // flags;    2 = show all colors

    0,            // lCustData

    0,            // lpfnHook

    ""            // lpTemplateName

);

show(result);

dll << UnloadDLL();

This code is not working, the color selection window is not displayed but the result from the call of the ColorPalette function is always zero.

I think one problem is that I don't know the correct value for 'lStructSize'. I tried every value from 1 to 10000 without any change. So obviously there are more errors in my code (as I said, I have no idea how to use dlls).

Can anybode help?

Here are some (maybe helpful) links:

https://msdn.microsoft.com/en-us/library/ms646912%28v=vs.85%29.aspx

https://msdn.microsoft.com/en-us/library/ms646829%28v=vs.85%29.aspx#choosing_color

https://msdn.microsoft.com/de-de/library/windows/desktop/ms646830%28v=vs.85%29.aspx

And here is some VBA code that works in MS Excel (slightly modified code I found in the internet). I tried to do it in JMP similarly.

Option Explicit

Private Type CHOOSECOLOR

    lStructSize As Long

    hwndOwner As Long

    hInstance As Long

    rgbResult As Long

    lpCustColors As String

    flags As Long

    lCustData As Long

    lpfnHook As Long

    lpTemplateName As String

End Type

Private Declare PtrSafe Function ChooseColorAPI Lib "comdlg32.dll" Alias _

"ChooseColorA" (pChoosecolor As CHOOSECOLOR) As Long

Dim CustomColors() As Byte

Sub test()

    Form_Load

   

    Dim cc As CHOOSECOLOR

    Dim Custcolor(16) As Long

    Dim lReturn As Long

    cc.lStructSize = Len(cc)

    'Debug.Print cc.lStructSize

    cc.hwndOwner = Application.Hwnd

    cc.hwndOwner = 0

    cc.hInstance = 0

    cc.lpCustColors = StrConv(CustomColors, vbUnicode)

    'cc.flags = 0

    cc.flags = 2     ' all colors

    'cc.flags = CC_FULLOPEN

    lReturn = ChooseColorAPI(cc)

    If lReturn <> 0 Then

        Dim Farbe, Rot, Gruen, Blau As Long

        Farbe = cc.rgbResult

        Rot = Farbe Mod 256

        Farbe = (Farbe - Rot) / 256

        Gruen = Farbe Mod 256

        Farbe = (Farbe - Gruen) / 256

        Blau = Farbe Mod 256

        MsgBox "Color: " & cc.rgbResult & vbNewLine & "Rot: " & Rot & vbNewLine & "Grün: " & Gruen & vbNewLine & "Blau: " & Blau

        CustomColors = StrConv(cc.lpCustColors, vbFromUnicode)

    Else

        MsgBox "User chose the Cancel Button"

    End If

End Sub

Sub Form_Load()

    ReDim CustomColors(0 To 16 * 4 - 1) As Byte

    Dim i As Integer

   

    For i = LBound(CustomColors) To UBound(CustomColors)

        CustomColors(i) = 0

    Next i

End Sub