|
//-----------------------------------------------------------------------------
//----- acrxEntryPoint.cpp
//-----------------------------------------------------------------------------
#include "StdAfx.h"
#include "resource.h"
//-----------------------------------------------------------------------------
#define szRDS _RXST("")
//globals
WNDPROC gWndProc;
//new window procedure
LRESULT CALLBACK myWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
if (uMsg == WM_COPYDATA) {
::MessageBox(NULL, L"WM_COPYDATA received!!!", L"Alert", MB_OK);
}
return ::CallWindowProc(gWndProc, hwnd, uMsg, wParam, lParam);
}
//-----------------------------------------------------------------------------
//----- ObjectARX EntryPoint
class CSend_WM_COPYDATAApp : public AcRxArxApp {
public:
CSend_WM_COPYDATAApp() : AcRxArxApp() {}
virtual AcRx::AppRetCode On_kInitAppMsg(void* pkt) {
AcRx::AppRetCode retCode = AcRxArxApp::On_kInitAppMsg(pkt);
AddWinHook();
return (retCode);
}
virtual AcRx::AppRetCode On_kUnloadAppMsg(void* pkt) {
RemoveWinHook();
AcRx::AppRetCode retCode = AcRxArxApp::On_kUnloadAppMsg(pkt);
return (retCode);
}
//subclassing the AutoCAD Main frame
void AddWinHook()
{
gWndProc = (WNDPROC)::SetWindowLongPtr(adsw_acadMainWnd(), GWLP_WNDPROC, (LONG_PTR)myWndProc);
}
//unload windows hook
void RemoveWinHook()
{
//restore the old winproc address
gWndProc = (WNDPROC)::SetWindowLongPtr(adsw_acadMainWnd(), GWLP_WNDPROC, (LONG_PTR)gWndProc);
}
virtual void RegisterServerComponents() { }
static void MyGroupMyTest() {
ACHAR *s = L"(alert \"Hello from WM_COPYDATA\")\n";
SendCmdToAcad(s);
}
static void SendCmdToAcad(const ACHAR* cmd)
{
COPYDATASTRUCT cmdMsg;
cmdMsg.dwData = (DWORD)1;
cmdMsg.cbData = (DWORD)(_tcslen(cmd) + 1) * sizeof(ACHAR);
cmdMsg.lpData = (void *)cmd;
SendMessage(adsw_acadMainWnd(), WM_COPYDATA, NULL, (LPARAM)&cmdMsg);
}
};
//-----------------------------------------------------------------------------
IMPLEMENT_ARX_ENTRYPOINT(CSend_WM_COPYDATAApp)
ACED_ARXCOMMAND_ENTRY_AUTO(CSend_WM_COPYDATAApp, MyGroup, MyTest, MyTest, ACRX_CMD_MODAL, NULL)[code]https://forums.autodesk.com/t5/objectarx/sending-wm-copydata-message-from-outside-autocad/m-p/9806250[/code] |
|