Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > API > [VB6] - detecting code window


Reply
 
Thread Tools Display Modes
  #1  
Old 04-09-2012, 01:15 PM
Cambalinho_83's Avatar
Cambalinho_83 Cambalinho_83 is offline
Senior Contributor
 
Join Date: Feb 2008
Location: somewhere in space
Posts: 1,177
Default [VB6] - detecting code window


using api functions in a timer i can see what windows are activated, getting their caption. but i'm having problem to complete the code:
in a timer:
Code:
If IsCodeWindowActivated = True Then tmrIDEScrollClick.Enabled = False
in a module:
Code:
Public Function IsCodeWindowActivated() As Boolean
    Dim lngActivatedWindow As Long
    Dim lngtest As Long
    
    lngActivatedWindow = GetActiveWindow
    
    EnumChildWindows lngActivatedWindow, AddressOf EnumChildProc, 0
    
End Function

Private Function EnumChildProc(ByVal hwnd As Long, ByVal lParam As Long) As Long
    'On Error Resume Next
    Dim slength As Long, wintext As String ' title bar text length and buffer
    Dim retval As Long ' return value
    Dim buffer As String
    Static winnum As Integer ' counter keeps track of how many windows have been enumerated

    winnum = winnum + 1 ' one more window enumerated....
    slength = GetWindowTextLength(hwnd) + 1 ' get length of title bar text
    buffer = Space(slength) ' make room in the buffer
    retval = GetWindowText(hwnd, buffer, slength) ' get title bar text
    
    If Left(buffer, slength - 1) = "Cambalinho" Then
        IsCodeWindowActivated = True
    Else
        IsCodeWindowActivated = False
    End If
    EnumChildProc = 1 ' return value of 1 means continue enumeration
End Function
(forget the Cambalinho string)
my objective is testing if the code window is activated or geted focus. can anyone advice me?
Reply With Quote
  #2  
Old 04-18-2012, 02:19 PM
Cambalinho_83's Avatar
Cambalinho_83 Cambalinho_83 is offline
Senior Contributor
 
Join Date: Feb 2008
Location: somewhere in space
Posts: 1,177
Default

heres how detect the focus window:
Code:
Private Declare Function GetWindowText Lib "user32.dll" Alias _
"GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As _
String, ByVal cch As Long) As Long
Private Declare Function GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" (ByVal hwnd As Long) As Long
Private Declare Function GetFocus Lib "user32.dll" () As Long

Public Function IsCodeWindowActivated() As Boolean
    Dim lngActivatedWindow As Long
       
    lngActivatedWindow = GetFocus
    If GetWindowCaption(lngActivatedWindow) Like "*(Code)*" Then
        IsCodeWindowActivated = True
    Else
        IsCodeWindowActivated = False
    End If
End Function

Private Function GetWindowCaption(ByVal Handle As Long) As String
    ' Display the text of the title bar of window Form1
    Dim textlen As Long ' receives length of text of title bar
    Dim titlebar As String ' receives the text of the title bar
    Dim slength As Long ' receives the length of the returned string

    ' Find out how many characters are in the window's title bar
    textlen = GetWindowTextLength(Handle)
    titlebar = Space(textlen + 1) ' make room in the buffer, allowing for the terminating null character
    slength = GetWindowText(Handle, titlebar, textlen + 1) ' read the text of the window
    titlebar = Left(titlebar, slength) ' extract information from the buffer
    GetWindowCaption = titlebar
End Function
thanks
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->