Author Topic: Change Title Bar Text in AutoCAD 2013 / 2014 Window  (Read 6561 times)

0 Members and 1 Guest are viewing this topic.

ROBBO

  • Bull Frog
  • Posts: 217
Change Title Bar Text in AutoCAD 2013 / 2014 Window
« on: February 24, 2014, 05:06:17 AM »
I tried to create a dll which will change the title bar text in the AutoCAD window using VS 2012 express.

I came across this web page http://adndevblog.typepad.com/autocad/2013/01/changing-the-displayed-autocad-title-bar-text.html , but have not had any success as a beginner in VB.NET.

I would either like to remove the Autodesk... text and perhaps replace with my custom text or company name.

This because of the long pathnames we have these days, and would like to maximise the space in title bar as a fan for displaying the full drawing path.

Any help with this would be much appreciated.

Many thanks in advance, Robbo.
The only thing to do with good advice is to pass it on.
It is never of any use to oneself.

Oscar Wilde
(1854-1900, Irish playwright, poet and writer)

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11653
  • class keyThumper<T>:ILazy<T>
Re: Change Title Bar Text in AutoCAD 2013 / 2014 Window
« Reply #1 on: February 24, 2014, 05:27:56 AM »
Have you tried something like this :
http://adndevblog.typepad.com/autocad/2013/01/changing-the-displayed-autocad-title-bar-text.html?cid=6a0167607c2431970b01a73d7aa899970d

added:
Sorry , just realised this was the reference you posted.

Can you indicate where it errors ?
« Last Edit: February 24, 2014, 05:37:46 AM by Kerry »
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

--> Donate to theSwamp<--

ROBBO

  • Bull Frog
  • Posts: 217
Re: Change Title Bar Text in AutoCAD 2013 / 2014 Window
« Reply #2 on: February 24, 2014, 05:34:50 AM »
Kerry,

Many thanks for your reply. I have but cannot get past the debug. As a beginner not sure how to solve the problem and create the dll.

I have VS 2012 Express installed.

Cheers, Robbo.
The only thing to do with good advice is to pass it on.
It is never of any use to oneself.

Oscar Wilde
(1854-1900, Irish playwright, poet and writer)

BlackBox

  • King Gator
  • Posts: 3743
Re: Change Title Bar Text in AutoCAD 2013 / 2014 Window
« Reply #3 on: February 24, 2014, 02:46:18 PM »
Here's a quick port from VB to C#, that I've just tested in Civil 3D 2014 successfully, and took the liberty of including a LispFunction Method:

