.NET

Reply
Active Member
Mikanikal
Posts: 6
Registered: ‎10-11-2010
Message 11 of 14 (241 Views)

Re: Setting focus back to AutoCAD

08-15-2013 01:18 PM in reply to: jaboone

I haven't looked into the possibility to doing this through AutoCAD api but you could test using a Win32 API call.

 

This is one of the options posted in arcticad's reply. This just shows you which AutoCAD property to use. This is untested fyi.

 

Declare Auto Funtion SetForeGroundWindow Lib "User32.dll"(ByVal Hwnd As IntPtr) As Long

'Call these API's through your code

SetForeGroundWindow(Autodesk.AutoCAD.ApplicationServices.Application.MainWindow.Handle)

 

ADN Support Specialist
Balaji_Ram
Posts: 702
Registered: ‎03-21-2011
Message 12 of 14 (207 Views)

Re: Setting focus back to AutoCAD

08-21-2013 06:49 AM in reply to: cjacobi

Another option that works in AutoCAD 2014 :

 

http://adndevblog.typepad.com/autocad/2013/03/use-of-windowfocus-in-autocad-2014.html



Balaji
Developer Technical Services
Autodesk Developer Network

Valued Contributor
cjacobi
Posts: 54
Registered: ‎11-12-2012
Message 13 of 14 (168 Views)

Re: Setting focus back to AutoCAD

10-31-2013 05:59 AM in reply to: Balaji_Ram

I had to set this aside for a bit....I am only a part time programmer. Soooo, I had some time to try the last suggestion. I am working in VB not C# so I converted the code but get an error on the "Dynamic" type.

 

Dim acaddoc As Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument
        Dim ed As Editor = acaddoc.Editor
        Dim acadDocObj As Dynamic = acaddoc.GetAcadDocument()

 My code does not like the Dynamic object???? I am running VS2010 with AutoCAD2014.

 

Any suggestions on what I'm doing wrong?

 

thanks

 

cj

Valued Contributor
cjacobi
Posts: 54
Registered: ‎11-12-2012
Message 14 of 14 (154 Views)

Re: Setting focus back to AutoCAD

10-31-2013 08:18 AM in reply to: cjacobi

Well I tried something different and got an appropriate solution. I added the following before my MsgBox.

Excel now minimizes and then Autocad is the main visible application showing my message to the user.

 

Not sure why I didn't find this earlier but sometime a step away brings new ideas when you return.

 

thanks to everyone who provided responses.

 

cj

 

myExcel.WindowState = Microsoft.Office.Interop.Excel.XlWindowState.xlMinimized

 

Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.