Jump to content

_TargetQueryStyles()


quaizywabbit
 Share

Recommended Posts

Have your way with Window or Control Styles/Exstyles...

#include-once
#Region _TargetQueryStyles
;===============================================================================
;
; Function Name:    _TargetQueryStyles()
; Description:      Retrieves/Sets/Unsets/Toggles/Replaces Styles and/or Exstyles of 'targeted' control/window
;                   When called with no 'action' verb it returns the current Styles/Exstyles for the window/control
; Parameter(s):     $title                - Window Title
;                   $text[optional]       - Window Text
;                   $controlid[optional]  - ControlId
;                   $action[optional]     - "set", "unset","toggle", and "replace"
;                   $Bool[optional]       - 1 to Update window/control when finished (default = 0 no update)
;                   $Style[optional]      - New window style (multiple styles can be BitOr'd)
;                    $ExStyle[optional]      - New window exstyle (multiple styles can be BitOr'd)
; Requirement(s):   #include <guiconstants.au3>
;                   AutoIt Version 3.1.66 Beta (or better)
; Return Value(s):  On success: [$action left blank]-returns an array with $array[0] as the current Style and $array[1] as the current Exstyle
;                    If style and exstyle are changed the function will return an array
;                   with $Array[0] as the previous style and
;                    $Array[1] as the previous exstyle
;                   On Error:affected array element returns 0, error flag set to 1 if Style, 2 if ExStyle.
;                   MsgBox displayed for either.
; Author(s):        Chase/Xenogis- - -Modified by Quaizywabbit (Many Thanks to Valik and Nutster for explaining Bitwise operations)
; Comments:         can only do a single 'verb' during each call, so required Style/Exstyle combinations may require
;                   additional _TargetQueryStyles() calls with the last call setting $Bool to 1 to update the 'target'
; UserCallTip:
#cs
    _TargetQueryStyles($title[, $text[, $controlid[, $action "set|unset|toggle|replace"[, Update"1 = yes/0 = no"[, $style[, $exstyle]]]]]])
#ce
;===============================================================================
Func _TargetQueryStyles($title, $text = 0, $controlid = 0, $action = 0, $Bool = 0, $style = -1, $exstyle = -1)
    Local $hWnd
    WinWait($title)
    $hWnd = WinGetHandle($title, $text)
    If Not ($controlid = 0) Then $hWnd = ControlGetHandle($title, $text, $controlid)
#region Beta IsHwnd
#cs <== remove if using Beta .66 or better
    If Not IsHWnd ($hWnd) Then
        SetError(1)
        Return 0
        MsgBox(4096 + 48, "Target not found", "could not retrieve Hwnd")
    EndIf
#ce <== remove if using Beta .66 or better
#endregion
    Local $ostyle = DllCall("user32.dll", "long", "GetWindowLong", "hwnd", $hWnd, "int", -16);get existing Style
    Local $oexstyle = DllCall("user32.dll", "long", "GetWindowLong", "hwnd", $hWnd, "int", -20);get existing ExStyle
    Select
        Case $action = "set"
            If $style <> - 1 Then Local $scall = DllCall("user32.dll", "long", "SetWindowLong", "hwnd", $hWnd, "int", -16, "long", BitOR($ostyle[0], $style));add Style to old style
            If $exstyle <> - 1 Then Local $exscall = DllCall("user32.dll", "long", "SetWindowLong", "hwnd", $hWnd, "int", -20, "long", BitOR($oexstyle[0], $exstyle));add Exstyle to old exstyle
        Case $action = "unset"
            If $style <> - 1 Then Local $scall = DllCall("user32.dll", "long", "SetWindowLong", "hwnd", $hWnd, "int", -16, "long", BitAND($ostyle[0], BitNOT($style)));remove Style from old style
            If $exstyle <> - 1 Then Local $exscall = DllCall("user32.dll", "long", "SetWindowLong", "hwnd", $hWnd, "int", -20, "long", BitAND($oexstyle[0], BitNOT($exstyle)));remove Exstyle from old exstyle
        Case $action = "toggle"
            If $style <> - 1 Then Local $scall = DllCall("user32.dll", "long", "SetWindowLong", "hwnd", $hWnd, "int", -16, "long", BitXOR($ostyle[0], $style));Toggle Style(s) on or off
            If $exstyle <> - 1 Then Local $exscall = DllCall("user32.dll", "long", "SetWindowLong", "hwnd", $hWnd, "int", -20, "long", BitXOR($oexstyle[0], $exstyle));Toggle ExStyle(s) on or off
        Case $action = "replace"
            If $style <> - 1 Then Local $scall = DllCall("user32.dll", "long", "SetWindowLong", "hwnd", $hWnd, "int", -16, "long", $style);replace Style
            If $exstyle <> - 1 Then Local $exscall = DllCall("user32.dll", "long", "SetWindowLong", "hwnd", $hWnd, "int", -20, "long", $exstyle);replace Exstyle
        Case Else
            Dim $ret[2]
            $ret[0] = $ostyle[0]
            $ret[1] = $oexstyle[0]
            Return $ret
    EndSelect
    Dim $return[2]
    If $style <> - 1 And $scall[0] <> $ostyle[0] Then
        SetError(1)
        $return[0] = 0
        MsgBox(4096 + 48, "Error setting Style", "Please check your Style settings and try again")
    ElseIf $exstyle <> - 1 And $exscall[0] <> $oexstyle[0] Then
        SetError(2)
        $return[1] = 0
        MsgBox(4096 + 48, "Error setting ExStyle", "Please check your ExStyle settings and try again")
    Else
        If $style <> - 1 Then
            $return[0] = $scall[0]
        Else
            $return[0] = $ostyle[0]
        EndIf
        If $exstyle <> - 1 Then
            $return[1] = $exscall[0]
        Else
            $return[1] = $oexstyle[0]
        EndIf
    EndIf
    If $Bool = 1 Then
        Const $SWP_NOMOVE = 0x0002, $SWP_NOSIZE = 0x0001, $SWP_NOZORDER = 0x0004, $SWP_FRAMECHANGED = 0x0020;from Winuser.h
        DllCall("user32.dll", "long", "SetWindowPos", "hwnd", $hWnd, "hwnd", $hWnd, "int", 0, "int", 0, "int", 0, "int", 0, _
                "long", BitOR($SWP_NOMOVE, $SWP_NOSIZE, $SWP_NOZORDER, $SWP_FRAMECHANGED))
    EndIf
    Return $return
EndFunc  ;==>_TargetQueryStyles
#EndRegion

For Windows and Controls: made it stand-alone (no ANYGUI required) :whistle:

Edited by quaizywabbit
[u]Do more with pre-existing apps![/u]ANYGUIv2.8
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...