title: How to breakall and continue on focus lost in Visual Studio 2017
body: <p>I got the Edit and continue function setup for my C++ project so i can execute a breakall, change code and then continue to view the results of my code. 
  However it would be better if i didn't have to manually click the buttons. My first solution was using 1 keypress that executes a BreakAll and then the Continue function. However i didn't find a answer for using only Visual studio 2017. </p>
  
  <p>Then i came to a better idea. What if the compiled exe loses its focus and then gains it focus back to make it Execute a BreakAll and then Continue. 
  Or an alternative way which does the same but would be easier to make. Is when Visual Studio loses its focus (because i focused on the compiled exe). It quickly executes a BreakAll and then continues.
  That would let me write code and execute it in realtime.</p>
  
  <p>My question is does something like that already exists? I couldn't find an answer. And if not does someone have an idea if this is possible to make an a extension? Or is someone willing to make it? Thanks for reading.</p>
  
  <p>EDIT:
  Here is some Pseudo code. </p>
  
  <pre><code>if compiled_build_running == true &amp;&amp; lost_focus == true {
    Debug.BreakAll
    Debug.Continue
  }
  </code></pre>
  
  <p>EDIT2:
  Alright got it to work with some help and example scripts. It now saves and recompiles when visual studio loses its focus. And BreaksAll when it gains focus.
  Here is the modified code:</p>
  
  <pre><code>using EnvDTE;
  using EnvDTE80;
  
  public class E : VisualCommanderExt.IExtension
  {
      public void SetSite(EnvDTE80.DTE2 DTE_, Microsoft.VisualStudio.Shell.Package package) {
      DTE = DTE_;
      System.Windows.Application.Current.Deactivated += OnDeactivated;
      System.Windows.Application.Current.Activated += OnActivated;
  }
  
  public void Close() {
      System.Windows.Application.Current.Deactivated -= OnDeactivated;
      System.Windows.Application.Current.Activated -= OnActivated;
  }
  
  private void OnDeactivated(object sender, System.EventArgs e) {
      try {
          DTE.ExecuteCommand("File.SaveAll");
      } catch (System.Exception ex) {
      }
      if (DTE.Mode == vsIDEMode.vsIDEModeDebug) {
          DTE.ExecuteCommand("Debug.Start");
      }
  }
  
  private void OnActivated(object sender, System.EventArgs e) {
  
      if (DTE.Mode == vsIDEMode.vsIDEModeDebug) {
          DTE.ExecuteCommand("Debug.BreakAll");
      }
  
  }
  
  private EnvDTE80.DTE2 DTE;
  }
  </code></pre>