﻿;-- TIME_STAMP   2021-02-13 12:19:09   v 0.1

#include-once
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>



; CONSTANTS: (G)ui(C)reated(C)ontrol ordered by Classname
;                                    FUNCTION					CLASS
Global Const $GCC_NONE     = 0
Global Const $GCC_BUTTON   = 1     ; GUICtrlCreateButton()		Button
Global Const $GCC_CHECKBOX = 2     ; GUICtrlCreateCheckbox()	Button
Global Const $GCC_GROUP    = 3     ; GUICtrlCreateGroup()		Button
Global Const $GCC_RADIO    = 4     ; GUICtrlCreateRadio()		Button
Global Const $GCC_COMBO    = 5     ; GUICtrlCreateCombo()		ComboBox
Global Const $GCC_EDIT     = 6     ; GUICtrlCreateEdit()		Edit
Global Const $GCC_INPUT    = 7     ; GUICtrlCreateInput()		Edit
Global Const $GCC_LIST     = 8     ; GUICtrlCreateList()		ListBox
Global Const $GCC_PROGRESS = 9     ; GUICtrlCreateProgress()	msctls_progress32
Global Const $GCC_SLIDER   = 10    ; GUICtrlCreateSlider()		msctls_trackbar32
Global Const $GCC_UPDOWN   = 11    ; GUICtrlCreateUpdown()		msctls_updown32
Global Const $GCC_GRAPHIC  = 12    ; GUICtrlCreateGraphic()		Static
Global Const $GCC_ICON     = 13    ; GUICtrlCreateIcon()		Static
Global Const $GCC_LABEL    = 14    ; GUICtrlCreateLabel()		Static
Global Const $GCC_PIC      = 15    ; GUICtrlCreatePic()			Static
Global Const $GCC_AVI      = 16    ; GUICtrlCreateAvi()			SysAnimate32
Global Const $GCC_DATE     = 17    ; GUICtrlCreateDate()		SysDateTimePick32
Global Const $GCC_LISTVIEW = 18    ; GuiCtrlCreateListView()	SysListView32
Global Const $GCC_MONTHCAL = 19    ; GUICtrlCreateMonthCal()	SysMonthCal32
Global Const $GCC_TAB      = 20    ; GUICtrlCreateTab()			SysTabControl32
Global Const $GCC_TREEVIEW = 21    ; GUICtrlCreateTreeView()	SysTreeView32

Global $__gaGCC_CLASSES[][2] = [['None_Class_detected',''], _  ; [[Class,Au3-Name (part from "GuiCtrlCreate..")]]
['Button','Button'],['Button','Checkbox'],['Button','Group'],['Button','Radio'],['ComboBox','Combo'], _
['Edit','Edit'],['Edit','Input'],['ListBox','List'],['msctls_progress32','Progress'],['msctls_trackbar32','Slider'], _
['msctls_updown32','Updown'],['Static','Graphic'],['Static','Icon'],['Static','Label'],['Static','Pic'], _
['SysAnimate32','Avi'],['SysDateTimePick32','Date'],['SysListView32','ListView'],['SysMonthCal32','MonthCal'], _
['SysTabControl32','Tab'],['SysTreeView32','TreeView']]


