• Blog
  • Info Support
  • Career
  • Training
  • International Group
  • Info Support
  • Blog
  • Career
  • Training
  • International Group
  • Search
logo InfoSupport
  • Latest blogs
  • Popular blogs
  • Experts
      • All
      • Bloggers
      • Speakers
  • Meet us
  • About us
    • nl
    • en
    • .NET
    • 3D printing
    • Advanced Analytics
    • Agile
    • Akka
    • Alexa
    • Algorithms
    • Api's
    • Architectuur
    • Artificial Intelligence
    • ATDD
    • Augmented Reality
    • AWS
    • Azure
    • Big Data
    • Blockchain
    • Business Intelligence
    • Chatbots
    • Cloud
    • Code Combat
    • Cognitive Services
    • Communicatie
    • Containers
    • Continuous Delivery
    • CQRS
    • Cyber Security
    • Dapr
    • Data
    • Data & Analystics
    • Data Science
    • Data Warehousing
    • Databricks
    • DataOps
    • Developers life
    • DevOps
    • Digital Days
    • Digital Twin
    • Docker
    • eHealth
    • Enterprise Architecture
    • Event Sourcing
    • Hacking
    • Infrastructure & Hosting
    • Innovatie
    • Integration
    • Internet of Things
    • Java
    • Machine Learning
    • Microservices
    • Microsoft
    • Microsoft Bot Framework
    • Microsoft Data Platform
    • Mobile Development
    • Mutation Testing
    • Open source
    • Pepper
    • Power BI
    • Privacy & Ethiek
    • Python
    • Quality Assistance & Test
    • Quality Assurance & Test
    • Requirements Management
    • Scala
    • Scratch
    • Security
    • SharePoint
    • Software Architecture
    • Software development
    • Software Factory
    • SQL Server
    • SSL
    • Start-up
    • Startup thinking
    • Stryker
    • Test Quality
    • Testing
    • TLS
    • TypeScript
    • Various
    • Web Development
    • Web-scale IT
    • Xamarin
    • All
    • Bloggers
    • Speakers
