0

I am looking for an event that will notify me when the main window is minimized and restored in a Visual Studio extension package.

I've looked at the DTE2.Events, as well as the IVsWindowFrame and IVsWindowFrameNotify interfaces but don't see anything that will do what I need.

dmck
  • 7,801
  • 7
  • 43
  • 79
  • Why do you want this? – Jason Malinowski Feb 13 '14 at 22:37
  • @JasonMalinowski I actually want to know when VS is inactive so I can offset a time sensitive variable. I tried using `IVsLongIdleManager` but it didn't seem to fire consistently. My next thought was detecting when VS was minimized (less than perfect solution, since VS can be sitting idle in another monitor, etc). Any suggestions for this scenario? – dmck Feb 19 '14 at 20:38
  • Maybe checking if it has focus or is active? – Charlie Feb 19 '14 at 21:55
  • Is your scenario to determine how long you or a dev has VS open and is "working" by some definition to log time (say for a contract)? Then you might have to get the HWND and go play with Win32 APIs from there. If it's a different scenario...well, please clarify. This is a great example of the XY problem: without knowing what you're actually trying to do, we can recommend 10 different solutions, none of are useful to you. – Jason Malinowski Feb 20 '14 at 02:08
  • At this point the goal of the application is diverging from the original question. – Charlie Feb 20 '14 at 18:20

2 Answers2

1

Get the HWND of the VS window: HWnd of Visual Studio 2010

Capture the messages being sent to Visual Studio: C# - Capturing Windows Messages from a specific application

Then wait for a WM_SIZE message: http://msdn.microsoft.com/en-us/library/ms632646%28v=VS.85%29.aspx

Community
  • 1
  • 1
Charlie
  • 8,530
  • 2
  • 55
  • 53
  • Thanks for the suggestion, however capturing windows messages from a VS extension does not appear to be a supported scenario – dmck Feb 19 '14 at 20:41
  • I think it's more supported than maybe you think. It's a documented fundamental API for Windows, and native hooks to .NET are also well documented and supported. The risk of MS doing something to break it in future versions of VS is practically zero. – Charlie Feb 19 '14 at 21:54
  • Correct, I should of been more specific. Application.AddMessageFilter isn't a supported sceneario.. so you do indeed need to use the approach detailed in your links. – dmck Feb 20 '14 at 19:11
  • It's not supported bu the VS extension API, but it's supported by the Win32 API which is itself compatible (although probably not officially "supported" by means of technical assistance but won't ever break) with VS. – Charlie Feb 20 '14 at 21:24
1

The EnvDTE80.DTE2.Events.WindowEvents.WindowMoved event fires on main window minimize and restore.

Sergey Vlasov
  • 26,641
  • 3
  • 64
  • 66
  • Thanks for the suggestion, however there doesn't appear to be a way to determine if the window or VS is visible or not – dmck Feb 19 '14 at 20:40
  • The Top parameter is -32000 when VS is minimized. Try: `private void OnWindowMoved(EnvDTE.Window w, int Top, int Left, int Width, int Height) { if (w == DTE.MainWindow) System.Windows.MessageBox.Show(Top.ToString()); }` – Sergey Vlasov Feb 20 '14 at 08:29
  • Unfortunately, on my VS 2010 WindowMoved is not fired when minimizing VS from the maximized state. – Sergey Vlasov Feb 20 '14 at 08:31