Disable Close option on DocumentWindow

Disable Close option on DocumentWindow

Anonymous
Not applicable
1,129 Views
1 Reply
Message 1 of 2

Disable Close option on DocumentWindow

Anonymous
Not applicable

Hi,

I have a requirement to add a custom start page when Autocad and plant 3D 2018  is opened. I get to know that there is no any API to alter existing start page so i added new page.  i'm using below code to do that

 

Application.DocumentWindowCollection.AddDocumentWindow("CADSupportForum", New Uri(url))

 

It is now serving my purpose, but anyone can close it. I want that close X button should be disabled for this document so that no one close it just like existing default start tab in AutoCAD. See the attachment for better understating.

 

Above code return  "DocumentWindow" and it has "CanClose" property but unfortunately it is ReadOnly , so i can not make it false.

 

 

I got a suggestion from AutoCAD customization group to use FILETABCLOSE command, but i don't know how to use it in dot .net code and read about it and i think it won't solve my problem.

 

Can you please suggest some way and share some sample code to achieve that.

 

0 Likes
1,130 Views
1 Reply
Reply (1)
Message 2 of 2

norman.yuan
Mentor
Mentor

Since the API only expose "CanClose" as read-only, and there is no event exposed where you can handle and cancel the closing, I do not think you can prevent user to close the custom document window. Further more, if I am the user, I'd much prefer the window can be closed.

 

With that said, technically there may be a very annoying way to get your custom window open again automatically after being close by user:

 

You can use a WpfDocumentWindow, which is derived from DocumentWindow, and override its OnDestroy method, so that once the custom window is closed, your code in this overriden OnDestroy() could try to recreate/reopen the window again. As I said, this way would be very annoying, and may "teach user" not to close your custom DocumentWindow. And again, I am not a fan to have a DocumwntWidnow I cannot close. I did a WpfDocumentWindow development, and did know there is OnDestroy() virtual method one can override. You may not want to directly reopen the window in OnDestroy(), rather, you can have a Window creating class that can hook up AutoCAD's Idle event, and once the window is closed and AutoCAD is idle, the custom window would open again.

 

Even it is doable, it is really bad idea, and user would really hate it and I'd absolutely not do it. Just from technical point of view, with existing available API, it may be possible to do.

Norman Yuan

Drive CAD With Code

EESignature

0 Likes