Home » Creating an VS2010 add-in to show the running user as part of the main IDE window title
  • Creating an VS2010 add-in to show the running user as part of the main IDE window title

    • By Marcel de Vries
    • .NET 12 years ago
    • .NET 0 comments
    • .NET .NET
    Creating an VS2010 add-in to show the running user as part of the main IDE window title

    *Moved to: http://fluentbytes.com/creating-an-vs2010-add-in-to-show-the-running-user-as-part-of-the-main-ide-window-title/

    Today some of my fellow MVP’s asked the question if there is an option in Visual Studio to show under which user account the IDE is running.

    the need this feature since they do a lot of demonstrations on using the IDE and then use the runas option, to show how you e.g. can work with multiple users on a piece of code using version control etc.

    Unfortunately this is something not default possible with the VS IDE.

    But after doing some visual Studio Integration work in the past I thought this should not be to hard to build myself.

    On the first thought I would just try to create an Visual Studio Add-in and there try to obtain a reference to the main window and there set the caption. Unfortunately that would have been too easy :-D. It is not possible this way , since the property on the main window is read-only and when you try to set it you will get an error message.

    But hey, you probably also remember the good old days where we had the Win32 API as our friend. In win32 you can set the windows caption of a window using a wind32 API call called SendMessage as long as you provide the correct parameters. So I thought to give that Idea a shot.

    To make that work I did following:

    On the Add In connect, get a reference to the Main Window. From the Main window, get the native windows handle (Hwnd)

    Then use good old PInvoke to call an imported win32 API SendMessage and send a WM_SETTEXT message to the main window.

    Now the last thing to fix, is that each and every time a window is opened or changed, the caption will disappear. To fix this, I just subscribed to two main events, WindowActivated and WindowCreated and there execute the same code again. this way the caption is always updated once a new window is opened or closed.

    The following code does the trick:

    [DllImport("user32.dll", CharSet = CharSet.Auto)]
            static extern IntPtr SendMessage(IntPtr hWnd, UInt32 Msg, IntPtr wParam, string lParam);
            public const UInt32 WM_SETTEXT = 0x000C;
    public void OnConnection(object application, ext_ConnectMode connectMode, object addInInst, ref Array custom)
    {
       _applicationObject = (DTE2)application;
       _addInInstance = (AddIn)addInInst;
    }
    public void OnStartupComplete(ref Array custom)
    {
        _applicationObject.Events.WindowEvents.WindowActivated += new _dispWindowEvents_WindowActivatedEventHandler(WindowEvents_WindowActivated);
        _applicationObject.Events.WindowEvents.WindowCreated += new _dispWindowEvents_WindowCreatedEventHandler(WindowEvents_WindowCreated);
        WindowEvents_WindowActivated(null, null);
    }
    void WindowEvents_WindowCreated(Window Window)
    {
        WindowEvents_WindowActivated(null, null);
    }

    void WindowEvents_WindowActivated(Window GotFocus, Window LostFocus)
    {
         DTE d = _applicationObject as DTE;
         IntPtr hWnd = new System.IntPtr(d.MainWindow.HWnd);
         string Caption = d.MainWindow.Caption + "*** " + System.Threading.Thread.CurrentPrincipal.Identity.Name + " ****";
         Connect.SendMessage(hWnd, WM_SETTEXT, new IntPtr(0), Caption);
    }

    As you can see, the following is the result when you activate the add-in:

    image

     

    Here you can find the sources as a downloadable Zip(https://blogs.infosupport.com/media/p/202504.aspx), I did not create an installer for it, just open the zip, compile it and activate the registered Add-in.

    voila 🙂

    Cheers

    Marcel

    Follow my new blog on http://fluentbytes.com

    Share this

Marcel de Vries

View profile

Related IT training

Go to training website

Related Consultancy solutions

Go to infosupport.com

Related blogs

  • Building a custom Kubernetes operator in C#

    Building a custom Kubernetes operator in C# Willem Meints - 2 months ago

  • Transform SpecFlow Table Column

    Transform SpecFlow Table Column Ronald Bosma - 4 months ago

  • Building a passwordless login flow with WebAuthn and th…

    Building a passwordless login flow with WebAuthn and th… Willem Meints - 7 months ago

Data Discovery Channel

  • Explainable AI - Break open the blackbox

  • Toekomstvaste microservice data architecturen

  • Modern Data Platform

Nieuwsbrief

* verplichte velden

Contact

  • Head office NL
  • Kruisboog 42
  • 3905 TG Veenendaal
  • T +31 318 552020
  • Call
  • Mail
  • Directions
  • Head office BE
  • Generaal De Wittelaan 17
  • bus 30 2800 Mechelen
  • T +32 15 286370
  • Call
  • Mail
  • Directions

Follow us

  • Twitter
  • Facebook
  • Linkedin
  • Youtube

Newsletter

Sign in

Extra

  • Media Library
  • Disclaimer
  • Algemene voorwaarden
  • ISHBS Webmail
  • Extranet
Beheer cookie toestemming
Deze website maakt gebruik van Functionele en Analytische cookies voor website optimalisatie en statistieken.
Functioneel Always active
De technische opslag of toegang is strikt noodzakelijk voor het legitieme doel het gebruik mogelijk te maken van een specifieke dienst waarom de abonnee of gebruiker uitdrukkelijk heeft gevraagd, of met als enig doel de uitvoering van de transmissie van een communicatie over een elektronisch communicatienetwerk.
Voorkeuren
De technische opslag of toegang is noodzakelijk voor het legitieme doel voorkeuren op te slaan die niet door de abonnee of gebruiker zijn aangevraagd.
Statistieken
De technische opslag of toegang die uitsluitend voor statistische doeleinden wordt gebruikt. De technische opslag of toegang die uitsluitend wordt gebruikt voor anonieme statistische doeleinden. Zonder dagvaarding, vrijwillige naleving door uw Internet Service Provider, of aanvullende gegevens van een derde partij, kan informatie die alleen voor dit doel wordt opgeslagen of opgehaald gewoonlijk niet worden gebruikt om je te identificeren.
Marketing
De technische opslag of toegang is nodig om gebruikersprofielen op te stellen voor het verzenden van reclame, of om de gebruiker op een website of over verschillende websites te volgen voor soortgelijke marketingdoeleinden.
Manage options Manage services Manage vendors Read more about these purposes
Voorkeuren
{title} {title} {title}