In C# is there a way to catch the AutoCAD application window events...?
Im interested in capturing the event that fires when the application window is resized.
Any and all help appreciated.
(C# / AutoCAD 2011/12)
|
In C# is there a way to catch the AutoCAD application window events...?
Im interested in capturing the event that fires when the application window is resized.
Any and all help appreciated.
(C# / AutoCAD 2011/12)
I've found a way to catch these events but now have a minor problem to solve. The code below only returns the first running version of the AutoCAD application and I would like to have more than one instance of AutoCAD running...
So, the ideal solution would be to get the AutoCAD application object from the .net dll that’s running.... Is there a way to do this??
OR does anyone know how to get the processid or something that uniquely identifies the AutoCAD application object that is currently running the .net DLL??
Code://Obtain AutoCAD application acApp = (AcadApplication)Marshal.GetActiveObject(progID); //Register WindowMovedOrResized event handler acApp.WindowMovedOrResized += new _DAcadApplicationEvents_WindowMovedOrResizedEventHandler (acApp_WindowMovedOrResized); //Register WindowChanged event handler acApp.WindowChanged += new _DAcadApplicationEvents_WindowChangedEventHandler (acApp_WindowChanged); //WindowChanged Event Handler void acApp_WindowChanged(AcWindowState WindowState){ //react to window state change } //WindowMovedOrResized Event Handler void acApp_WindowMovedOrResized(int HWNDFrame, bool bMoved){ //react to move or resize } //Make sure event handlers are removed. acApp.WindowMovedOrResized -= new _DAcadApplicationEvents_WindowMovedOrResizedEventHandler (acApp_WindowMovedOrResized); acApp.WindowChanged -= new _DAcadApplicationEvents_WindowChangedEventHandler (acApp_WindowChanged);
(NOTE the code is incomplete and needs 'fleshing out' with the using directives etc. so you can't just cut and paste it into a new project... I’ve built a little demo of it working and will post if anyone is interested.)
If you get the app object by class id, then its going to be generic and pointing to the current instance. Use the current instance's Application object. Here it is in vb. AcadApplication is the COM Interop version of the .net app.
Dim app As AcadApplication = Autodesk.AutoCAD.ApplicationServices.Application.AcadApplication
Last edited by Ed Jobe; 2011-11-17 at 10:34 PM.
Thanks for the reply Ed.
Modified the code to your suggestion - solves the issue for multiple AutoCAD sessions.
I have another issue now;
Launch AutoCAD, Netload .DLL, click the 'Restore Down' on the AutoCAD window, the event WindowChanged does not fire... subsequent clicks of 'Maximise','Restore Down' fires the event every time but never the first time. This occurs when the AcadApp window starts in either Max or Restore Down states.....
Any Ideas???
Well it looks like after hours of looking through the object browser I've found a solution and it works flawlessly...
Question is, is this ok to use??
Code:using Autodesk.AutoCAD.Internal.Reactors;Code:ApplicationEventManager cadWinEvnts = Autodesk.AutoCAD.Internal.Reactors.ApplicationEventManager.Instance();Code:cadWinEvnts.ApplicationMainWindowMoved += new ApplicationMainWindowMovedEventHandler(cadWinEvnts_ApplicationMainWindowMoved);Code:void cadWinEvnts_ApplicationMainWindowMoved(object sender, EventArgs e) { //Do Somthing }