Что нового

DoubleCkick на Label

RAMzor

Чайник
Сообщения
13
Репутация
0
Я использую EventMode ГУИ
Как можно реалезовать DoubleCkick на Label ("Hello world!" в моём примере)?

DoubleCkick на любое пустое место получается (смотри консоль) :-[
Код:
#include <GUIConstantsEx.au3>


Global $WM_LBUTTONDBLCLK = 0x0203
Opt("GUIOnEventMode", 1)

$TestGUI = GUICreate("My Test", 300, 100)
GUISetOnEvent($GUI_EVENT_CLOSE, "SpecialEvents")
GUISetOnEvent($GUI_EVENT_MINIMIZE, "SpecialEvents")
GUISetOnEvent($GUI_EVENT_RESTORE, "SpecialEvents")


$Lbl = GUICtrlCreateLabel("Hello world!", 30, 10)

$OkBtn = GUICtrlCreateButton("OK", 10, 30, 50)
GUICtrlSetOnEvent(-1, "OKPressed")

$CancelBtn = GUICtrlCreateButton("Cancel", 0, -1)
GUICtrlSetOnEvent(-1, "CancelPressed")

GUIRegisterMsg($WM_LBUTTONDBLCLK, "WM_LBUTTONDBLCLK")

GUISetState(@SW_SHOW)

; Just idle around
While 1
	Sleep(10)
WEnd


Func OKPressed()
	ConsoleWrite("OK Pressed  " & "ID=" & @GUI_CtrlId & " WinHandle=" & @GUI_WinHandle & " CtrlHandle=" & @GUI_CtrlHandle & @CRLF)
EndFunc   ;==>OKPressed


Func CancelPressed()
	ConsoleWrite("Cancel Pressed  " & "ID=" & @GUI_CtrlId & " WinHandle=" & @GUI_WinHandle & " CtrlHandle=" & @GUI_CtrlHandle & @CRLF)
EndFunc   ;==>CancelPressed


Func SpecialEvents()
	Select
		Case @GUI_CtrlId = $GUI_EVENT_CLOSE
			ConsoleWrite("Close Pressed  " & "ID=" & @GUI_CtrlId & " WinHandle=" & @GUI_WinHandle & @CRLF)
			Exit

		Case @GUI_CtrlId = $GUI_EVENT_MINIMIZE
			ConsoleWrite("Window Minimized  " & "ID=" & @GUI_CtrlId & " WinHandle=" & @GUI_WinHandle & @CRLF)

		Case @GUI_CtrlId = $GUI_EVENT_RESTORE
			ConsoleWrite("Window Restored  " & "ID=" & @GUI_CtrlId & " WinHandle=" & @GUI_WinHandle & @CRLF)

	EndSelect
EndFunc   ;==>SpecialEvents


Func WM_LBUTTONDBLCLK()
	ConsoleWrite("#### Double Click On Main Form ####" & @CRLF)
EndFunc   ;==>WM_LBUTTONDBLCLK
 

CreatoR

Must AutoIt!
Команда форума
Администратор
Сообщения
8 159
Репутация
2 329
Вот так можно (это не только для Label):

Код:
#include <GUIConstantsEx.au3>
#include <Constants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>
;

Global Const $WM_LBUTTONDBLCLK = 0x0203

Global $hGUI, $Button, $Edit, $Label
Global $aWndProcs[1][2]
Global $fDoubleClicked = False

Global $hProc = DllCallbackRegister('_EventsCallback_Handler', 'lresult', 'hwnd;uint;wparam;lparam')
Global $pProc = DllCallbackGetPtr($hProc)

$hGUI = GUICreate('Test', 200, 400)

$Button = GUICtrlCreateButton('&Click', 65, 360, 70, 25)
_InstallControlProcedure($Button, $pProc)

$Edit = GUICtrlCreateEdit('', 10, 10, 180, 280)
_InstallControlProcedure($Edit, $pProc)

$Label = GUICtrlCreateLabel('This also', 65, 320, 70, 25, $SS_CENTER)
_InstallControlProcedure($Label, $pProc)

GUISetState()

While 1
	Switch GUIGetMsg()
		Case $GUI_EVENT_CLOSE
			GUIDelete()
			DllCallbackFree($hProc)
			Exit
	EndSwitch
	
	If $fDoubleClicked <> False Then
		$iID = $fDoubleClicked
		$fDoubleClicked = False
		
		Switch $iID
            Case $Button
                MsgBox(0x40, 'Button', 'Double Click')
            Case $Edit
                MsgBox(0x40, 'Edit', 'Double Click')
            Case $Label
                MsgBox(0x40, 'Label', 'Double Click')
        EndSwitch
	EndIf
WEnd

Func _EventsCallback_Handler($hWnd, $iMsg, $iwParam, $ilParam)
    Local $iIndex = 0
    
    For $i = 1 To $aWndProcs[0][0]
        If $hWnd = $aWndProcs[$i][0] Then
            $iIndex = $i
            ExitLoop
        EndIf
    Next
    
    If $iMsg = $WM_LBUTTONDBLCLK Then
        $fDoubleClicked = _WinAPI_GetDlgCtrlID($hWnd)
    EndIf
    
    Return _WinAPI_CallWindowProc($aWndProcs[$iIndex][1], $hWnd, $iMsg, $iwParam, $ilParam)
EndFunc

Func _InstallControlProcedure($hControl, $pProc)
    If Not IsHWnd($hControl) Then
        $hControl = GUICtrlGetHandle($hControl)
        If Not IsHWnd($hControl) Then Return SetError(1, 0, 0)
    EndIf
    
    $aWndProcs[0][0] += 1
	ReDim $aWndProcs[$aWndProcs[0][0]+1][2]
	
    $aWndProcs[$aWndProcs[0][0]][0] = $hControl
    $aWndProcs[$aWndProcs[0][0]][1] = _WinAPI_SetWindowLong($hControl, $GWL_WNDPROC, $pProc)
    
    Return 1
EndFunc



Добавлено:
Сообщение автоматически объединено:

Ну или вот так:

Код:
#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
;

Global $iClicked = 0, $iDoubleClicked = 0

Opt("GUIOnEventMode", 1)

$TestGUI = GUICreate("My Test", 300, 100)

GUISetOnEvent($GUI_EVENT_CLOSE, "SpecialEvents")
GUISetOnEvent($GUI_EVENT_MINIMIZE, "SpecialEvents")
GUISetOnEvent($GUI_EVENT_RESTORE, "SpecialEvents")

$Lbl = GUICtrlCreateLabel("Hello world!", 30, 10)

$OkBtn = GUICtrlCreateButton("OK", 10, 30, 50)
GUICtrlSetOnEvent(-1, "OKPressed")

$CancelBtn = GUICtrlCreateButton("Cancel", 70, -1)
GUICtrlSetOnEvent(-1, "CancelPressed")

GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")
GUISetState(@SW_SHOW)

While 1
	Switch GUIGetMsg()
		Case $GUI_EVENT_CLOSE
			Exit
	EndSwitch
	
	If $iDoubleClicked > 0 Then
		$iID = $iDoubleClicked
		$iDoubleClicked = 0
		MsgBox(64, "Title", "DoubleClicked: " & $iID)
	EndIf
WEnd

Func CancelPressed()
	ConsoleWrite("Cancel Pressed  " & "ID=" & @GUI_CtrlId & " WinHandle=" & @GUI_WinHandle & _
		" CtrlHandle=" & @GUI_CtrlHandle & @CRLF)
EndFunc   ;==>CancelPressed

Func OKPressed()
	ConsoleWrite("OK Pressed  " & "ID=" & @GUI_CtrlId & " WinHandle=" & @GUI_WinHandle & " CtrlHandle=" & @GUI_CtrlHandle & @CRLF)
EndFunc   ;==>OKPressed

Func SpecialEvents()
	Select
		Case @GUI_CtrlId = $GUI_EVENT_CLOSE
			ConsoleWrite("Close Pressed  " & "ID=" & @GUI_CtrlId & " WinHandle=" & @GUI_WinHandle & @CRLF)
			Exit
		Case @GUI_CtrlId = $GUI_EVENT_MINIMIZE
			ConsoleWrite("Window Minimized  " & "ID=" & @GUI_CtrlId & " WinHandle=" & @GUI_WinHandle & @CRLF)
		Case @GUI_CtrlId = $GUI_EVENT_RESTORE
			ConsoleWrite("Window Restored  " & "ID=" & @GUI_CtrlId & " WinHandle=" & @GUI_WinHandle & @CRLF)
	EndSelect
EndFunc   ;==>SpecialEvents

Func WM_COMMAND($hWnd, $MsgID, $wParam, $lParam)
	Local Const $STN_DBLCLK = 1, $STN_CLICKED = 0
	Local $nID = BitAND($wParam, 0xFFFF)
	Local $nNotifyCode = BitShift($wParam, 16)
	
	Switch $nNotifyCode
		Case $STN_CLICKED
			$iClicked = $nID
		Case $STN_DBLCLK
			$iDoubleClicked = $nID
	EndSwitch
	
	Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_COMMAND
 
Автор
R

RAMzor

Чайник
Сообщения
13
Репутация
0
Большое спасибо!
 
Верх