Code - C#: [Select]
  1. //
  2. using Autodesk.AutoCAD.ApplicationServices;
  3. using Autodesk.AutoCAD.DatabaseServices;
  4. using Autodesk.AutoCAD.EditorInput;
  5. using Autodesk.AutoCAD.Interop;
  6. using Autodesk.AutoCAD.Runtime;
  7.  
  8. using acApp = Autodesk.AutoCAD.ApplicationServices.Application;
  9.  
  10. using System;
  11. using System.Runtime.InteropServices;
  12.  
  13. [assembly: CommandClass(typeof(BlackBox.AutoCAD.TitleBarText.Commands))]
  14.  
  15. // Inspired by:
  16. // http://www.theswamp.org/index.php?topic=46380.0
  17. // http://adndevblog.typepad.com/autocad/2013/01/changing-the-displayed-autocad-title-bar-text.html?cid=6a0167607c2431970b01a73d7aa899970d
  18.  
  19. namespace BlackBox.AutoCAD.TitleBarText
  20. {
  21.    public class Commands
  22.    {
  23.        //private string progID = "AutoCAD.Application.18"; // 2010
  24.        private string progID = "AutoCAD.Application.19"; // 2013
  25.        private string curTitle = "";
  26.  
  27.        [DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)]
  28.        public static extern long GetActiveWindow();
  29.        [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
  30.        internal static extern long GetWindowText(long hWnd, string lpString, long nMaxCount);
  31.        [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
  32.        public static extern long SetWindowText(long hwnd, String lpString);
  33.        [DllImport("user32.dll", EntryPoint = "FindWindowA", SetLastError = true)]
  34.        static extern long FindWindow(string ZeroOnly, string lpWindowName);
  35.        [CommandMethod("TitleBarText")]
  36.        public void TitleBarText()
  37.        {
  38.            Document doc = acApp.DocumentManager.MdiActiveDocument;
  39.  
  40.            try
  41.            {
  42.                Type acType = Type.GetTypeFromProgID(progID);
  43.  
  44.                AcadApplication acAppCom =
  45.                    acApp.AcadApplication as AcadApplication;
  46.  
  47.                if (acAppCom == null)
  48.                    return;
  49.  
  50.                acAppCom.Visible = true;
  51.  
  52.                System.Threading.Thread.Sleep(2000);
  53.  
  54.                long acadhnd = 0;
  55.                string title = new string(' ', 256);
  56.                acadhnd = GetActiveWindow();
  57.                acadhnd = FindWindow(null, acAppCom.Caption);
  58.                GetWindowText(acadhnd, title, 125);
  59.  
  60.                if (curTitle == "")
  61.                    curTitle = title;
  62.  
  63.                doc.Editor.WriteMessage("\nCurrent Title Bar Text: {0}\n", title);
  64.  
  65.                PromptStringOptions pso =
  66.                    new PromptStringOptions("\nEnter Title Bar Text: ");
  67.                pso.AllowSpaces = true;
  68.  
  69.                PromptResult pr = doc.Editor.GetString(pso);
  70.  
  71.                if (pr.Status != PromptStatus.OK)
  72.                    return;  
  73.  
  74.                SetWindowText(acadhnd, pr.StringResult);
  75.            }
  76.            catch (System.Exception ex)
  77.            {
  78.                doc.Editor.WriteMessage("\n; error: System.Exception: {0}\n", ex.Message);
  79.            }
  80.        }
  81.        [LispFunction("vla-SetTitleBarText")]
  82.        public bool TitleBarText(ResultBuffer resbuf)
  83.        {
  84.            Document doc = acApp.DocumentManager.MdiActiveDocument;
  85.  
  86.            try
  87.            {
  88.                if (resbuf == null)
  89.                    throw new TooFewArgsException();
  90.  
  91.                TypedValue[] args = resbuf.AsArray();
  92.                int i = args.Length;
  93.  
  94.                if (args.Length > 1)
  95.                    throw new TooManyArgsException();
  96.  
  97.                if (args[0].TypeCode != (int)LispDataType.Text)
  98.                    throw new ArgumentTypeException("stringp", args[0]);
  99.  
  100.                Type acType = Type.GetTypeFromProgID(progID);
  101.  
  102.                AcadApplication acAppCom =
  103.                    acApp.AcadApplication as AcadApplication;
  104.  
  105.                if (acAppCom == null)
  106.                    return false;
  107.  
  108.                acAppCom.Visible = true;
  109.  
  110.                System.Threading.Thread.Sleep(2000);
  111.  
  112.                long acadhnd = 0;
  113.                string title = new string(' ', 256);
  114.                acadhnd = GetActiveWindow();
  115.                acadhnd = FindWindow(null, acAppCom.Caption);
  116.                GetWindowText(acadhnd, title, 125);
  117.  
  118.                if (curTitle == "")
  119.                    curTitle = title;
  120.  
  121.                SetWindowText(acadhnd, (string)args[0].Value);
  122.  
  123.                return true;
  124.            }
  125.            catch (System.Exception ex)
  126.            {
  127.                doc.Editor.WriteMessage("\n; error: System.Exception: {0}\n", ex.Message);
  128.  
  129.                return false;
  130.            }
  131.        }
  132.    }
  133.    /// <summary>
  134.    /// Special thanks to Gile for his LispException classes:
  135.    /// </summary>
  136.    class LispException : System.Exception
  137.    {
  138.        public LispException(string msg) : base(msg) { }
  139.    }
  140.    class TooFewArgsException : LispException
  141.    {
  142.        public TooFewArgsException() : base("too few arguments") { }
  143.    }
  144.    class TooManyArgsException : LispException
  145.    {
  146.        public TooManyArgsException() : base("too many arguments") { }
  147.    }
  148.    class ArgumentTypeException : LispException
  149.    {
  150.        public ArgumentTypeException(string s, TypedValue tv)
  151.            : base(string.Format(
  152.           "invalid argument type: {0}: {1}",
  153.           s, tv.TypeCode == (int)LispDataType.Nil ? "nil" : tv.Value))
  154.        { }
  155.    }
  156. }
  157.  
"How we think determines what we do, and what we do determines what we get."

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11653
  • class keyThumper<T>:ILazy<T>
Re: Change Title Bar Text in AutoCAD 2013 / 2014 Window
« Reply #4 on: February 24, 2014, 04:44:58 PM »
Looks like it would work.

casual thought : I wonder if this is available for PInvoke from ARX ??

Personally I'd not use the vla- prefix though ... I can imagine confusion down the road.

Code - C#: [Select]
  1. [LispFunction("vla-SetTitleBarText")]
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

--> Donate to theSwamp<--

BlackBox

  • King Gator
  • Posts: 3743
Re: Change Title Bar Text in AutoCAD 2013 / 2014 Window
« Reply #5 on: February 24, 2014, 05:03:01 PM »
casual thought : I wonder if this is available for PInvoke from ARX ??

Interesting idea; no time to test now, but had these 2014 mangled names handy before closing up:

Code - C#: [Select]
  1.  
  2. ?SetWindowTextW@CIPEToolBarEdit@@QEAAXPEB_W@Z
  3.  
  4. ?acedGetAcadFrame@@YAPEAVCMDIFrameWnd@@XZ
  5.  
  6.  
"How we think determines what we do, and what we do determines what we get."

exmachina

  • Guest
Re: Change Title Bar Text in AutoCAD 2013 / 2014 Window
« Reply #6 on: February 24, 2014, 10:18:33 PM »


Code - vb.net: [Select]
  1. Imports System.Runtime.InteropServices
  2. Imports System.Text
  3. Imports System.Windows.Forms
  4.  
  5. #If BCAD Then
  6. Imports Teigha.Runtime
  7. Imports _AcAp = Bricscad.ApplicationServices
  8. Imports Autodesk.AutoCAD.Runtime
  9. Imports _AcAp = Autodesk.AutoCAD.ApplicationServices
  10. #End If
  11.  
  12. Public Class aEiOu
  13.    Implements IExtensionApplication
  14.  
  15.    Private _hook As MainWindowHook
  16.  
  17.    Private Sub Initialize() Implements IExtensionApplication.Initialize
  18.        _hook = New MainWindowHook
  19.        Dim hwnd As IntPtr = _AcAp.Application.MainWindow.Handle
  20.        Dim length As Integer = NativeMethods.GetWindowTextLengthW(hwnd)
  21.        Dim stb As StringBuilder = New StringBuilder(length + 1)
  22.        NativeMethods.GetWindowTextW(hwnd, stb, length + 1)
  23.        NativeMethods.SetWindowTextW(hwnd, stb.ToString())
  24.    End Sub
  25.  
  26.    Private Sub Terminate() Implements IExtensionApplication.Terminate
  27.        If _hook IsNot Nothing Then
  28.            _hook.Dispose()
  29.            _hook = Nothing
  30.        End If
  31.    End Sub
  32.  
  33.    Private Class MainWindowHook
  34.        Inherits NativeWindow
  35.        Implements IDisposable
  36.  
  37.        Private Const windowTitle As String = "aEiOu"
  38.  
  39.        Public Sub New()
  40.            AssignHandle(_AcAp.Application.MainWindow.Handle)
  41.        End Sub
  42.  
  43.        Protected Overrides Sub WndProc(ByRef m As Message)
  44.            Select Case m.Msg
  45.                Case NativeConstants.WM_GETTEXT
  46.                    Dim wParam As Long = m.WParam.ToInt64()
  47.  
  48.                    Dim text As String = windowTitle
  49.                    If wParam < windowTitle.Length Then
  50.                        text = text.Substring(0, CInt(wParam))
  51.                    End If
  52.  
  53.                    text += vbNullChar
  54.  
  55.                    Dim textBytes() As Byte = System.Text.Encoding.Unicode.GetBytes(text)
  56.                    Marshal.Copy(textBytes, 0, m.LParam, textBytes.Length)
  57.                    m.Result = New IntPtr(text.Length)
  58.                    Return
  59.  
  60.                Case NativeConstants.WM_GETTEXTLENGTH
  61.                    m.Result = New IntPtr(windowTitle.Length)
  62.                    Return
  63.            End Select
  64.  
  65.            MyBase.WndProc(m)
  66.        End Sub
  67.  
  68.        Private disposedValue As Boolean
  69.  
  70.        Protected Overridable Sub Dispose(disposing As Boolean)
  71.            If Not disposedValue Then
  72.                ReleaseHandle()
  73.                disposedValue = True
  74.            End If
  75.        End Sub
  76.  
  77.  
  78.        Protected Overrides Sub Finalize()
  79.            Dispose(False)
  80.            MyBase.Finalize()
  81.        End Sub
  82.  
  83.        Public Sub Dispose() Implements IDisposable.Dispose
  84.            Dispose(True)
  85.            GC.SuppressFinalize(Me)
  86.        End Sub
  87.  
  88.    End Class
  89.  
  90.    Private NotInheritable Class NativeMethods
  91.  
  92.        <DllImport("user32.dll", EntryPoint:="GetWindowTextLengthW")> _
  93.        Public Shared Function GetWindowTextLengthW(ByVal hWnd As IntPtr) As Integer
  94.        End Function
  95.  
  96.        <DllImport("user32.dll", EntryPoint:="GetWindowTextW")> _
  97.        Public Shared Function GetWindowTextW(ByVal hWnd As IntPtr, <MarshalAs(UnmanagedType.LPWStr)> ByVal lpString As System.Text.StringBuilder, ByVal cch As Integer) As Integer
  98.        End Function
  99.  
  100.        <DllImport("user32.dll", EntryPoint:="SetWindowTextW")> _
  101.        Public Shared Function SetWindowTextW(ByVal hWnd As IntPtr, <MarshalAs(UnmanagedType.LPWStr)> ByVal lpString As String) As <MarshalAs(UnmanagedType.Bool)> Boolean
  102.        End Function
  103.    End Class
  104.  
  105.    Private NotInheritable Class NativeConstants
  106.        Public Const WM_GETTEXT As Integer = 13
  107.        Public Const WM_GETTEXTLENGTH As Integer = 14
  108.    End Class
  109. End Class

Idea taken from :
http://www.manusoft.com/software/freebies/arx.html
(ChangeAcadTitle.zip)
« Last Edit: February 24, 2014, 10:23:41 PM by jar »

owenwengerd

  • Bull Frog
  • Posts: 437
Re: Change Title Bar Text in AutoCAD 2013 / 2014 Window
« Reply #7 on: February 24, 2014, 10:35:25 PM »
(ChangeAcadTitle.zip)

I thought about mentioning that file when I first saw this thread, but I was afraid it might no longer work. I'm glad to see the technique does still work.

ROBBO

  • Bull Frog
  • Posts: 217
Re: Change Title Bar Text in AutoCAD 2013 / 2014 Window
« Reply #8 on: February 25, 2014, 03:35:51 AM »
Thank you to all of you who have taken time to respond.

Went with the C# option from BlackBox and works a treat in both 2013 and 2014. :-D

Not sure why I could not get my attempt to work, but never mind. Problem solved!

Cheers, Robbo.
The only thing to do with good advice is to pass it on.
It is never of any use to oneself.

Oscar Wilde
(1854-1900, Irish playwright, poet and writer)

BlackBox

  • King Gator
  • Posts: 3743
Re: Change Title Bar Text in AutoCAD 2013 / 2014 Window
« Reply #9 on: February 25, 2014, 08:38:56 AM »
Thank you to all of you who have taken time to respond.

Went with the C# option from BlackBox and works a treat in both 2013 and 2014. :-D

Not sure why I could not get my attempt to work, but never mind. Problem solved!

Cheers, Robbo.

We're happy to help, and that is kind of you to say... However I merely ported VB to C# (with minor changes) - I'd be remiss to take credit for what Xiaodong Liang wrote in the DevBlog article Kerry and yourself referenced above.  :-)

