Notifications
Clear all
[Closed] Getting/Setting the Max Color copy/paste values
Apr 16, 2018 8:40 pm
Does anyone know if it’s possible to get/set the color value from when you right-click on a colorpicker control?
3 Replies
Apr 16, 2018 8:40 pm
do you mean – is it possible to get/set color clipboard used with the colorpicker?
1 Reply
Apr 16, 2018 8:40 pm
I’ve managed to do it only this ugly way.
(
(
local source = ""
source = "using System;
"
source += "using System.Runtime.InteropServices;
"
source += "
"
source += "namespace WinAPI
"
source += "{
"
source += "class PInvoke
"
source += "{
"
source += "[DllImport(\"user32.dll\")]
"
source += "public static extern IntPtr WindowFromPoint(System.Drawing.Point p);
"
source += "}
"
source += "}
"
csharpProvider = dotnetobject "Microsoft.CSharp.CSharpCodeProvider"
compilerParams = dotnetobject "System.CodeDom.Compiler.CompilerParameters"
compilerParams.ReferencedAssemblies.Add("System.dll");
compilerParams.ReferencedAssemblies.Add("System.Drawing.dll");
compilerParams.GenerateInMemory = on
compilerResults = csharpProvider.CompileAssemblyFromSource compilerParams #(source)
global dll = compilerResults.CompiledAssembly.CreateInstance "WinAPI.PInvoke"
)
try (destroydialog X ) catch ()
rollout X "" (
colorPicker cp "color1"
)
createDialog X pos:[100,100]
DialogMonitorOPS.Enabled = false
DialogMonitorOPS.UnRegisterNotification id:#showHWND
fn catchRCMENU = (
local hwnd = DialogMonitorOPS.GetWindowHandle()
if hwnd != undefined do (
local ptr = ::dll.WindowFromPoint (dotnetobject "System.Drawing.Point" (mouse.screenpos.x-1) (mouse.screenpos.y-1))
local data = windows.getHWNDData ptr
if data[4] == "ColorSwatch" do (
global swatch = (dotNetClass "Autodesk.Max.GlobalInterface").Instance.GetIColorSwatch (dotNetObject "System.IntPtr" ptr)
DialogMonitorOPS.Enabled = false
DialogMonitorOPS.UnRegisterNotification id:#showHWND
swatch.SetColor ((dotnetclass "System.Drawing.Color").fromArgb 255 128 64) 0
format " Acolor: [%,%,%]
" swatch.aColor.r swatch.aColor.g swatch.aColor.b
format "system.drawing.color: [%,%,%]
" swatch.Color.r swatch.Color.g swatch.Color.b -- [B,G,R] ??
)
)
true
)
DialogMonitorOPS.Enabled = true
DialogMonitorOPS.RegisterNotification catchRCMENU id:#showHWND
)