Mingre Posted June 13, 2016 Share Posted June 13, 2016 (edited) expandcollapse popup#include-once #include <WindowsConstants.au3> #include <GUIConstantsEx.au3> #include <GuiListView.au3> #include <WindowsConstants.au3> ;Opt('MustDeclareVars', 1) Opt('TrayIconDebug', 1) Opt('Guioneventmode', 1) HotKeySet('{ESC}', '_exit') #include <Array.au3> #include <Excel.au3> Global $lastID Global $listEnabled = '' Global $listDisabled = '' Global $hGui, $idListview, $idInput, $width_hGui = 700 $hGui = GUICreate('', $width_hGui, 500) Local $te = StringSplit('' & _ 'rash|lump|pruritus|jaundice|cyanosis|onycholysis|mole changes' & _ '', '|', 2) GUISetOnEvent(-3, '_exit') createBlock($te, 0, 0, 200) GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") GUISetState(@SW_SHOW) WinWait('Forever') Func WM_NOTIFY($hWnd, $Msg, $wParam, $lParam) Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR ;, $tagNMHDR $tNMHDR = DllStructCreate($tagNMHDR, $lParam) $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom")) $iIDFrom = DllStructGetData($tNMHDR, "IDFrom") $iCode = DllStructGetData($tNMHDR, "Code") ConsoleWrite(@LF & @SEC & ' - ' & $iIDFrom & ' - ' & $iCode) Tooltip($hWndFrom) $lastID = $iIDFrom Return 'GUI_RUNDEFMSG' ;$GUI_RUNDEFMSG EndFunc ;==>WM_NOTIFY Func createBlock(ByRef $text, $x_Zero = Default, Const $y_Zero = 100, Const $width = 150) If $x_Zero = Default Then $x_Zero = 150 Local $idBtn[UBound($text)] $idBtn[0] = GUICtrlCreateButton($text[0], $x_Zero, $y_Zero, -1, -1, 0x4000) For $i = 1 To UBound($text) - 1 Step +1 $posPrev = ControlGetPos($hGui, '', $idBtn[$i - 1]) $x = $posPrev[0] + $posPrev[2] $y = $posPrev[1] $idBtn[$i] = GUICtrlCreateButton($text[$i], $x, $y, -1, -1, 0x4000) $posCurr = ControlGetPos($hGui, '', $idBtn[$i]) If $posCurr[0] + $posCurr[2] - $x_Zero > $width Then GUICtrlDelete($idBtn[$i]) $idBtn[$i] = GUICtrlCreateButton($text[$i], $x_Zero, $posPrev[1] + $posPrev[3]) If $i = UBound($text) - 1 Then $posLast = ControlGetPos($hGui, '', $idBtn[$i]) If $posLast[2] > $width Then GUICtrlDelete($idBtn[$i]) $idBtn[$i] = GUICtrlCreateButton($text[$i], $x_Zero, $posPrev[1] + $posPrev[3], $width, -1, -1, 0x4000) EndIf EndIf Local $array[1] $t = $i - 1 ; t for temp $s = $i $tot_x = 0 While True $s -= 1 $pos2 = ControlGetPos($hGui, '', $idBtn[$s]) If $pos2[1] = $posPrev[1] Then _ArrayAdd($array, $pos2[2]) $tot_x += $pos2[2] If $s = 0 Then ExitLoop Else $s += 1 ExitLoop EndIf WEnd _ArrayDelete($array, 0) _ArrayReverse($array) $x_Zero1 = $x_Zero For $j = $s To $t Step +1 GUICtrlDelete($idBtn[$j]) $k = $j - $s $array[$k] = $width * 1.3 * ($array[$k] / $tot_x) $idBtn[$j] = GUICtrlCreateButton($text[$j], $x_Zero1, $posPrev[1], $array[$k]);, -1, -1, 0x4000) $x_Zero1 += $array[$k] Next EndIf Next For $i = 0 To UBound($idBtn) - 1 GUICtrlSetOnEvent($idBtn[$i], 'yey') $x = GUICtrlCreateContextMenu($idBtn[$i]) GUICtrlCreateMenuItem("Positive", $x) GUICtrlCreateMenuItem("Negative", $x) GUICtrlCreateMenuItem("Not asked", $x) Next EndFunc ;==>createBlock Func hehe() ; How to get the ID of the right-clicked button? EndFunc ;==>hehe Func yey() $hexDisabled = 0xff8b8b $hexEnabled = 0x8bb1ff $x = @GUI_CtrlId $read = GUICtrlRead($x) Select Case StringRegExp($listEnabled, '\(' & $read & '\)') ; Already enabled ; Disable! ;ToolTip('Will disable!') $listEnabled = StringRegExpReplace($listDisabled, '\(' & $read & '\)', '') $listDisabled = '(' & $read & ')' GUICtrlSetBkColor($x, $hexDisabled) Case StringRegExp($listDisabled, '\(' & $read & '\)') ; Case Else ; Enable! ;ToolTip('Will enable!') $listEnabled = '(' & $read & ')' GUICtrlSetBkColor($x, $hexEnabled) EndSelect ; Tooltip(GUICtrlRead($x)) EndFunc ;==>yey Func _exit() Exit EndFunc ;==>_exit Hello forums, Is there any way to retrieve the control ID of the last right-clicked button control? I'm trying to do it using WM_NOTIFY function (by saving the last value returned by DllStructGetData($tNMHDR, "IDFrom")) but I'm always getting the wrong ID. Thanks! Edited June 13, 2016 by Mingre Link to comment Share on other sites More sharing options...
Danp2 Posted June 13, 2016 Share Posted June 13, 2016 You are saving the $iIDFrom value for all WM_NOTIFY hits. Instead, you should check for a right click and then update the variable: If $tNMHDR.Code = $NM_RCLICK Then $lastID = $iIDFrom Endif Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
Mingre Posted June 13, 2016 Author Share Posted June 13, 2016 @Danp2 Func WM_NOTIFY($hWnd, $Msg, $wParam, $lParam) Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR ;, $tagNMHDR $tNMHDR = DllStructCreate($tagNMHDR, $lParam) $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom")) $iIDFrom = DllStructGetData($tNMHDR, "IDFrom") $iCode = DllStructGetData($tNMHDR, "Code") If $tNMHDR.Code = $NM_RCLICK Then $lastID = $iIDFrom ConsoleWrite(@LF & $lastID) EndIf Return 'GUI_RUNDEFMSG' ;$GUI_RUNDEFMSG EndFunc ;==>WM_NOTIFY But this doesn't give me any values for $lastID Link to comment Share on other sites More sharing options...
Synapsee Posted June 13, 2016 Share Posted June 13, 2016 expandcollapse popup#include-once #include <WindowsConstants.au3> #include <GUIConstantsEx.au3> #include <GuiListView.au3> #include <WindowsConstants.au3> ;Opt('MustDeclareVars', 1) Opt('TrayIconDebug', 1) Opt('Guioneventmode', 1) HotKeySet('{ESC}', '_exit') #include <Array.au3> #include <Excel.au3> Global $lastID Global $listEnabled = '' Global $listDisabled = '' Global $hGui, $idListview, $idInput, $width_hGui = 700 $hGui = GUICreate('', $width_hGui, 500) Local $te = StringSplit('' & _ 'rash|lump|pruritus|jaundice|cyanosis|onycholysis|mole changes' & _ '', '|', 2) GUISetOnEvent(-3, '_exit') Local $idBtn[UBound($te)] createBlock($te, 0, 0, 200) GUISetOnEvent($GUI_EVENT_SECONDARYDOWN, "_SecondaryDown") ;~ GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") GUISetState(@SW_SHOW) WinWait('Forever') Func WM_NOTIFY($hWnd, $Msg, $wParam, $lParam) Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR ;, $tagNMHDR $tNMHDR = DllStructCreate($tagNMHDR, $lParam) $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom")) $iIDFrom = DllStructGetData($tNMHDR, "IDFrom") $iCode = DllStructGetData($tNMHDR, "Code") ConsoleWrite(@LF & @SEC & ' - ' & $iIDFrom & ' - ' & $iCode) Tooltip($hWndFrom) $lastID = $iIDFrom Return 'GUI_RUNDEFMSG' ;$GUI_RUNDEFMSG EndFunc ;==>WM_NOTIFY Func createBlock(ByRef $text, $x_Zero = Default, Const $y_Zero = 100, Const $width = 150) If $x_Zero = Default Then $x_Zero = 150 Local $idBtn[UBound($text)] $idBtn[0] = GUICtrlCreateButton($text[0], $x_Zero, $y_Zero, -1, -1, 0x4000) For $i = 1 To UBound($text) - 1 Step +1 $posPrev = ControlGetPos($hGui, '', $idBtn[$i - 1]) $x = $posPrev[0] + $posPrev[2] $y = $posPrev[1] $idBtn[$i] = GUICtrlCreateButton($text[$i], $x, $y, -1, -1, 0x4000) $posCurr = ControlGetPos($hGui, '', $idBtn[$i]) If $posCurr[0] + $posCurr[2] - $x_Zero > $width Then GUICtrlDelete($idBtn[$i]) $idBtn[$i] = GUICtrlCreateButton($text[$i], $x_Zero, $posPrev[1] + $posPrev[3]) If $i = UBound($text) - 1 Then $posLast = ControlGetPos($hGui, '', $idBtn[$i]) If $posLast[2] > $width Then GUICtrlDelete($idBtn[$i]) $idBtn[$i] = GUICtrlCreateButton($text[$i], $x_Zero, $posPrev[1] + $posPrev[3], $width, -1, -1, 0x4000) EndIf EndIf Local $array[1] $t = $i - 1 ; t for temp $s = $i $tot_x = 0 While True $s -= 1 $pos2 = ControlGetPos($hGui, '', $idBtn[$s]) If $pos2[1] = $posPrev[1] Then _ArrayAdd($array, $pos2[2]) $tot_x += $pos2[2] If $s = 0 Then ExitLoop Else $s += 1 ExitLoop EndIf WEnd _ArrayDelete($array, 0) _ArrayReverse($array) $x_Zero1 = $x_Zero For $j = $s To $t Step +1 GUICtrlDelete($idBtn[$j]) $k = $j - $s $array[$k] = $width * 1.3 * ($array[$k] / $tot_x) $idBtn[$j] = GUICtrlCreateButton($text[$j], $x_Zero1, $posPrev[1], $array[$k]);, -1, -1, 0x4000) $x_Zero1 += $array[$k] Next EndIf Next For $i = 0 To UBound($idBtn) - 1 GUICtrlSetOnEvent($idBtn[$i], 'yey') $x = GUICtrlCreateContextMenu($idBtn[$i]) GUICtrlCreateMenuItem("Positive", $x) GUICtrlCreateMenuItem("Negative", $x) GUICtrlCreateMenuItem("Not asked", $x) Next EndFunc ;==>createBlock Func _SecondaryDown() $aCInfo = GUIGetCursorInfo($hGUI) MsgBox($MB_SYSTEMMODAL, "Pressed", $aCInfo[4]) EndFunc Func hehe() ; How to get the ID of the right-clicked button? EndFunc ;==>hehe Func yey() $hexDisabled = 0xff8b8b $hexEnabled = 0x8bb1ff $x = @GUI_CtrlId $read = GUICtrlRead($x) Select Case StringRegExp($listEnabled, '\(' & $read & '\)') ; Already enabled ; Disable! ;ToolTip('Will disable!') $listEnabled = StringRegExpReplace($listDisabled, '\(' & $read & '\)', '') $listDisabled = '(' & $read & ')' GUICtrlSetBkColor($x, $hexDisabled) Case StringRegExp($listDisabled, '\(' & $read & '\)') ; Case Else ; Enable! ;ToolTip('Will enable!') $listEnabled = '(' & $read & ')' GUICtrlSetBkColor($x, $hexEnabled) EndSelect ; Tooltip(GUICtrlRead($x)) EndFunc ;==>yey Func _exit() Exit EndFunc ;==>_exit Mingre 1 Link to comment Share on other sites More sharing options...
Mingre Posted June 13, 2016 Author Share Posted June 13, 2016 @Synapsee Thanks so much! Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now