Announcement

Collapse
No announcement yet.

WM_GetTitleBarInfoEx

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

  • WM_GetTitleBarInfoEx

    Code:
    #COMPILE EXE
    #DIM ALL
    #INCLUDE "Win32Api.inc"
    
    %WM_GETTITLEBARINFOEX = &H033F???
    
    TYPE TITLEBARINFOEX DWORD
       cbSize                       AS DWORD
       rcTitleBar                   AS RECT
       rgstate(%CCHILDREN_TITLEBAR) AS DWORD 'CCHILDREN_TITLEBAR = 5
       rgrect(%CCHILDREN_TITLEBAR)  AS RECT
    END TYPE
    
    GLOBAL hDlg AS DWORD
    
    %LabelInfo = 101
    '______________________________________________________________________________
    
    FUNCTION StateInfo(s AS DWORD) AS STRING
    
     '0 The title bar itself, 1 Reserved, 2 Minimize button, 3 Maximize button, 4 Help button, 5 Close button.
     'STATE_SYSTEM_OFFSCREEN mean the element has no visible representation.
     FUNCTION = $TAB & "(" & HEX$(s, 8) & ") " & _
                IIF$((s AND %STATE_SYSTEM_PRESSED),     "PRESSED",     "pressed")     & ", " & _
                IIF$((s AND %STATE_SYSTEM_UNAVAILABLE), "UNAVAILABLE", "unavailable") & ", " & _
                IIF$((s AND %STATE_SYSTEM_OFFSCREEN),   "OFFSCREEN",   "offscreen")   & ", " & _
                IIF$((s AND %STATE_SYSTEM_INVISIBLE),   "INVISIBLE",   "invisible")   & ", " & _
                IIF$((s AND %STATE_SYSTEM_FOCUSABLE),   "FOCUSABLE",   "focusable")
    END FUNCTION
    '______________________________________________________________________________
    
    FUNCTION RectInfo(r AS RECT) AS STRING
    
     MapWindowPoints(%HWND_DESKTOP, hDlg, BYVAL VARPTR(r), 2) 'Relative to client area instead of desktop area
     '.rgrect(0) and .rgrect(1) are reserved.
     FUNCTION = $TAB & "      " & STR$(r.nRight - r.nLeft) & " x" & _
                STR$(r.nBottom - r.nTop) & _
                $TAB & " at " & STR$(r.nLeft) & "," & STR$(r.nTop)
    
    END FUNCTION
    '______________________________________________________________________________
    
    CALLBACK FUNCTION DlgProc
     LOCAL TBI AS TITLEBARINFOEX
    
     SELECT CASE CBMSG
    
       CASE %WM_SETCURSOR 'hwnd, nHittest = LOWORD(lParam), wMouseMsg = HIWORD(lParam).
    
         TBI.cbSize = SIZEOF(TITLEBARINFOEX)
         IF SendMessage(hDlg, %WM_GETTITLEBARINFOEX, 0, VARPTR(TBI)) THEN
           CONTROL SET TEXT hDlg, %LabelInfo, _
           "TitleBar       "        & RectInfo(TBI.rcTitleBar)  & $CRLF & _
           "Minimize button"        & RectInfo(TBI.rgrect(2))   & $CRLF & _
           "Maximize button"        & RectInfo(TBI.rgrect(3))   & $CRLF & _
           "Help button    "        & RectInfo(TBI.rgrect(4))   & $CRLF & _
           "Close button   "        & RectInfo(TBI.rgrect(5))   & $CRLF & _
           ""                                                   & $CRLF & _
           "TitleBar state        " & StateInfo(TBI.rgstate(0)) & $CRLF & _
           "Minimize button state " & StateInfo(TBI.rgstate(2)) & $CRLF & _
           "Maximize button state " & StateInfo(TBI.rgstate(3)) & $CRLF & _
           "Help button state     " & StateInfo(TBI.rgstate(4)) & $CRLF & _
           "Close button state    " & StateInfo(TBI.rgstate(5))
         END IF
    
      END SELECT
    
    END FUNCTION
    '______________________________________________________________________________
    
    FUNCTION PBMAIN()
     LOCAL hIcon AS DWORD
    
     DIALOG NEW %HWND_DESKTOP, "WM_GetTitleBarInfoEx", , , 350, 100, %WS_CAPTION OR _
     %WS_MINIMIZEBOX OR %WS_MAXIMIZEBOX OR %WS_SYSMENU OR %WS_THICKFRAME, 0 TO hDlg
    
     hIcon = ExtractIcon(GetModuleHandle(""), "Shell32.dll", 159)
     SetClassLong(hDlg, %GCL_HICON, hIcon)
     SendMessage(hDlg, %WM_SETICON, %ICON_SMALL, hIcon)
    
     CONTROL ADD LABEL, hDlg, %LabelInfo, "TITLEBARINFOEX", 5, 5, 340, 90
    
     DIALOG SHOW MODAL hDlg CALL DlgProc
    
     DestroyIcon(hIcon)
    
    END FUNCTION
    '______________________________________________________________________________
    '
    Last edited by Pierre Bellisle; 18 May 2021, 10:04 PM.
Working...
X