.NET

Reply
Valued Contributor
kevinsir
Posts: 78
Registered: ‎08-20-2012
Message 1 of 6 (448 Views)

How Can I change the document window title?

448 Views, 5 Replies
07-07-2013 12:25 AM

I set the document.window.text="aa" what i want 

However, when the state of  window the window is changed the text is reover to the document full name

Who can help me?

I also use the AcadDocument WindowChanged event,but it is not use.

Valued Contributor
kevinsir
Posts: 78
Registered: ‎08-20-2012
Message 2 of 6 (443 Views)

Re: How Can I change the document window title?

07-07-2013 12:27 AM in reply to: kevinsir

I use AutoCAD2008

Valued Contributor
kevinsir
Posts: 78
Registered: ‎08-20-2012
Message 3 of 6 (374 Views)

Re: How Can I change the document window title?

07-08-2013 09:57 PM in reply to: kevinsir

Omm,has anyone?

*Expert Elite*
norman.yuan
Posts: 1,049
Registered: ‎04-27-2009
Message 4 of 6 (353 Views)

Re: How Can I change the document window title?

07-09-2013 09:17 AM in reply to: kevinsir

I have to say that I am not fan of changing drawing window's text (title), which only seeable when drawing window is not maximized.

 

With latest AutoCAD the drawing window is now tabbed, which makes it a lot easier to switch between drawings, which in turn makes it even likely user always leaves drawing window maxmized. In this case, whatever doucment window text you set simply does not show as the drawing window tabs' text also remains as drawing name. So, what is the point to set custom document window text? Also, when whatever you set the AutoCAD's main Window's text, AutoCAD always append active drawing's name (or full path) to the custom Window text.

 

However, if you insist doing it, then it can be done in good or ugly way. For good way, you probably have to catch Windows message via Windows API. For a ugly way, I managed doing in with AutoCAD .NET API only. Here is the code:

 

using System;
using System.Collections.Generic;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.Runtime;

[assembly: ExtensionApplication(typeof(DocWindowText.MyDocWindowText))]

namespace DocWindowText
{
    public class MyDocWindowText : IExtensionApplication
    {
        private static Dictionary<IntPtr, string> _docWiindowTexts =
            new Dictionary<IntPtr, string>();
        private static int i = 0;

        #region IExtensionApplication Members

        public void Initialize()
        {
            DocumentCollection docs = Application.DocumentManager;
            docs.DocumentCreated += docs_DocumentCreated;
            docs.DocumentToBeDestroyed += docs_DocumentToBeDestroyed;
            docs.DocumentActivated += docs_DocumentActivated;

            docs.MdiActiveDocument.Editor.WriteMessage(
                "\nDocument window text updating tool initialised.");

            SetWindowText();
            Application.MainWindow.Text = 
                _docWiindowTexts[docs.MdiActiveDocument.Window.Handle];
        }

        void docs_DocumentActivationChanged(
            object sender, DocumentActivationChangedEventArgs e)
        {
            SetWindowText();
        }

        void docs_DocumentActivated(
            object sender, DocumentCollectionEventArgs e)
        {
            SetWindowText();
            Application.MainWindow.Text = 
                _docWiindowTexts[e.Document.Window.Handle];
        }

        void docs_DocumentToBeDestroyed(
            object sender, DocumentCollectionEventArgs e)
        {
            e.Document.ViewChanged -= Document_ViewChanged;

            if (_docWiindowTexts.ContainsKey(e.Document.Window.Handle))
            {
                _docWiindowTexts.Remove(e.Document.Window.Handle);
            }
        }

        void docs_DocumentCreated(
            object sender, DocumentCollectionEventArgs e)
        {
            SetWindowText();
            e.Document.ViewChanged += Document_ViewChanged;

        }

        void Document_ViewChanged(object sender, EventArgs e)
        {
            SetWindowText();
        }

        public void Terminate()
        {

        }

        #endregion

        private void SetWindowText()
        {
            foreach (Document doc in Application.DocumentManager)
            {
                if (_docWiindowTexts.ContainsKey(doc.Window.Handle))
                {
                    doc.Window.Text = _docWiindowTexts[doc.Window.Handle];
                }
                else
                {
                    i++;
                    string text = "My Drawing Window " + i.ToString();
                    doc.Window.Text = text;
                    _docWiindowTexts.Add(doc.Window.Handle, text);
                }
            }
        }
    }
}

 

 

I say it is ugly, because when you click different document window to switch active document, you can see the window text set back to document name by AutoCAD first, then the code set it back to the custom text. This code also updated document window's text when window is resized, moved, minimized and restored back.

 

See attached picture:

 

AcadWintext.png

 

 

Valued Contributor
kevinsir
Posts: 78
Registered: ‎08-20-2012
Message 5 of 6 (335 Views)

Re: How Can I change the document window title?

07-09-2013 07:00 PM in reply to: norman.yuan

Thanks for your repy!I will try it!

Valued Contributor
kevinsir
Posts: 78
Registered: ‎08-20-2012
Message 6 of 6 (324 Views)

Re: How Can I change the document window title?

07-10-2013 04:40 AM in reply to: norman.yuan

I am sorry I use CAD2008, have not found the viewChange event.

I use Document.Window.Text Property to set the window title.

I also use .net api to change the windows text.

[DllImport("user32", EntryPoint = "SetWindowText")]

public static extern int SetWindowTextA(int hwnd, string lpString);

However, the problom is when to set the title of the document window. I use the WindowChanged event of AcadDocument to set the Document.Window.Text Property .In the event it is all right, and the Document.Window.Text is set to what i want. However when out the event , i turn to the AutoCAD UI, the title is set to document name automaticly which was not i want.

I am so confuse. and wish someone can help me!

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Are You Going To Be @ AU 2014? Feel free to drop by our AU topic post and share your plans, plug a class that you're teaching, or simply check out who else from the community might be in attendance. Ohh and don't forgot to stop by the Autodesk Help | Learn | Collaborate booths in the Exhibit Hall and meet our community team if you get a chance!