473,463 Members | 1,380 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

VS Add-In question

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.
Jul 30 '07 #1
4 1069
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]
- mv*@spam.guard.caspershouse.com

"Johnny Jörgensen" <jo**@altcom.sewrote in message
news:Oo**************@TK2MSFTNGP02.phx.gbl...
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.

Jul 30 '07 #2
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/NE...T/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.Ha ndle,
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.HW nd,
IntPtr), Nothing, Me)

Any ideas about how I can do that?

Cheers,

Johnny J.



"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.comskrev i
meddelandet news:%2****************@TK2MSFTNGP03.phx.gbl...
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]
- mv*@spam.guard.caspershouse.com

"Johnny Jörgensen" <jo**@altcom.sewrote in message
news:Oo**************@TK2MSFTNGP02.phx.gbl...
>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.


Jul 30 '07 #3
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]
- mv*@spam.guard.caspershouse.com

"Johnny Jörgensen" <jo**@altcom.sewrote in message
news:%2****************@TK2MSFTNGP04.phx.gbl...
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/NE...T/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.Ha ndle, 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.HW nd,
IntPtr), Nothing, Me)

Any ideas about how I can do that?

Cheers,

Johnny J.



"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.comskrev i
meddelandet news:%2****************@TK2MSFTNGP03.phx.gbl...
>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]
- mv*@spam.guard.caspershouse.com

"Johnny Jörgensen" <jo**@altcom.sewrote in message
news:Oo**************@TK2MSFTNGP02.phx.gbl...
>>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.



Jul 30 '07 #4
Thanks a lot for your help Nicholas - Now I got it working perfectly just
like I want it...

Cheers,
Johnny J.

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.comskrev i
meddelandet news:e2**************@TK2MSFTNGP04.phx.gbl...
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]
- mv*@spam.guard.caspershouse.com

"Johnny Jörgensen" <jo**@altcom.sewrote in message
news:%2****************@TK2MSFTNGP04.phx.gbl...
>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/NE...T/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.H andle, 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.H Wnd, IntPtr), Nothing,
Me)

Any ideas about how I can do that?

Cheers,

Johnny J.



"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.comskrev
i meddelandet news:%2****************@TK2MSFTNGP03.phx.gbl...
>>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]
- mv*@spam.guard.caspershouse.com

"Johnny Jörgensen" <jo**@altcom.sewrote in message
news:Oo**************@TK2MSFTNGP02.phx.gbl...
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.



Jul 31 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
by: Stefan Mueller | last post by:
With the following code I can add a new row to an existing table. That really works great. Many thanks to all who helped me so far. But my problem is that the added cells do somehow not have the...
5
by: Mike L | last post by:
I have two questions. 1) What is the code to check if datagrid already has a datasource? When the user clicks "ADD" button I want to add a record to the data grid, if the user clicks "ADD"...
3
by: Dean Slindee | last post by:
Is there a way to replace the commented out parameter add syntax with a single line of code, like the .Parameter.Add("@Letter"...) line below (which does not work)? 'Dim prmLetter As New...
0
by: herman404 | last post by:
Hi everyone, I'm trying to dynamically add 3 button columns to a DataGrid object that I have on an ASP.net webpage, but I don't see any documentation on how to do it. I've seen plenty of examples...
3
by: Greg Scharlemann | last post by:
I'm not sure the best way to accomplish this... my hunch is with javascript, but I'm not sure if using server side code (PHP) would be easier. I'm adding people to a database. People have a...
12
by: David | last post by:
Below are three classes for a console application. If put into three separate files, the sub main() will launch multiple threads adding and removing the same value. At the end we expect the value...
1
by: Sri Nanduri | last post by:
Hi , I am new to JS. Please help me to resolve my issue. 1.When the form loads there are two DropDown boxes and a ADD button. 2.When I click the add button it will add two DropDown boxes and a add...
0
by: anureddy | last post by:
help me how to add datagridview columns to another table,using windowsapplications. and set the displaymember and value member datagridviewcomboboxcolumn. i used this below code but that not...
0
acoder
by: acoder | last post by:
Problem The select object's add method doesn't append options to the end of the list. Browser Internet Explorer Example The Javascript code for appending an option element at the end of a...
2
by: Question123 | last post by:
<root> <Element> <add key="1" value="1"/> <add key="2" value="2"/> <add key="3" value="3"/> <add key="4" value="4"/> </Element> <Items>
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.