Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / July 2007

Tip: Looking for answers? Try searching our database.

VS Add-In question

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Johnny Jörgensen - 30 Jul 2007 15:46 GMT
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.
Nicholas Paldino [.NET/C# MVP] - 30 Jul 2007 16:03 GMT
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).

Signature

         - Nicholas Paldino [.NET/C# MVP]
         - mvp@spam.guard.caspershouse.com

> 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
[quoted text clipped - 5 lines]
> Cheers,
> Johnny J.
Johnny Jörgensen - 30 Jul 2007 22:07 GMT
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/NET/Code/Libraries/Windows_Messages/Subclassin
g_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,
>
[quoted text clipped - 13 lines]
>> Cheers,
>> Johnny J.
Nicholas Paldino [.NET/C# MVP] - 30 Jul 2007 22:29 GMT
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);

Signature

         - Nicholas Paldino [.NET/C# MVP]
         - mvp@spam.guard.caspershouse.com

> Hi Nicholas
>
[quoted text clipped - 47 lines]
>>> Cheers,
>>> Johnny J.
Johnny Jörgensen - 31 Jul 2007 19:56 GMT
Thanks a lot for your help Nicholas - Now I got it working perfectly just
like I want it...

Cheers,
Johnny J.

> Johnny,
>
[quoted text clipped - 59 lines]
>>>> Cheers,
>>>> Johnny J.

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.