Cheers
"How we think determines what we do, and what we do determines what we get."

Jeff H

  • Needs a day job
  • Posts: 5995
Re: Change Title Bar Text in AutoCAD 2013 / 2014 Window
« Reply #10 on: February 25, 2014, 09:50:43 AM »
I'm shameless.
Your Welcome :-)

BlackBox

  • King Gator
  • Posts: 3743
Re: Change Title Bar Text in AutoCAD 2013 / 2014 Window
« Reply #11 on: February 25, 2014, 10:23:21 AM »
"How we think determines what we do, and what we do determines what we get."

nullptr

  • BricsCAD
  • Needs a day job
  • Posts: 6820
  • AKA Daniel
Re: Change Title Bar Text in AutoCAD 2013 / 2014 Window
« Reply #12 on: February 27, 2014, 02:44:08 PM »
this may work too

Code: [Select]
        [CommandMethod("doit")]
        static public void doit()
        {
            AcAp.Application.MainWindow.Text = "Hello world";
        }

BlackBox

  • King Gator
  • Posts: 3743
Re: Change Title Bar Text in AutoCAD 2013 / 2014 Window
« Reply #13 on: February 27, 2014, 03:22:31 PM »
this may work too

Code: [Select]
        [CommandMethod("doit")]
        static public void doit()
        {
            AcAp.Application.MainWindow.Text = "Hello world";
        }

