This may be a bug of CRhinoGetXform class

Hi;
In my code, when I pick point with left mouse button, I won’t be able to run rhino command by RhinoApp().RunScript(), Is this a bug?

#include "StdAfx.h"
class CDrawStringGetPoint : public CRhinoGetXform
{
public:
	CDrawStringGetPoint() = default;
	BOOL CalculateTransform(CRhinoViewport& vp, const ON_3dPoint& pt, ON_Xform& xform);
	void DynamicDraw(CRhinoDisplayPipeline& dp, const ON_3dPoint& pt) override;
};
BOOL CDrawStringGetPoint::CalculateTransform(CRhinoViewport& vp, const ON_3dPoint& point, ON_Xform& xform)
{
	UNREFERENCED_PARAMETER(vp);
	UNREFERENCED_PARAMETER(point);
	return xform.IsValid() ? TRUE : FALSE;
}
void CDrawStringGetPoint::DynamicDraw(CRhinoDisplayPipeline& dp, const ON_3dPoint& pt)
{
	CRhinoViewport* vp = dp.GetRhinoVP();
	if (nullptr != vp)
	{
		ON_wString str;
		RhinoFormatPoint(pt, str);
		ON_Xform w2s;
		vp->VP().GetXform(ON::world_cs, ON::screen_cs, w2s);
		ON_3dPoint screenpoint = w2s * pt;
		screenpoint.x += 5.0;
		screenpoint.y += -5.0;
		dp.DrawString(str, str.Length(), screenpoint, false, 12, L"System");
	}
	CRhinoGetPoint::DynamicDraw(dp, pt);
}

class CCommandTestAcceptMessage : public CRhinoScriptCommand
{
public:
	CCommandTestAcceptMessage() = default;
	UUID CommandUUID() override
	{
		// {882B8A5B-B20F-46BD-8FC1-3DA306A9B8C2}
		static const GUID TestAcceptMessageCommand_UUID =
		{ 0x882B8A5B, 0xB20F, 0x46BD, { 0x8F, 0xC1, 0x3D, 0xA3, 0x06, 0xA9, 0xB8, 0xC2 } };
		return TestAcceptMessageCommand_UUID;
	}
	const wchar_t* EnglishCommandName() override { return L"TestAcceptMessage"; }
	CRhinoCommand::result RunCommand(const CRhinoCommandContext& context) override;
};

static class CCommandTestAcceptMessage theTestAcceptMessageCommand;
CRhinoCommand::result CCommandTestAcceptMessage::RunCommand(const CRhinoCommandContext& context)
{
	UNREFERENCED_PARAMETER(context);
	CDrawStringGetPoint gp;
	gp.SetCommandPrompt(L"Pick test point");
	gp.AcceptCustomWindowsMessage(0xC000);
	for (;;)
	{
		CRhinoGet::result res = gp.GetPoint(0, true);
		if (gp.CommandResult() != CRhinoCommand::success)
		{
			break;
		}
		else
		{
			if (res == CRhinoGetObject::point)
			{
				char buf[] = "abc";
				gp.PostCustomWindowsMessage(0xC000, (WPARAM)0, (LPARAM)buf);
				continue;
			}
			else if (res == CRhinoGetObject::winmsg)
			{
				MSG msg = gp.WindowsMessage();
				ON_wString Caption = (char*)msg.lParam;
				//RhinoApp().Print(Caption);
				break;
			}
			else
			{
				continue;
			}
		}
	}
	RhinoApp().RunScript(RhinoApp().ActiveDoc()->RuntimeSerialNumber(), L"_Line", true);
	return CRhinoCommand::success;
}

Hi @suc_kiet,

Yeah, that’s not how AcceptCustomWindowsMessage and PostCustomWindowsMessage were designed to be used. Have you reviewed the SDK samples?

SampleModelessCancel

– Dale

Hi @dale ;
Got it, thank you. :smiley: