Announcement

Collapse

Forum Guidelines

This forum is for finished source code that is working properly. If you have questions about this or any other source code, please post it in one of the Discussion Forums, not here.
See more
See less

Identify windows that may be covering yours

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Identify windows that may be covering yours


    Code:
    'Compilable Example:
    'Identify Windows that may be covering yours
    
    #COMPILE EXE
    #DIM ALL
    #INCLUDE "win32api.inc"
    %IDC_ListView = 500
    
    'Modified by Jim Fritts on 20 MAR 2017
    
    'Original Program by Gary Beene
    'Thanks to Gary's code the listview provides the User an idea of how many parent
    'windows are curently running.
    
    'Thanks to my filter you get this:
    'GOAL:
    'Identify open visible (non-iconized) parent windows and get their
    'Z-Order
    'Handle
    'Class Name
    'Description
    'Location
    'Size
    'Output Data to a semicolon separated global array string which can be used to
    'determine if my program is being eclipsed by any open window/s.
    
    GLOBAL gsEnumWindows AS STRING
    
    TYPE WindowList
       hwnd AS DWORD
       Parent AS LONG
       R AS RECT
    END TYPE
    
    GLOBAL hDlg AS DWORD
    GLOBAL iCount  AS LONG
    GLOBAL wList() AS WindowList
    
    FUNCTION PBMAIN() AS LONG
        REDIM wList(5000)
        DIALOG NEW PIXELS, 0, "Enumerate Windows",300,300,800,500,%WS_OVERLAPPEDWINDOW TO hDlg
        DIALOG SHOW MODAL hDlg CALL DlgProc
    END FUNCTION
    
    CALLBACK FUNCTION DlgProc() AS LONG
       LOCAL iResult AS LONG
       SELECT CASE CB.MSG
          CASE %WM_INITDIALOG
             CreateListView
             iResult = EnumWindows(CODEPTR(ParentCallback), 0&)
             REDIM PRESERVE wList(iCount)
             FillListView
    '         ListView Sort hDlg, %IDC_ListView, 1, Descend
             DIALOG SET TEXT hDlg, "Enumerate Windows:  " + STR$(iCount) + " found"
          CASE %WM_SIZE
             CONTROL SET SIZE hDlg, %IDC_ListView, LO(WORD,CB.LPARAM)-20, HI(WORD,CB.LPARAM)-20
       END SELECT
    END FUNCTION
    
    FUNCTION ParentCallback (BYVAL hWndChild AS LONG, lRaram AS LONG) AS LONG
        LOCAL szParentClass AS ASCIIZ * %MAX_PATH
        LOCAL aResult       AS LONG
    
        aResult = GetClassName(hWndChild, szParentClass, SIZEOF(szParentClass))
        INCR iCount
        wList(iCount).Parent = 1
        wList(iCount).hwnd = hWndChild
    
        SELECT CASE UCASE$(szParentClass)
           CASE "COMBOBOX", "COMBOBOXEX32", "SYSIPADDRESS32", "SYSLISTVIEW32", "SYSTABCONTROL32", "SYSDATATIMEPICK32"
             'do nothing
           CASE ELSE
             'IF IsWindowVisible(hWndChild) THEN
             '    iResult = EnumChildWindows(hWndChild, CODEPTR(ChildCallback), 0&)
             'END IF
        END SELECT
        FUNCTION = 1
    END FUNCTION
    
    'FUNCTION ChildCallback (BYVAL hWndChild AS LONG, lRaram AS LONG) AS LONG
    '    INCR iCount
    '    wList(iCount).hwnd = hWndChild
    '    FUNCTION = 1
    'END FUNCTION
    
    SUB CreateListView
        'create control
        CONTROL ADD LISTVIEW, hDlg, %IDC_ListView, "", 10,10,175,75   '225
        'columns               hdlg, id&, col, "test", width, format
        LISTVIEW INSERT COLUMN hDlg, %IDC_ListView, 1, "#", 50, 0
        LISTVIEW INSERT COLUMN hDlg, %IDC_ListView, 2, "hWnd", 75, 0
        LISTVIEW INSERT COLUMN hDlg, %IDC_ListView, 3, "Level", 200, 0
        LISTVIEW INSERT COLUMN hDlg, %IDC_ListView, 4, "Class", 200, 0
        LISTVIEW INSERT COLUMN hDlg, %IDC_ListView, 5, "Text", 100, 0
        LISTVIEW INSERT COLUMN hDlg, %IDC_ListView, 6, "x1", 50, 0
        LISTVIEW INSERT COLUMN hDlg, %IDC_ListView, 7, "y1", 50, 0
        LISTVIEW INSERT COLUMN hDlg, %IDC_ListView, 8, "x2", 50, 0
        LISTVIEW INSERT COLUMN hDlg, %IDC_ListView, 9, "y2", 50, 0
    
        LISTVIEW SET STYLEXX hDlg, %IDC_ListView, %LVS_EX_GRIDLINES OR %LVS_EX_FULLROWSELECT
        LISTVIEW SET STYLEXX hDlg, %IDC_ListView, %LVS_EX_FULLROWSELECT
    END SUB
    
    SUB FillListview
       LOCAL i, iResult AS LONG
       LOCAL szClass, szText AS ASCIIZ * %MAX_PATH
       DIM ENUMW(1 TO UBOUND(wList))      AS STRING
       LOCAL TrackEnum   AS LONG
       LOCAL Xi AS LONG
    
       FOR i = 0 TO UBOUND(wList)
          iResult = GetWindowRect(wList(i).hwnd, wList(i).R)   'save bounding dimensions
          iResult = GetClassName(wList(i).hwnd, szClass, SIZEOF(szClass))
          iResult = GetWindowText(wList(i).hwnd, szText, SIZEOF(szText))
          LISTVIEW INSERT ITEM hDlg, %IDC_ListView, i, 0, STR$(i)
    
          IF UCASE$(szClass) <> "" AND _
              UCASE$(szClass) <> "EDGEUIINPUTTOPWNDCLASS" AND _
              UCASE$(szClass) <> "PROGMAN" AND _
              wList(i).R.nLeft >= 0 AND _
              wList(i).R.nTop >= 0 AND _
              wList(i).R.nRight >= 0 AND _
              wList(i).R.nBottom >= 0 AND _
              ISFALSE(wList(i).R.nLeft = 0 AND wList(i).R.nTop = 0 AND wList(i).R.nRight = 0 AND wList(i).R.nBottom = 0) AND _
              ISFALSE(wList(i).R.nLeft = 1 AND wList(i).R.nTop = 1 AND wList(i).R.nRight = 1 AND wList(i).R.nBottom = 1) AND _
              wList(i).Parent = 1 AND _
              IsWindowVisible(wList(i).hwnd) = 1 THEN
    
              IF UCASE$(szClass) = "APPLICATIONFRAMEWINDOW" THEN  'USED FOR EDGE
                  SELECT CASE TRIM$(szText)
                      CASE ""
                          'BLOCK THIS
                          GOTO PassOver01
    
                  END SELECT
              END IF
              IF UCASE$(szClass) = "WORKERW" THEN
                  SELECT CASE TRIM$(szText)
                      CASE ""
                          'BLOCK THIS
                          GOTO PassOver01
    
                  END SELECT
              END IF
              IF UCASE$(szClass) = "QWIDGET" THEN
                  SELECT CASE UCASE$(TRIM$(szText))
                      CASE <> "GOOGLE EARTH"
                          'BLOCK THIS
                          GOTO PassOver01
    
                  END SELECT
              END IF
              INCR TrackEnum
              ENUMW(TrackEnum) = TRIM$(STR$(TrackEnum)) + ";" + _
                  TRIM$(STR$(wList(i).hwnd)) + ";" + _
                  TRIM$(szClass) + ";" + _
                  TRIM$(PARSE$(szText, "-", 1)) + ";" + _
                  TRIM$(STR$(wList(i).R.nLeft)) + ";" + _
                  TRIM$(STR$(wList(i).R.nTop)) + ";" + _
                  TRIM$(STR$(wList(i).R.nRight)) + ";" + _
                  TRIM$(STR$(wList(i).R.nBottom))
    
              LISTVIEW SET TEXT hDlg, %IDC_ListView, TrackEnum,2, STR$(wList(i).hwnd)
              'LISTVIEW SET TEXT hDlg, %IDC_ListView, TrackEnum,3, IIF$(wList(i).Parent,"Parent:","    Child:")  'ONLY LOOKING AT PARENTS
              LISTVIEW SET TEXT hDlg, %IDC_ListView, TrackEnum,4, szClass
              LISTVIEW SET TEXT hDlg, %IDC_ListView, TrackEnum,5, szText
              LISTVIEW SET TEXT hDlg, %IDC_ListView, TrackEnum,6, STR$(wList(i).R.nLeft)
              LISTVIEW SET TEXT hDlg, %IDC_ListView, TrackEnum,7, STR$(wList(i).R.nTop)
              LISTVIEW SET TEXT hDlg, %IDC_ListView, TrackEnum,8, STR$(wList(i).R.nRight)
              LISTVIEW SET TEXT hDlg, %IDC_ListView, TrackEnum,9, STR$(wList(i).R.nBottom)
    
          END IF
          PassOver01:
       NEXT i
       gsEnumWindows = ""
       FOR Xi = 1 TO TrackEnum
           gsEnumWindows = gsEnumWindows + ENUMW(Xi) + $CRLF
       NEXT Xi
       ? gsEnumWindows
    END SUB
    
    '******************************************************************************
    'The End
    '******************************************************************************

  • #2
    Discussion is here

    Comment

    Working...
    X