Yes ! I got it running

This is what I've done :
On MyInitControl I initialise RangeStar :
void myInitControl()
{
RangeStart = GetMenuRange( 1 );
}
On MyPostInit I call a thread that will search for MAch3 windows while mach3 is loading. When mach3 is found, it add the menu item :
void myPostInitControl()
{
AfxBeginThread(ProcessFindMach3, NULL);
}
The code for my thred is :
UINT ProcessFindMach3(LPVOID param)
{
do {
EnumWindows(EnumWindowsProc2, NULL);
}while(mach3Wnd==NULL);
mach3CWnd.Attach(mach3Wnd);
dlg = new CProbeDlg;
dlg->Create(IDD_DIALOG_CONFIG,&mach3CWnd);
static bool menued = false;
if( !menued)
{
//" Startup of Menu handler"
menued = true;
if (mach3Wnd != NULL)
{
CMenu *menu = mach3CWnd.GetMenu();
HMENU hSubmenu = CreatePopupMenu();
int pos = FindMenuItem3(menu,"PlugIn Control");
//here we can add menu items to MAch3's menu..
int x = pos;
HMENU control = GetSubMenu( menu->m_hMenu, pos);
InsertMenu ( control, -1, MF_BYPOSITION, RangeStart , _T("Probe") );
mach3CWnd.DrawMenuBar();
}
}
return 1;
}
My Callback routine :
BOOL CALLBACK EnumWindowsProc2(HWND hWnd, LPARAM lParam)
{
char String[255];
if (!hWnd)
return TRUE; // Not a window
if (!::IsWindowVisible(hWnd))
return TRUE; // Not visible
if (!SendMessage(hWnd, WM_GETTEXT, sizeof(String), (LPARAM)String))
return TRUE; // No window title
GetWindowText(hWnd,String,0);
CString toto(String);
if (toto.Find("Mach3 CNC",0) !=-1)
{
mach3Wnd=hWnd;
return 1;
}
return TRUE;
}
And FinWindow :
int FindMenuItem3(CMenu* Menu, LPCTSTR MenuString)
{
ASSERT(Menu);
ASSERT(::IsMenu(Menu->GetSafeHmenu()));
int count = Menu->GetMenuItemCount();
for (int i = 0; i < count; i++)
{
CString str;
if (Menu->GetMenuString(i, str, MF_BYPOSITION) &&
(strcmp(str, MenuString) == 0))
return i;
}
return -1;
}
I have also Add the notify routine ion my .cpp:
extern void myNotify(int ID);
extern "C" __declspec(dllexport) void Notify(int ID)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
myNotify(ID);
//Called when reset is pressed, at end of actual reset commend in Mach3.
//Check the Engine.Estop variable to see if we have reset or not..
}
And in MyNotify I got the message ID when I click on menu item, so I call My Plugin :
void myNotify(int ID)
{
if (ID == RangeStar)
{
....
}
}