Здравствуйте!
Суть вопроса : Есть любое окно GUI и в нём указаны разные Checkbox`сы. Нужно, чтобы при нажатии на Checkbox снизу под Checkbox`ом появлялось окно ToolTip приблизительно такое
If Not IsDeclared("sToolTipAnswer") Then Local $sToolTipAnswer
$sToolTipAnswer = ToolTip("tresgfdsgfdsgfdsg",20,10,"643",0,1)
c разным тестом в зависимости от Checkbox`са.
Проблема в том что ToolTip работает по координатам экрана, а Checkbox имеет координаты самого окна GUI т.е. нужно определить координаты расположения самого Checkbox`са на экране и ниже уже вывести ToolTip. Нужно сделать приблизительно похожее на команду GUICtrlSetTip.
В справке _WinAPI_ScreenToClient. Там готовый пример. Есть ещё _WinAPI_ClientToScreen.
AZJIO, у меня видимо справка старая на русском языке, не могли бы Вы мне ссылочку дать ?
madmasles
19-05-2014, 13:39
у меня видимо справка старая на русском языке, не могли бы Вы мне ссылочку дать ? »
Развитие русской справки (http://autoit-script.ru/index.php/topic,10070.0.html)
Можно примерно так сделать.#include (http://autoit-script.ru/autoit3_docs/keywords.htm##include) <GUIConstantsEx.au3>
Global (http://www.autoitscript.com/autoit3/docs/keywords.htm#Global) $hGui, $i_Msg, $a_ChBx[6][2] = [[5],['Первый', 'Первая подсказка'],['Второй', 'Вторая подсказка'],['Третий', 'Третья подсказка'], _
['Четвертый', 'Четвертая подсказка'],['Пятый', 'Пятая подсказка']], $a_Check[2] = [@LF (http://autoit-script.ru/autoit3_docs/macros.htm#@lf) & '(Не отмечен)', @LF (http://autoit-script.ru/autoit3_docs/macros.htm#@lf) & '(Отмечен)']
$hGui = GUICreate (http://autoit-script.ru/autoit3_docs/functions/GUICreate.htm)('Test', 200, $a_ChBx[0][0] * 30 + 30)
For (http://www.autoitscript.com/autoit3/docs/keywords.htm#For) $i = 1 To (http://www.autoitscript.com/autoit3/docs/keywords.htm#To) $a_ChBx[0][0]
$a_ChBx[$i][0] = GUICtrlCreateCheckbox (http://autoit-script.ru/autoit3_docs/functions/GUICtrlCreateCheckbox.htm)($a_ChBx[$i][0], 20, 20 + ($i - 1) * 30, 100, 20)
GUICtrlSetBkColor (http://autoit-script.ru/autoit3_docs/functions/GUICtrlSetBkColor.htm)(-1, 0xFFFFFF)
Next (http://www.autoitscript.com/autoit3/docs/keywords.htm#Next)
GUISetState (http://autoit-script.ru/autoit3_docs/functions/GUISetState.htm)()
While (http://www.autoitscript.com/autoit3/docs/keywords.htm#While) 1
$i_Msg = GUIGetMsg (http://autoit-script.ru/autoit3_docs/functions/GUIGetMsg.htm)()
Switch (http://www.autoitscript.com/autoit3/docs/keywords.htm#Switch) $i_Msg
Case (http://www.autoitscript.com/autoit3/docs/keywords.htm#Case) $GUI_EVENT_CLOSE
ExitLoop (http://www.autoitscript.com/autoit3/docs/keywords.htm#ExitLoop)
Case (http://www.autoitscript.com/autoit3/docs/keywords.htm#Case) $a_ChBx[1][0]
ConsoleWrite (http://autoit-script.ru/autoit3_docs/functions/ConsoleWrite.htm)(_ToolTipControl($a_ChBx[1][0], $a_ChBx[1][1] & $a_Check[GUICtrlSendMsg (http://autoit-script.ru/autoit3_docs/functions/GUICtrlSendMsg.htm)($a_ChBx[1][0], 0xF0, 0, 0)], 'My Title', 1, 1, 5000) & @LF (http://autoit-script.ru/autoit3_docs/macros.htm#@lf))
Case (http://www.autoitscript.com/autoit3/docs/keywords.htm#Case) $a_ChBx[2][0] To (http://www.autoitscript.com/autoit3/docs/keywords.htm#To) $a_ChBx[$a_ChBx[0][0]][0]
For (http://www.autoitscript.com/autoit3/docs/keywords.htm#For) $i = 2 To (http://www.autoitscript.com/autoit3/docs/keywords.htm#To) $a_ChBx[0][0]
If (http://www.autoitscript.com/autoit3/docs/keywords.htm#If) $i_Msg = $a_ChBx[$i][0] Then (http://www.autoitscript.com/autoit3/docs/keywords.htm#Then)
ConsoleWrite (http://autoit-script.ru/autoit3_docs/functions/ConsoleWrite.htm)(_ToolTipControl($a_ChBx[$i][0], $a_ChBx[$i][1] & $a_Check[GUICtrlSendMsg (http://autoit-script.ru/autoit3_docs/functions/GUICtrlSendMsg.htm)($a_ChBx[$i][0], 0xF0, 0, 0)]) & @LF (http://autoit-script.ru/autoit3_docs/macros.htm#@lf));$BM_GETCHECK = 0xF0
ExitLoop (http://www.autoitscript.com/autoit3/docs/keywords.htm#ExitLoop)
EndIf (http://www.autoitscript.com/autoit3/docs/keywords.htm#EndIf)
Next (http://www.autoitscript.com/autoit3/docs/keywords.htm#Next)
EndSwitch (http://www.autoitscript.com/autoit3/docs/keywords.htm#EndSwitch)
WEnd (http://www.autoitscript.com/autoit3/docs/keywords.htm#WEnd)
_KillTT()
Exit (http://www.autoitscript.com/autoit3/docs/keywords.htm#Exit)
Func (http://www.autoitscript.com/autoit3/docs/keywords.htm#Func) _ToolTipControl($i_ID, $s_Text, $s_Title = '', $i_Icon = 0, $i_Right = 0, $i_Time = 3000)
Local (http://www.autoitscript.com/autoit3/docs/keywords.htm#Local) $h_ID, $t_Rect, $p_Rect, $a_Res, $i_X, $i_Y, $i_Ret
$h_ID = GUICtrlGetHandle (http://autoit-script.ru/autoit3_docs/functions/GUICtrlGetHandle.htm)($i_ID)
If (http://www.autoitscript.com/autoit3/docs/keywords.htm#If) Not (http://www.autoitscript.com/autoit3/docs/keywords.htm#Not) $h_ID Then (http://www.autoitscript.com/autoit3/docs/keywords.htm#Then) Return (http://www.autoitscript.com/autoit3/docs/keywords.htm#Return) 0
$t_Rect = DllStructCreate (http://autoit-script.ru/autoit3_docs/functions/DllStructCreate.htm)('long[4]')
$p_Rect = DllStructGetPtr (http://autoit-script.ru/autoit3_docs/functions/DllStructGetPtr.htm)($t_Rect)
$a_Res = DllCall (http://autoit-script.ru/autoit3_docs/functions/DllCall.htm)('user32.dll', 'int', 'GetWindowRect', 'hwnd', $h_ID, 'ptr', $p_Rect);_WinAPI_GetWindowRect()
If (http://www.autoitscript.com/autoit3/docs/keywords.htm#If) (@error (http://autoit-script.ru/autoit3_docs/macros.htm#@error)) Or (http://www.autoitscript.com/autoit3/docs/keywords.htm#Or) (Not (http://www.autoitscript.com/autoit3/docs/keywords.htm#Not) $a_Res[0]) Then (http://www.autoitscript.com/autoit3/docs/keywords.htm#Then) Return (http://www.autoitscript.com/autoit3/docs/keywords.htm#Return) 0
If (http://www.autoitscript.com/autoit3/docs/keywords.htm#If) $i_Right Then (http://www.autoitscript.com/autoit3/docs/keywords.htm#Then)
$i_X = DllStructGetData (http://autoit-script.ru/autoit3_docs/functions/DllStructGetData.htm)($t_Rect, 1, 3)
Else (http://www.autoitscript.com/autoit3/docs/keywords.htm#Else)
$i_X = DllStructGetData (http://autoit-script.ru/autoit3_docs/functions/DllStructGetData.htm)($t_Rect, 1, 1)
EndIf (http://www.autoitscript.com/autoit3/docs/keywords.htm#EndIf)
$i_Y = DllStructGetData (http://autoit-script.ru/autoit3_docs/functions/DllStructGetData.htm)($t_Rect, 1, 4)
$i_Ret = ToolTip (http://autoit-script.ru/autoit3_docs/functions/ToolTip.htm)($s_Text, $i_X, $i_Y, $s_Title, $i_Icon)
If (http://www.autoitscript.com/autoit3/docs/keywords.htm#If) $i_Ret Then (http://www.autoitscript.com/autoit3/docs/keywords.htm#Then)
AdlibUnRegister (http://autoit-script.ru/autoit3_docs/functions/AdlibUnRegister.htm)('_KillTT')
AdlibRegister (http://autoit-script.ru/autoit3_docs/functions/AdlibRegister.htm)('_KillTT', $i_Time)
EndIf (http://www.autoitscript.com/autoit3/docs/keywords.htm#EndIf)
Return (http://www.autoitscript.com/autoit3/docs/keywords.htm#Return) $i_Ret
EndFunc (http://www.autoitscript.com/autoit3/docs/keywords.htm#EndFunc) ;==>_ToolTipControl
Func (http://www.autoitscript.com/autoit3/docs/keywords.htm#Func) _KillTT()
AdlibUnRegister (http://autoit-script.ru/autoit3_docs/functions/AdlibUnRegister.htm)('_KillTT')
ToolTip (http://autoit-script.ru/autoit3_docs/functions/ToolTip.htm)('')
EndFunc (http://www.autoitscript.com/autoit3/docs/keywords.htm#EndFunc) ;==>_KillTT
madmasles
19-05-2014, 15:48
-TRM-,
Или так сделать, чтобы ToolTip перемещался вместе с окном.#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
Opt('MustDeclareVars', 1)
Global $hGui, $iMsg, $iDummy, $a_ChBx[6][2] = [[5],['Первый', 'Первая подсказка'],['Второй', 'Вторая подсказка'],['Третий', 'Третья подсказка'], _
['Четвертый', 'Четвертая подсказка'],['Пятый', 'Пятая подсказка']], $a_Check[2] = [@LF & '(Не отмечен)', @LF & '(Отмечен)'], $aTT
$hGui = GUICreate('Test', 200, $a_ChBx[0][0] * 30 + 30, -1, -1, $WS_OVERLAPPEDWINDOW)
For $i = 1 To $a_ChBx[0][0]
$a_ChBx[$i][0] = GUICtrlCreateCheckbox($a_ChBx[$i][0], 50, 20 + ($i - 1) * 30, 100, 20)
GUICtrlSetBkColor(-1, 0xFFFFFF)
Next
$iDummy = GUICtrlCreateDummy()
GUISetState()
While 1
$iMsg = GUIGetMsg()
Switch $iMsg
Case $GUI_EVENT_CLOSE
ExitLoop
Case $iDummy
__TT_MoveControl($aTT)
Case $a_ChBx[1][0]
$aTT = _Create_ToolTip_Control($a_ChBx[1][0], $a_ChBx[1][1] & $a_Check[GUICtrlSendMsg($a_ChBx[1][0], 0xF0, 0, 0)], 'My Title', 1, 1, 50000);$BM_GETCHECK = 0xF0
ConsoleWrite('_Create_ToolTip_Control error: ' & @error & @LF)
Case $a_ChBx[2][0] To $a_ChBx[$a_ChBx[0][0]][0]
For $i = 2 To $a_ChBx[0][0]
If $iMsg = $a_ChBx[$i][0] Then
$aTT = _Create_ToolTip_Control($a_ChBx[$i][0], $a_ChBx[$i][1] & $a_Check[GUICtrlSendMsg($a_ChBx[$i][0], 0xF0, 0, 0)]);$BM_GETCHECK = 0xF0
ConsoleWrite('_Create_ToolTip_Control error: ' & @error & @LF)
ExitLoop
EndIf
Next
EndSwitch
WEnd
_KillTT()
GUIDelete($hGui)
Exit
Func _Create_ToolTip_Control($i_ID, $s_Text, $s_Title = '', $i_Icon = 0, $i_Right = 0, $i_Time = 10000)
Local $h_ID, $ai_XY, $h_TT, $a_Ret[3], $i_Opt
$h_ID = GUICtrlGetHandle($i_ID)
If Not $h_ID Then Return SetError(1, 0, 0)
$ai_XY = _WinAPI_GetWindowXY_Ex($h_ID, $i_Right)
If @error Then Return SetError(2, 0, 0)
If ToolTip($s_Text, $ai_XY[0], $ai_XY[1], $s_Title, $i_Icon) Then
$i_Opt = Opt('WinTitleMatchMode', 1)
$h_TT = WinGetHandle('[Class:tooltips_class32;Title:' & StringLeft($s_Text, 24) & ']')
Opt('WinTitleMatchMode', $i_Opt)
If $h_TT Then
$a_Ret[0] = $h_ID
$a_Ret[1] = $h_TT
$a_Ret[2] = $i_Right
GUIRegisterMsg($WM_WINDOWPOSCHANGED, '_WM_WINDOWPOSCHANGED')
GUIRegisterMsg($WM_SIZE, '_WM_SIZE')
EndIf
AdlibUnRegister('_KillTT')
AdlibRegister('_KillTT', $i_Time)
Return $a_Ret
EndIf
Return SetError(3, 0, 0)
EndFunc ;==>_Create_ToolTip_Control
Func _KillTT()
If Not IsArray($aTT) Then Return
GUIRegisterMsg($WM_WINDOWPOSCHANGED, '')
GUIRegisterMsg($WM_SIZE, '')
$aTT = 0
AdlibUnRegister('_KillTT')
ToolTip('')
EndFunc ;==>_KillTT
Func _WM_WINDOWPOSCHANGED($h_Wnd, $iMsg, $i_wParam, $i_lParam)
Switch $h_Wnd
Case $hGui
__TT_MoveControl($aTT)
GUICtrlSendToDummy($iDummy)
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc ;==>_WM_WINDOWPOSCHANGED
Func _WM_SIZE($h_Wnd, $iMsg, $i_wParam, $i_lParam)
Switch $h_Wnd
Case $hGui
Switch $i_wParam
Case 1, 2
GUICtrlSendToDummy($iDummy)
EndSwitch
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc ;==>_WM_SIZE
Func __TT_MoveControl($a_TT)
If Not IsArray($a_TT) Then Return 0
If Not $a_TT[1] Then Return 0
Local $ai_XY
$ai_XY = _WinAPI_GetWindowXY_Ex($a_TT[0], $a_TT[2])
If @error Then Return SetError(1, 0, 0)
Return WinMove($a_TT[1], '', $ai_XY[0], $ai_XY[1])
EndFunc ;==>__TT_MoveControl
Func _WinAPI_GetWindowXY_Ex($h_Wnd, $i_Right = 0)
Local $t_Rect, $p_Rect, $a_Res, $ai_XY[2]
If Not IsHWnd($h_Wnd) Then Return SetError(1, 0, 0)
$t_Rect = DllStructCreate('long[4]')
$p_Rect = DllStructGetPtr($t_Rect)
$a_Res = DllCall('user32.dll', 'int', 'GetWindowRect', 'hwnd', $h_Wnd, 'ptr', $p_Rect)
If (@error) Or (Not $a_Res[0]) Then Return SetError(2, 0, 0)
If $i_Right Then
$ai_XY[0] = DllStructGetData($t_Rect, 1, 3)
Else
$ai_XY[0] = DllStructGetData($t_Rect, 1, 1)
EndIf
$ai_XY[1] = DllStructGetData($t_Rect, 1, 4)
Return $ai_XY
EndFunc ;==>_WinAPI_GetWindowXY_Ex
vBulletin v3.6.4, Copyright ©2000-2025, Jelsoft Enterprises Ltd.