Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsVB SyntaxEnterprise DevelopmentDatabase AccessControlsCOMWin APICrystal ReportDeploymentGeneralGeneral 2
Related Topics
VB.NET / ASP.NETMS SQL ServerMS AccessOther Database ProductsMore Topics ...

VB Forum / General / August 2004



Tip: Looking for answers? Try searching our database.

Applicaion Logger

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Tim Baur - 30 Aug 2004 21:51 GMT
I'd like to write an background process that periodically logs the caption
of the window that has focus.  Any idea which API can do that?
Al Reid - 30 Aug 2004 22:03 GMT
> I'd like to write an background process that periodically logs the caption
> of the window that has focus.  Any idea which API can do that?
Tim,

Perhaps a combination of GetForgroundWindow and GetWondowText?

Signature

Al Reid

"It ain't what you don't know that gets you into trouble. It's what you know
for sure that just ain't so."  --- Mark Twain

Tim Baur - 30 Aug 2004 22:19 GMT
>> I'd like to write an background process that periodically logs the
>> caption of the window that has focus.  Any idea which API can do
>> that?
> Tim,
>
> Perhaps a combination of GetForgroundWindow and GetWondowText?

Yesiree, GetForgroundWindow, GetWondowText, and GetWindowTextLength did the
job.  

Thanks, Al.
Ken Halter - 30 Aug 2004 22:36 GMT
> Yesiree, GetForgroundWindow, GetWondowText, and GetWindowTextLength did the
> job.  
>
> Thanks, Al.

GetForgroundWindow and GetWondowText?

LOL... just shows how copy/paste bugs can keep going... and going... and
going..

Try... GetForegroundWindow and GetWindowText or post the declarations
your using for the others <g>

Signature

Ken Halter - MS-MVP-VB - http://www.vbsight.com
Please keep all discussions in the groups..

Tim Baur - 30 Aug 2004 22:46 GMT
>> Yesiree, GetForgroundWindow, GetWondowText, and GetWindowTextLength
>> did the job.  
[quoted text clipped - 8 lines]
> Try... GetForegroundWindow and GetWindowText or post the declarations
> your using for the others <g>

Hey!  I resemble that remark!

* * * * * * * *
 Declaration
* * * * * * * *

Public Declare Function GetForegroundWindow Lib "user32.dll" () As Long

Public Declare Function GetWindowText Lib "user32.dll" Alias _
"GetWindowTextA" (ByVal hWnd As Long, ByVal lpString As String, _
ByVal nMaxCount As Long) As Long

Public Declare Function GetWindowTextLength Lib "user32.dll" Alias _
"GetWindowTextLengthA" (ByVal hWnd As Long) As Long

* * * * * * * *
   Usage
* * * * * * * *

Dim sCaption As String
   
sCaption = Space(GetWindowTextLength(GetForegroundWindow) + 1)

Call GetWindowText(GetForegroundWindow, sCaption, Len(sCaption))

MsgBox sCaption
Tim Baur - 31 Aug 2004 16:07 GMT
Okay, here's the whole program if anyone's interested.  It's quick and
dirty but does what I need it to do.

This should help make my time sheets a whole lot easier to do.  I'm a
little afraid to see just how much screwing off I really do in a day,
however.

Controls:

Timer - "Timer1"
DataGrid - "grd"
RecordSet - "rs"

* * * * * * * *

Private Sub Form_Load()

   flds = Array("Window", "Date", "MarkTime", "Elapsed", "Current")
   ReDim vals(UBound(flds))
   
   rs.Fields.Append flds(0), adVarChar, 150
   rs.Fields.Append flds(1), adDate
   rs.Fields.Append flds(2), adUnsignedBigInt
   rs.Fields.Append flds(3), adUnsignedBigInt
   rs.Fields.Append flds(4), adUnsignedBigInt
   
   rs.Open
   
   Set grd.DataSource = rs
End Sub

Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
   If MsgBox("Save?", vbYesNo) = vbYes Then
       rs.Save "C:\Temp\TaskLog.xml", adPersistXML
   End If
End Sub

Private Sub Timer1_Timer()
   Dim sCaption As String
   Dim vBookMark As Variant
   
   sCaption = Space(GetWindowTextLength(GetForegroundWindow) + 1)
   Call GetWindowText(GetForegroundWindow, sCaption, Len(sCaption))
   
   sCaption = Left(sCaption, Len(sCaption) - 1)
   
   rs.Filter = "Window = '" & sCaption & "'"
       
   If rs.EOF And rs.BOF Then
       vals() = Array(sCaption, Date, Timer, 0, 0)
       rs.AddNew flds, vals
   Else
       With rs
           If sCaption <> sLastWindow Then
               .Fields("Elapsed") = .Fields("Elapsed") + _
                                    .Fields("Current")
               .Fields("MarkTime") = Timer
           Else
               .Fields("Current") = (Timer - .Fields("MarkTime"))
           End If
       End With
   End If
   
   rs.Filter = "Window <> '!'"
   sLastWindow = sCaption

End Sub

* * * * * * * *

One question for the group.

Whenever I try to remove a recordset filter with rs.Filter = AdFilterNone,
or rs.Filter = "", it never works.  All the documentation I've read in the
past tells me it should.  I usually have to hack it by filtering not equal
to a value I know doesn't exist.  Any idea what I'm doing wrong?
Al Reid - 30 Aug 2004 22:57 GMT
> > Yesiree, GetForgroundWindow, GetWondowText, and GetWindowTextLength did the
> > job.
> >
> > Thanks, Al.
>
> GetForgroundWindow and GetWondowText?

Ouch! Did I type that?  Quick make up a story...  Would you believe
arthritis and fat fingers?

> LOL... just shows how copy/paste bugs can keep going... and going... and
> going..
>
> Try... GetForegroundWindow and GetWindowText or post the declarations
> your using for the others <g>
Jim Edgar - 30 Aug 2004 23:47 GMT
> > Yesiree, GetForgroundWindow, GetWondowText, and GetWindowTextLength did the
> > job.
[quoted text clipped - 5 lines]
> LOL... just shows how copy/paste bugs can keep going... and going... and
> going..

There are some good typos out there.  Check out the News section at www.vbsight.com

News:
2004-05-27
Having problems with FrontPage.
Please bare with me. I should have
something new soon.

Bare with me?  Any takers yet<g>?

JEdgar

> Try... GetForegroundWindow and GetWindowText or post the declarations
> your using for the others <g>
Ken Halter - 31 Aug 2004 15:15 GMT
> There are some good typos out there.  Check out the News section at www.vbsight.com
>
[quoted text clipped - 5 lines]
>
> Bare with me?  Any takers yet<g>?

Yeah... the 'something new soon' part *must* be a typo <g>

> JEdgar

Signature

Ken Halter - MS-MVP-VB - http://www.vbsight.com
Please keep all discussions in the groups..

 
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



©2009 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.