<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />JMPカラー選択ウィンドウをスクリプトで開きたいと思います。ユーザーが選択した色が返されるはずです(RGB値)。
だから私はスクリプトでこれらのウィンドウを開きたいと思います:


これは可能ですか?これまでのところ(JMP 12.1では)その方法が見つかりませんでした。
だから私はあなたがWindowsのdllを使うことができると思った。私の問題は、私はDLLを使用する方法についての手がかりがないということです...
JMPスクリプトガイドと構文リファレンスブック、および下記のインターネットページを使用して、次のコードを作成しました。
/*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();このコードは機能していません、色選択ウィンドウは表示されませんが、ColorPalette関数の呼び出しの結果は常にゼロです。
問題の1つは、「lStructSize」の正しい値がわからないことです。私は1から10000までのすべての値を変更せずに試しました。だから私のコードには間違いなくもっと多くのエラーがあります(私が言ったように、私はdllを使う方法がわかりません)。
誰でも助けられますか?
これは(おそらく役に立つ)リンクです:
https://msdn.microsoft.com/ja-jp/library/ms646912%28v=vs.85%29.aspx
https://msdn.microsoft.com/ja-jp/library/ms646829%28v=vs.85%29.aspx#choosing_color
https://msdn.microsoft.com/de-de/library/windows/desktop/ms646830%28v=vs.85%29.aspx
そしてこれがMS Excelで動作するVBAコードです(私がインターネットで見つけたコードを少し修正したものです)。私も同様にJMPでやってみました。
Option ExplicitPrivate 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 StringEnd TypePrivate Declare PtrSafe Function ChooseColorAPI Lib "comdlg32.dll" Alias _"ChooseColorA" (pChoosecolor As CHOOSECOLOR) As LongDim CustomColors() As ByteSub 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 IfEnd SubSub 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 iEnd Sub
私は同じ要求がありました。 ありがとう、あなたのサンプルコード。 私はそれを修正し、JMP 12でテストに合格しました。
これが私のスクリプトです
ChooseColor = Function( {intColor, flags=3},
{Default Local},
If( Host is( Windows ),
dll = Load DLL("C:/Windows/System32/Comdlg32.dll", Quiet );
dll << Declare Function( "ChooseColorW", Convention(STDCALL), Alias("PickColor"),
StructArg(
Arg(Int64, "lStructSize"),
Arg(Int64, "hwndOwner"),
Arg(Int64, "hInstance"),
Arg(Int32, "rgbResult"),
Arg(AnsiString(64), "lpCustColors"),
Arg(Int64, "Flags"),
Arg(Int64, "lCustData"),
Arg(Int64, "lpfnHook"),
Arg(UnicodeString, "lpTemplateName"),
Update,
"CHOOSECOLOR"
),
Returns(Int32)
);
lStructSize = 72;
hwndOwner = 0;
lstRGB = As List( ( Matrix( Color To RGB(intColor) ) * 255 ) );
hexRGB = Concat(Substr(Hex(lstRGB[3], "integer"),7,2), Substr(Hex(lstRGB[2], "integer"),7,2), Substr(Hex(lstRGB[1], "integer"), 7,2));
rgbResult = Hex to Number( hexRGB );
lpCustColors = Repeat(Hex To Char( "FFFFFF00" ), 16);
lCustData = 0;
lpfnHook = 0;
intRc = dll << PickColor(lStructSize, 0, 0, rgbResult, lpCustColors, Flags,0,0,"");
If(intRC == 0,
Return(intColor)
,
hexRGB = Hex(rgbResult, "integer");
Return( RGB Color( Hex to Number(Substr(hexRGB,7,2)), Hex to Number(Substr(hexRGB,5,2)), Hex to Number(Substr(hexRGB,3,2) ) ) );
);
dll << Unload DLL();
);
);