Fantastic :-D... Why on Earth would they write out all that they did in the DevBlog article then?!?  :-o
"How we think determines what we do, and what we do determines what we get."

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11653
  • class keyThumper<T>:ILazy<T>
Re: Change Title Bar Text in AutoCAD 2013 / 2014 Window
« Reply #14 on: April 03, 2014, 05:10:45 AM »
this may work too

Code: [Select]
        [CommandMethod("doit")]
        static public void doit()
        {
            AcAp.Application.MainWindow.Text = "Hello world";
        }

A late re-visit.
Thanks Dan.
There's an expression that goes something like "Can't see the wood for the trees" ... probably applies :)
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

--> Donate to theSwamp<--

Andrey Bushman

  • Swamp Rat
  • Posts: 860
Re: Change Title Bar Text in AutoCAD 2013 / 2014 Window
« Reply #15 on: April 03, 2014, 06:37:01 AM »
Yes, this is the old info :) I used it in the AutoCAD 2009 even :)

gpa

  • Guest
Re: Change Title Bar Text in AutoCAD 2013 / 2014 Window
« Reply #16 on: September 29, 2014, 08:41:37 AM »
Please advise how to apply this on AutoCAD 2014. VERY URGENT.

        [CommandMethod("doit")]
        static public void doit()
        {
            AcAp.Application.MainWindow.Text = "Hello world";
        }

