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 / Windows Forms / WinForm General / April 2005

Tip: Looking for answers? Try searching our database.

Active Window

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Josh - 11 Apr 2005 14:50 GMT
Hi,

Anyone know how to read the text from the title bar of currently active
window in Windows.  I want to record what application I used at what time.

I hope there is a quick c# answer.

Thanks in advance
Tim Wilson - 11 Apr 2005 18:09 GMT
One way to do this might be to pinvoke the GetForegroundWindow,
GetWindowTextLength, and GetWindowText functions. I believe all of these
functions are present at the link below.
http://www.pinvoke.net/

Signature

Tim Wilson
.Net Compact Framework MVP

> Hi,
>
[quoted text clipped - 4 lines]
>
> Thanks in advance
Josh - 12 Apr 2005 14:11 GMT
Excellent advice, thanks very much!!!!
lhsu - 22 Apr 2005 20:45 GMT
Hello,
I am trying to do the same thing but have no experience with pinvoke.  Can
you provide a code snippet to help get me started?
Thanks!
Josh - 25 Apr 2005 10:12 GMT
 private void GetActiveWindow()
 {
  try
  {

   const int nChars = 256;
   int handle = 0;
   StringBuilder Buff = new StringBuilder(nChars);

   handle = GetForegroundWindow();

   if ( GetWindowText(handle, Buff, nChars) > 0 )
   {
    textBox1.Text = Buff.ToString();
   }

   comboBox1.Visible = false;
   button1_Click(null,null);
  }
  catch(Exception wentWrong)
  {
//    MessageBox.Show(this,wentWrong.Message);
  }

 }

> Hello,
> I am trying to do the same thing but have no experience with pinvoke.  Can
> you provide a code snippet to help get me started?
> Thanks!

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.