#include <GUIConstantsEx.au3>
#include <EditConstants.au3>
#include <ComboConstants.au3>
#include <WindowsConstants.au3>
Opt('MustDeclareVars', 1)
Opt('TrayMenuMode', 1)
Global $sTitle = 'Цвет по координатам', $iMaxX, $iMaxY, $fWin, $fClient, _
$hGui, $nRadioDesktop, $nRadioWindow, $nRadioOptWin, $nRadioOptClient, _
$nButtonRefresh, $nComboTitle, $nInputSize, $nInputX, $nInputY, $nButtonGet, _
$nInputColor, $nButtonCopy
If WinExists($sTitle & '{[/@$@\]}') Then Exit
AutoItWinSetTitle($sTitle & '{[/@$@\]}')
$hGui = GUICreate($sTitle, 350, 150, -1, -1, -1, $WS_EX_TOPMOST)
GUICtrlCreateGroup('Объект поиска:', 5, 5, 100, 65)
$nRadioDesktop = GUICtrlCreateRadio('Монитор', 15, 20, 80, 20)
GUICtrlSetState(-1, $GUI_CHECKED)
$nRadioWindow = GUICtrlCreateRadio('Окно', 15, 45, 80, 20)
GUICtrlCreateGroup('', -99, -99, 1, 1)
GUICtrlCreateGroup('Поиск относительно:', 110, 5, 130, 65)
$nRadioOptWin = GUICtrlCreateRadio('Окна', 125, 20, 100, 20)
$nRadioOptClient = GUICtrlCreateRadio('Клиентской части', 125, 45, 110, 20)
GUICtrlCreateGroup('', -99, -99, 1, 1)
$nButtonRefresh = GUICtrlCreateButton('P', 5, 89, 22, 22)
GUICtrlSetFont(-1, 11, 600, -1, 'Wingdings 3')
GUICtrlSetCursor(-1, 0)
GUICtrlSetTip(-1, 'Обновить список окон')
GUICtrlCreateLabel('Заголовок окна:', 5, 75, 235, 14, $ES_CENTER)
$nComboTitle = GUICtrlCreateCombo('', 32, 90, 208, 20, BitOR($CBS_DROPDOWNLIST, $CBS_AUTOHSCROLL))
GUICtrlSetTip(-1, 'Выбрать окно')
GUICtrlSetCursor(-1, 0)
GUICtrlCreateLabel('Размеры окна:', 250, 75, 95, 14, $ES_CENTER)
$nInputSize = GUICtrlCreateInput('', 250, 90, 95, 20, BitOR($ES_CENTER, $ES_READONLY))
GUICtrlCreateGroup('Координаты:', 245, 5, 100, 65)
GUICtrlCreateLabel('X:', 255, 23, 14, 14)
GUICtrlCreateLabel('Y:', 255, 48, 14, 14)
$nInputX = GUICtrlCreateInput(0, 270, 20, 65, 20)
GUICtrlSetFont(-1, 10)
$nInputY = GUICtrlCreateInput(0, 270, 45, 65, 20)
GUICtrlSetFont(-1, 10)
GUICtrlCreateGroup('', -99, -99, 1, 1)
$nButtonGet = GUICtrlCreateButton('Получить', 250, 119, 95, 22)
GUICtrlSetTip(-1, 'Получить цвет (RGB)')
GUICtrlSetCursor(-1, 0)
$nInputColor = GUICtrlCreateInput('', 110, 120, 130, 20, BitOR($ES_CENTER, $ES_READONLY))
GUICtrlSetFont(-1, 10)
$nButtonCopy = GUICtrlCreateButton('Копировать', 5, 119, 95, 22)
GUICtrlSetTip(-1, 'Копировать цвет')
GUICtrlSetCursor(-1, 0)
_GUICtrl_Dis_En(0)
_Get_Size()
GUISetState()
GUIRegisterMsg($WM_COMMAND, 'WM_COMMAND')
While 1
Switch GUIGetMsg()
Case $GUI_EVENT_CLOSE
Exit
Case $nButtonRefresh
_Get_Windows()
_Get_Size()
_Check_XY()
Case $nComboTitle
_Get_Size()
_Check_XY()
Case $nRadioOptWin
Opt('PixelCoordMode', 0)
$fClient = False
_Get_Size()
_Check_XY()
Case $nRadioOptClient
Opt('PixelCoordMode', 2)
$fClient = True
_Get_Size()
_Check_XY()
Case $nRadioDesktop
Opt('PixelCoordMode', 1)
$fWin = False
_GUICtrl_Dis_En(0)
GUICtrlSetState($nRadioOptWin, $GUI_UNCHECKED)
GUICtrlSetState($nRadioOptClient, $GUI_UNCHECKED)
GUICtrlSetData($nComboTitle, '')
_Get_Size()
_Check_XY()
Case $nRadioWindow
$fWin = True
_Get_Windows()
_GUICtrl_Dis_En(1)
GUICtrlSetState($nRadioOptWin, $GUI_CHECKED)
$fClient = False
Opt('PixelCoordMode', 0)
_Get_Size()
_Check_XY()
Case $nButtonGet
GUISetState(@SW_HIDE)
_Get_Color()
GUISetState()
Case $nButtonCopy
ClipPut(GUICtrlRead($nInputColor))
EndSwitch
WEnd
Func _Get_Color()
Local $s_Title, $h_Wnd, $i_X, $i_Y, $i_Color, $h_Active
$i_X = GUICtrlRead($nInputX)
$i_Y = GUICtrlRead($nInputY)
If Not $i_X Or Not $i_Y Then
GUICtrlSetData($nInputColor, 'Ошибка')
Return
EndIf
$i_X = Number($i_X)
$i_Y = Number($i_Y)
If Not $fWin Then
$i_Color = PixelGetColor($i_X, $i_Y)
GUICtrlSetData($nInputColor, '0x' & Hex($i_Color, 6))
Return
EndIf
$s_Title = GUICtrlRead($nComboTitle)
If $s_Title And WinExists($s_Title) Then
$h_Wnd = WinGetHandle($s_Title)
If Not $h_Wnd Then
GUICtrlSetData($nInputColor, 'Ошибка')
Return
EndIf
$h_Active = WinGetHandle('[ACTIVE]')
If Not WinActive($h_Wnd) Then WinActivate($h_Wnd)
If Not WinWaitActive($h_Wnd, '', 3) Then
GUICtrlSetData($nInputColor, 'Ошибка')
Else
$i_Color = PixelGetColor($i_X, $i_Y, $h_Wnd)
GUICtrlSetData($nInputColor, '0x' & Hex($i_Color, 6))
EndIf
If $h_Active Then
WinActivate($h_Active)
EndIf
Else
GUICtrlSetData($nInputColor, 'Ошибка')
EndIf
EndFunc ;==>_Get_Color
Func _Get_Size()
Local $s_Title, $a_Size
$iMaxX = 0
$iMaxY = 0
If Not $fWin Then
$iMaxX = @DesktopWidth
$iMaxY = @DesktopHeight
Else
$s_Title = GUICtrlRead($nComboTitle)
If $s_Title And WinExists($s_Title) Then
If Not BitAND(WinGetState($s_Title), 16) Then
If $fClient Then
$a_Size = WinGetClientSize($s_Title)
If Not @error Then
$iMaxX = $a_Size[0]
$iMaxY = $a_Size[1]
EndIf
Else
$a_Size = WinGetPos($s_Title)
If Not @error Then
$iMaxX = $a_Size[2]
$iMaxY = $a_Size[3]
EndIf
EndIf
EndIf
EndIf
EndIf
If Not $iMaxX Or Not $iMaxY Then
GUICtrlSetData($nInputSize, 'Ошибка')
Else
GUICtrlSetData($nInputSize, $iMaxX & ' x ' & $iMaxY)
EndIf
EndFunc ;==>_Get_Size
Func _GUICtrl_Dis_En($i_Flag)
Local $s_State = $GUI_DISABLE
If $i_Flag Then $s_State = $GUI_ENABLE
For $i = $nRadioOptWin To $nComboTitle
GUICtrlSetState($i, $s_State)
Next
EndFunc ;==>_GUICtrl_Dis_En
Func _Get_Windows()
Local $a_List, $i_Count, $i_State, $s_FirstString, $s_String_Title = '|'
$a_List = WinList('[REGEXPCLASS:[^(Explore|Cabinet)WClassProgram Manager]]')
If Not $a_List[0][0] Then
TrayTip($sTitle, 'Ошибка', 3, 3)
Return
EndIf
For $i = 1 To $a_List[0][0]
If $a_List[$i][0] Then
$i_State = WinGetState($a_List[$i][1])
If BitAND($i_State, 2) And Not BitAND($i_State, 16) Then
If $a_List[$i][1] <> $hGui Then
$i_Count += 1
If Not $s_FirstString Then $s_FirstString = $a_List[$i][0]
$s_String_Title &= $a_List[$i][0] & '|'
EndIf
EndIf
EndIf
Next
If $i_Count Then
$s_String_Title = StringTrimRight($s_String_Title, 1)
GUICtrlSetData($nComboTitle, $s_String_Title, $s_FirstString)
Return
Else
TrayTip($sTitle, 'Ошибка', 3, 3)
Return
EndIf
EndFunc ;==>_Get_Windows
Func _Check_XY()
Local $sStringX, $sStringY
GUICtrlSetData($nInputColor, '')
$sStringX = GUICtrlRead($nInputX)
If $sStringX And Not StringIsDigit($sStringX) Then
GUICtrlSetData($nInputX, 0)
Else
If Number($sStringX) > $iMaxX Then
GUICtrlSetData($nInputX, $iMaxX)
EndIf
EndIf
$sStringY = GUICtrlRead($nInputY)
If $sStringY And Not StringIsDigit($sStringY) Then
GUICtrlSetData($nInputY, 0)
Else
If Number($sStringY) > $iMaxY Then
GUICtrlSetData($nInputY, $iMaxY)
EndIf
EndIf
EndFunc ;==>_Check_XY
Func WM_COMMAND($hWnd, $imsg, $iwParam, $ilParam)
Local $nNotifyCode, $nID
$nNotifyCode = BitShift($iwParam, 16)
$nID = BitAND($iwParam, 0xFFFF)
Switch $hWnd
Case $hGui
Switch $nNotifyCode
Case $EN_CHANGE
Switch $nID
Case $nInputX, $nInputY
_Check_XY()
EndSwitch
EndSwitch
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc ;==>WM_COMMAND