Func _GuiCtrlGetInfo($_ID)
	Local $tInfo = DllStructCreate('int ID;hwnd hWnd;char Class[32];char Au3Name[32];int Au3Type;int Style;int ExStyle;')
	$tInfo.ID = $_ID
	$tInfo.hWnd = GUICtrlGetHandle($_ID)
	Local $aResult = DllCall("user32.dll", "int", "GetClassName", "hwnd", $tInfo.hWnd, "str", "", "int", 4096)
	If @error Or Not $aResult[0] Then
		$tInfo.Class = "None_Class_detected"
		Return SetError(@error, @extended, $tInfo)
	Else
		$tInfo.Class = StringStripWS($aResult[2], 2)
	EndIf
	Local $aStyle = _CtrlGetStyle($tInfo.hWnd)
	$tInfo.Style = $aStyle[0]
	$tInfo.ExStyle = $aStyle[1]

	Switch $tInfo.Class
		Case "Button"
			If BitAND($tInfo.Style, $BS_GROUPBOX) = $BS_GROUPBOX Then
				$tInfo.Au3Type = $GCC_GROUP
			ElseIf BitAND($tInfo.Style, $BS_3STATE) = $BS_3STATE Or _
				   BitAND($tInfo.Style, $BS_AUTO3STATE) = $BS_AUTO3STATE Or _
				   BitAND($tInfo.Style, $BS_AUTOCHECKBOX) = $BS_AUTOCHECKBOX Or _
				   BitAND($tInfo.Style, $BS_CHECKBOX) = $BS_CHECKBOX Then
				$tInfo.Au3Type = $GCC_CHECKBOX
			ElseIf BitAND($tInfo.Style, $BS_RADIOBUTTON) = $BS_RADIOBUTTON Or _
				   BitAND($tInfo.Style, $BS_AUTORADIOBUTTON) = $BS_AUTORADIOBUTTON Then
				$tInfo.Au3Type = $GCC_RADIO
			Else
				$tInfo.Au3Type = $GCC_BUTTON
			EndIf
		Case "Edit"
			If BitAND($tInfo.Style, $ES_AUTOVSCROLL) = $ES_AUTOVSCROLL Then
				$tInfo.Au3Type = $GCC_EDIT
			Else
				$tInfo.Au3Type = $GCC_INPUT
			EndIf
		Case "Static"
			If BitAND($tInfo.Style, $SS_ICON) = $SS_ICON Then
				$tInfo.Au3Type = $GCC_ICON
			ElseIf BitAND($tInfo.Style, $SS_BITMAP) = $SS_BITMAP Or _
				   BitAND($tInfo.Style, $SS_ENHMETAFILE) = $SS_ENHMETAFILE Then
				$tInfo.Au3Type = $GCC_PIC
			; Label and Graphic can have as only style: $SS_NOTIFY
			ElseIf BitAND($tInfo.Style, $SS_NOTIFY) = $SS_NOTIFY Then
				; try to use a graphic function - if fails: it's a label
				Local $ret = GUICtrlSetGraphic($tInfo.ID, $GUI_GR_PIXEL, -1, -1)
				If $ret = 1 Then
					$tInfo.Au3Type = $GCC_GRAPHIC
				Else
					$tInfo.Au3Type = $GCC_LABEL
				EndIf
			EndIf
		Case Else
			For $i = 0 To UBound($__gaGCC_CLASSES) -1
				If $__gaGCC_CLASSES[$i][0] = $tInfo.Class Then
					$tInfo.Au3Type = $i
					ExitLoop
				EndIf
			Next
	EndSwitch

	$tInfo.Au3Name = $__gaGCC_CLASSES[$tInfo.Au3Type][1]
	Return $tInfo
EndFunc



; #FUNCTION# =======================================================================================
; Name...........: _CtrlGetStyle
; Description ...: Retrieves the Styles/ExStyles value(s) of the control.
; Syntax.........: _CtrlGetStyle($iControlID)
; Parameters ....: $iControlID - A valid control ID.
; Requirement(s).: v3.3.2.0 or higher
; Return values .: Success - Returns an Array[2] = [Style, ExStyle] with the Styles/ExStyles value(s).
;                  Failure - Returns an Array with -1 as the 0 & 1 Index's.
; Author ........: guinness & additional information from Melba23.
; Example........; Yes
;===================================================================================================
Func _CtrlGetStyle($iControlID)
    Local $aArray[2] = [-1, -1], $aExStyle, $aStyle, $hControl = $iControlID
	If Not IsHWnd($hControl) Then $hControl = GUICtrlGetHandle($iControlID)
    $aStyle = DllCall("user32.dll", "long", "GetWindowLong", "hwnd", $hControl, "int", 0xFFFFFFF0)
    If Not @error Then
        $aArray[0] = $aStyle[0]
    EndIf
    $aExStyle = DllCall("user32.dll", "long", "GetWindowLong", "hwnd", $hControl, "int", 0xFFFFFFEC)
    If Not @error Then
        $aArray[1] = $aExStyle[0]
    EndIf
    Return $aArray
EndFunc  ;==>_CtrlGetStyle