[..] WM_NOTIFY, tab et Id
Posté : ven. 31 déc. 2021 13:02
Bonjour,
Suite à une réponse de l'un de vous, j'essaie de prendre pour habitude de ne pas utiliser les UDF pour créer les contrôles.
Ainsi, lorsque j'utilise WN_NOTIFY / WM_COMMAND, j'essaie de privilégier IDFrom plutôt que hWndFrom.
De mémoire, lorsque j'utilise un menu contextuel avec une listview, je suis obligé de passer par le handle.
J'aimerais savoir si je suis également obligé de la faire pour des onglets.
Ma question n'étant peut-être pas très explicite, voici le code utilisant l'UDF (handle) et celui avec la commande classique (ID) qui ne fonctionne pas.
Suite à une réponse de l'un de vous, j'essaie de prendre pour habitude de ne pas utiliser les UDF pour créer les contrôles.
Ainsi, lorsque j'utilise WN_NOTIFY / WM_COMMAND, j'essaie de privilégier IDFrom plutôt que hWndFrom.
De mémoire, lorsque j'utilise un menu contextuel avec une listview, je suis obligé de passer par le handle.
J'aimerais savoir si je suis également obligé de la faire pour des onglets.
Ma question n'étant peut-être pas très explicite, voici le code utilisant l'UDF (handle) et celui avec la commande classique (ID) qui ne fonctionne pas.
#include <GUIConstantsEx.au3>
#include <GuiTab.au3>
#include <WindowsConstants.au3>
Global $g_hTab
Example()
Func Example()
Local $hGUI
; Create GUI
$hGUI = GUICreate("(UDF Created) Tab Control Create", 400, 300)
$g_hTab = _GUICtrlTab_Create($hGUI, 2, 2, 396, 296)
GUISetState(@SW_SHOW)
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
; Add tabs
_GUICtrlTab_InsertItem($g_hTab, 0, "Tab 1")
_GUICtrlTab_InsertItem($g_hTab, 1, "Tab 2")
_GUICtrlTab_InsertItem($g_hTab, 2, "Tab 3")
; Loop until the user exits.
Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE
GUIDelete()
EndFunc ;==>Example
Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)
#forceref $hWnd, $iMsg, $wParam
Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndTab
$hWndTab = $g_hTab
If Not IsHWnd($g_hTab) Then $hWndTab = GUICtrlGetHandle($g_hTab)
$tNMHDR = DllStructCreate($tagNMHDR, $lParam)
$hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
$iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
$iCode = DllStructGetData($tNMHDR, "Code")
Switch $hWndFrom
Case $hWndTab
Switch $iCode
Case $NM_CLICK ; The user has clicked the left mouse button within the control
_DebugPrint("$NM_CLICK" & @CRLF & "--> hWndFrom:" & @TAB & $hWndFrom & @CRLF & _
"-->IDFrom:" & @TAB & $iIDFrom & @CRLF & _
"-->Code:" & @TAB & $iCode)
; The return value is ignored by the tab control
EndSwitch
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc ;==>WM_NOTIFY
Func _DebugPrint($s_Text, $sLine = @ScriptLineNumber)
ConsoleWrite( _
"!===========================================================" & @CRLF & _
"+======================================================" & @CRLF & _
"-->Line(" & StringFormat("%04d", $sLine) & "):" & @TAB & $s_Text & @CRLF & _
"+======================================================" & @CRLF)
EndFunc ;==>_DebugPrint
#include <GuiTab.au3>
#include <WindowsConstants.au3>
Global $g_hTab
Example()
Func Example()
Local $hGUI
; Create GUI
$hGUI = GUICreate("(UDF Created) Tab Control Create", 400, 300)
$g_hTab = _GUICtrlTab_Create($hGUI, 2, 2, 396, 296)
GUISetState(@SW_SHOW)
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
; Add tabs
_GUICtrlTab_InsertItem($g_hTab, 0, "Tab 1")
_GUICtrlTab_InsertItem($g_hTab, 1, "Tab 2")
_GUICtrlTab_InsertItem($g_hTab, 2, "Tab 3")
; Loop until the user exits.
Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE
GUIDelete()
EndFunc ;==>Example
Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)
#forceref $hWnd, $iMsg, $wParam
Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndTab
$hWndTab = $g_hTab
If Not IsHWnd($g_hTab) Then $hWndTab = GUICtrlGetHandle($g_hTab)
$tNMHDR = DllStructCreate($tagNMHDR, $lParam)
$hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
$iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
$iCode = DllStructGetData($tNMHDR, "Code")
Switch $hWndFrom
Case $hWndTab
Switch $iCode
Case $NM_CLICK ; The user has clicked the left mouse button within the control
_DebugPrint("$NM_CLICK" & @CRLF & "--> hWndFrom:" & @TAB & $hWndFrom & @CRLF & _
"-->IDFrom:" & @TAB & $iIDFrom & @CRLF & _
"-->Code:" & @TAB & $iCode)
; The return value is ignored by the tab control
EndSwitch
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc ;==>WM_NOTIFY
Func _DebugPrint($s_Text, $sLine = @ScriptLineNumber)
ConsoleWrite( _
"!===========================================================" & @CRLF & _
"+======================================================" & @CRLF & _
"-->Line(" & StringFormat("%04d", $sLine) & "):" & @TAB & $s_Text & @CRLF & _
"+======================================================" & @CRLF)
EndFunc ;==>_DebugPrint
#include <GUIConstantsEx.au3>
#include <GuiTab.au3>
#include <WindowsConstants.au3>
Example()
Func Example()
Local $hGUI
; Create GUI
$hGUI = GUICreate("(UDF Created) Tab Control Create", 400, 300)
GUICtrlCreateTab( 2, 2, 396, 296)
GUISetState(@SW_SHOW)
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
; Add tabs
Local $idTab1 = GUICtrlCreateTabItem("Tab 1")
Local $idTab2 = GUICtrlCreateTabItem("Tab 2")
Local $idTab3 = GUICtrlCreateTabItem("Tab 3")
; Loop until the user exits.
Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE
GUIDelete()
EndFunc ;==>Example
Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)
#forceref $hWnd, $iMsg, $wParam
Local $iIDFrom, $iCode, $tNMHDR
$tNMHDR = DllStructCreate($tagNMHDR, $lParam)
$iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
$iCode = DllStructGetData($tNMHDR, "Code")
Switch $iIDFrom
Case $idTab1, $idTab2, $idTab3
Switch $iCode
Case $NM_CLICK ; The user has clicked the left mouse button within the control
_DebugPrint("$NM_CLICK" & @CRLF & "-->IDFrom:" & @TAB & $iIDFrom & @CRLF & _
"-->Code:" & @TAB & $iCode)
; The return value is ignored by the tab control
EndSwitch
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc ;==>WM_NOTIFY
Func _DebugPrint($s_Text, $sLine = @ScriptLineNumber)
ConsoleWrite( _
"!===========================================================" & @CRLF & _
"+======================================================" & @CRLF & _
"-->Line(" & StringFormat("%04d", $sLine) & "):" & @TAB & $s_Text & @CRLF & _
"+======================================================" & @CRLF)
EndFunc ;==>_DebugPrint
#include <GuiTab.au3>
#include <WindowsConstants.au3>
Example()
Func Example()
Local $hGUI
; Create GUI
$hGUI = GUICreate("(UDF Created) Tab Control Create", 400, 300)
GUICtrlCreateTab( 2, 2, 396, 296)
GUISetState(@SW_SHOW)
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
; Add tabs
Local $idTab1 = GUICtrlCreateTabItem("Tab 1")
Local $idTab2 = GUICtrlCreateTabItem("Tab 2")
Local $idTab3 = GUICtrlCreateTabItem("Tab 3")
; Loop until the user exits.
Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE
GUIDelete()
EndFunc ;==>Example
Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)
#forceref $hWnd, $iMsg, $wParam
Local $iIDFrom, $iCode, $tNMHDR
$tNMHDR = DllStructCreate($tagNMHDR, $lParam)
$iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
$iCode = DllStructGetData($tNMHDR, "Code")
Switch $iIDFrom
Case $idTab1, $idTab2, $idTab3
Switch $iCode
Case $NM_CLICK ; The user has clicked the left mouse button within the control
_DebugPrint("$NM_CLICK" & @CRLF & "-->IDFrom:" & @TAB & $iIDFrom & @CRLF & _
"-->Code:" & @TAB & $iCode)
; The return value is ignored by the tab control
EndSwitch
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc ;==>WM_NOTIFY
Func _DebugPrint($s_Text, $sLine = @ScriptLineNumber)
ConsoleWrite( _
"!===========================================================" & @CRLF & _
"+======================================================" & @CRLF & _
"-->Line(" & StringFormat("%04d", $sLine) & "):" & @TAB & $s_Text & @CRLF & _
"+======================================================" & @CRLF)
EndFunc ;==>_DebugPrint