VS Add-In question

J

Johnny Jörgensen

In the VS 2005 add-in I'm currently developing, I want to be able to find
out when the entire Visual Studio IDE receives and loses focus (e.g. when
the user switches to another program and back to the IDE).

I would have expected such an event to be present in DTE.DTEEvents, but it
isn't, so how do I go about doing that?

Cheers,
Johnny J.
 
N

Nicholas Paldino [.NET/C# MVP]

Johnny,

It's a bit of a hack, but from the DTE class, you could use the
MainWindow property to get what I assume is the main window to the IDE.
Once you have that, you can subclass the window and intercept the
WM_ACTIVATE and/or WM_ACTIVATEAPP messages to see when your main window is
being activated (or a window that is a child of the main window).
 
J

Johnny Jörgensen

Hi Nicholas

Thanks for the input. I did try your approach. But seeing that I'm not so
experienced in subclassing windows messages, I found a C# example of how to
do it on vbAccelerator.com
(http://www.vbaccelerator.com/home/N...dows_Messages/Subclassing_in__NET/article.asp).
It was actually almost precisely what i was looking for apart from one
thing: it was indeed in C#, and the current project I'm working on is VB.

So I converted the C# to VB and it went ok apart from one detail (as far as
I can tell - it compiled at least...):

It seems like I can get the hWnd as well as the Handle from
EnvDTE.MainWindow (even though they are not visible in the intellisense).
The problem is that both of these values are Integer, but my subclassing
routine requires a handle of the type IntPtr.

I tried this:
activateChange = New ActivationChangeSubclass(CType(myDTE.MainWindow.Handle,
IntPtr), Nothing, Me)

but It made the Add-In crash, so apparently it wasn't the right solution.
Same with:

activateChange = New ActivationChangeSubclass(CType(myDTE.MainWindow.HWnd,
IntPtr), Nothing, Me)

Any ideas about how I can do that?

Cheers,

Johnny J.









Johnny,

It's a bit of a hack, but from the DTE class, you could use the
MainWindow property to get what I assume is the main window to the IDE.
Once you have that, you can subclass the window and intercept the
WM_ACTIVATE and/or WM_ACTIVATEAPP messages to see when your main window is
being activated (or a window that is a child of the main window).


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Johnny Jörgensen said:
In the VS 2005 add-in I'm currently developing, I want to be able to find
out when the entire Visual Studio IDE receives and loses focus (e.g. when
the user switches to another program and back to the IDE).

I would have expected such an event to be present in DTE.DTEEvents, but
it isn't, so how do I go about doing that?

Cheers,
Johnny J.
 
N

Nicholas Paldino [.NET/C# MVP]

Johnny,

You can't cast directly from an integer to an IntPtr, but you can create
a new IntPtr from an integer, like so (in C#, but you can convert it to VB
easily):

// The integer value.
int i = 10;

IntPtr ptr = new IntPtr(i);


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Johnny Jörgensen said:
Hi Nicholas

Thanks for the input. I did try your approach. But seeing that I'm not so
experienced in subclassing windows messages, I found a C# example of how
to do it on vbAccelerator.com
(http://www.vbaccelerator.com/home/N...dows_Messages/Subclassing_in__NET/article.asp).
It was actually almost precisely what i was looking for apart from one
thing: it was indeed in C#, and the current project I'm working on is VB.

So I converted the C# to VB and it went ok apart from one detail (as far
as I can tell - it compiled at least...):

It seems like I can get the hWnd as well as the Handle from
EnvDTE.MainWindow (even though they are not visible in the intellisense).
The problem is that both of these values are Integer, but my subclassing
routine requires a handle of the type IntPtr.

I tried this:
activateChange = New
ActivationChangeSubclass(CType(myDTE.MainWindow.Handle, IntPtr), Nothing,
Me)

but It made the Add-In crash, so apparently it wasn't the right solution.
Same with:

activateChange = New ActivationChangeSubclass(CType(myDTE.MainWindow.HWnd,
IntPtr), Nothing, Me)

Any ideas about how I can do that?

Cheers,

Johnny J.









Johnny,

It's a bit of a hack, but from the DTE class, you could use the
MainWindow property to get what I assume is the main window to the IDE.
Once you have that, you can subclass the window and intercept the
WM_ACTIVATE and/or WM_ACTIVATEAPP messages to see when your main window
is being activated (or a window that is a child of the main window).


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Johnny Jörgensen said:
In the VS 2005 add-in I'm currently developing, I want to be able to
find out when the entire Visual Studio IDE receives and loses focus
(e.g. when the user switches to another program and back to the IDE).

I would have expected such an event to be present in DTE.DTEEvents, but
it isn't, so how do I go about doing that?

Cheers,
Johnny J.
 
J

Johnny Jörgensen

Thanks a lot for your help Nicholas - Now I got it working perfectly just
like I want it...

Cheers,
Johnny J.





Nicholas Paldino said:
Johnny,

You can't cast directly from an integer to an IntPtr, but you can
create a new IntPtr from an integer, like so (in C#, but you can convert
it to VB easily):

// The integer value.
int i = 10;

IntPtr ptr = new IntPtr(i);


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Johnny Jörgensen said:
Hi Nicholas

Thanks for the input. I did try your approach. But seeing that I'm not so
experienced in subclassing windows messages, I found a C# example of how
to do it on vbAccelerator.com
(http://www.vbaccelerator.com/home/N...dows_Messages/Subclassing_in__NET/article.asp).
It was actually almost precisely what i was looking for apart from one
thing: it was indeed in C#, and the current project I'm working on is VB.

So I converted the C# to VB and it went ok apart from one detail (as far
as I can tell - it compiled at least...):

It seems like I can get the hWnd as well as the Handle from
EnvDTE.MainWindow (even though they are not visible in the intellisense).
The problem is that both of these values are Integer, but my subclassing
routine requires a handle of the type IntPtr.

I tried this:
activateChange = New
ActivationChangeSubclass(CType(myDTE.MainWindow.Handle, IntPtr), Nothing,
Me)

but It made the Add-In crash, so apparently it wasn't the right solution.
Same with:

activateChange = New
ActivationChangeSubclass(CType(myDTE.MainWindow.HWnd, IntPtr), Nothing,
Me)

Any ideas about how I can do that?

Cheers,

Johnny J.









Johnny,

It's a bit of a hack, but from the DTE class, you could use the
MainWindow property to get what I assume is the main window to the IDE.
Once you have that, you can subclass the window and intercept the
WM_ACTIVATE and/or WM_ACTIVATEAPP messages to see when your main window
is being activated (or a window that is a child of the main window).


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

In the VS 2005 add-in I'm currently developing, I want to be able to
find out when the entire Visual Studio IDE receives and loses focus
(e.g. when the user switches to another program and back to the IDE).

I would have expected such an event to be present in DTE.DTEEvents, but
it isn't, so how do I go about doing that?

Cheers,
Johnny J.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top