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.
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:
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!