Thanks...

this may work too

Code: [Select]
        [CommandMethod("doit")]
        static public void doit()
        {
            AcAp.Application.MainWindow.Text = "Hello world";
        }

A late re-visit.
Thanks Dan.
There's an expression that goes something like "Can't see the wood for the trees" ... probably applies :)

gpa

  • Guest
Re: Change Title Bar Text in AutoCAD 2013 / 2014 Window
« Reply #17 on: September 30, 2014, 07:33:37 AM »
Dear BlackBox,

Please assist how to do that and apply to AutoCAD 2014?
Appreciate your kind assistance and guide... or anyone else who willing to share...  :-D

Thank you to all of you who have taken time to respond.

Went with the C# option from BlackBox and works a treat in both 2013 and 2014. :-D

Not sure why I could not get my attempt to work, but never mind. Problem solved!

Cheers, Robbo.

We're happy to help, and that is kind of you to say... However I merely ported VB to C# (with minor changes) - I'd be remiss to take credit for what Xiaodong Liang wrote in the DevBlog article Kerry and yourself referenced above.  :-)

Cheers

Keith Brown

  • Swamp Rat
  • Posts: 593
Re: Change Title Bar Text in AutoCAD 2013 / 2014 Window
« Reply #18 on: September 30, 2014, 09:42:52 AM »
When you post the same question over and over people will just tend to ignore you.  You have asked the question several times and the answer has been posted in several forms.

Below I will post a complete class that will change the Title Bar.  The class below is as simple as it gets and if you are unable to get it to work then you will need to think about taking some basic .NET courses and/or read up on the .NET API for AutoCAD.   I would suggest going through the Autodesk training located at http://usa.autodesk.com/adsk/servlet/index?id=18162650&siteID=123112.  If you had already done the miminum and looked at this course then you would not be asking the questions that you are asking.


Code - C#: [Select]
  1. // Requires reference to accoremgd.dll, acdbmgd.dll, & acmgd.dll
  2.  
  3. using Autodesk.AutoCAD.Runtime;
  4. using AcApp = Autodesk.AutoCAD.ApplicationServices.Application;
  5.  
  6. [assembly: CommandClass(typeof(TheSwamp.Mep.TitleBar))]
  7. [assembly: ExtensionApplication(typeof(TheSwamp.Mep.TitleBar))]
  8.  
  9. namespace TheSwamp.Mep
  10. {
  11.    class TitleBar : IExtensionApplication
  12.    {
  13.        private const string TitleBarText = "Manually modified TitleBar Text";
  14.  
  15.        // Will change the text of the main window upon loading of the plugin.
  16.        public void Initialize()
  17.        {
  18.            AcApp.MainWindow.Text = "AutoCAD MEP 2014 - Brought to you by The Swamp.org";
  19.        }
  20.  
  21.        public void Terminate()
  22.        {
  23.        }
  24.  
  25.        // Will change the text of the main window when the command is ran.
  26.        [CommandMethod("ModifyTitleBar")]
  27.        static public void ModifyTitleBar()
  28.        {
  29.            AcApp.MainWindow.Text = TitleBarText;
  30.        }
  31.    }
  32. }


**Edit** To include comments as to what each method does.
« Last Edit: September 30, 2014, 09:59:51 AM by Keith Brown »
Keith Brown | AutoCAD MEP Blog | RSS Feed
AutoCAD MEP 2014 / Revit MEP 2014 / EastCoast CAD/CAM addon / Visual Studio 2013