Advertisement
AZJIO

TrackPopupMenu

Oct 22nd, 2012
545
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
AutoIt 7.09 KB | None | 0 0
  1. #include <StaticConstants.au3>
  2. #include <ButtonConstants.au3>
  3. #include <GUIConstantsEx.au3>
  4. #include <WindowsConstants.au3>
  5. #include <GuiMenu.au3>
  6.  
  7.  
  8. ; En
  9.  
  10. $LngTitle = 'Test'
  11. $LngOpEpl='Open in Explorer'
  12. $LngDel = 'Delete'
  13. $LngDef = 'Default'
  14. $LngOpn = 'Open'
  15.  
  16. ; Ru
  17. ; если русская локализация, то русский язык
  18. If @OSLang = 0419 Then
  19. $LngTitle = 'Контекстное меню'
  20. $LngOpEpl='Открыть в проводнике'
  21. $LngDel = 'Удалить'
  22. $LngDef = 'Основной'
  23. $LngOpn = 'Открыть'
  24. EndIf
  25.  
  26. $hGui = GUICreate($LngTitle, 500, 300, -1, -1, BitOR($GUI_SS_DEFAULT_GUI, $WS_OVERLAPPEDWINDOW, $WS_CLIPCHILDREN), $WS_EX_ACCEPTFILES)
  27.  
  28. ; $iBtn1 = GUICtrlCreateLabel(ChrW('0x25BC'), 11, 11, 23, 23, $SS_CENTER + $SS_CENTERIMAGE)
  29. $iBtn1 = GUICtrlCreateButton(ChrW('0x25BC'), 5, 5, 25, 25)
  30. $hBtn1 = _SetButton($iBtn1)
  31. $iBtn2 = GUICtrlCreateButton(ChrW('0x25BC'), 500 - 30, 5, 25, 25)
  32. $hBtn2 = _SetButton($iBtn2)
  33. $iBtn3 = GUICtrlCreateButton(ChrW('0x25B2'), 500 - 30, 300 - 30, 25, 25)
  34. $hBtn3 = _SetButton($iBtn3)
  35. $iBtn4 = GUICtrlCreateButton(ChrW('0x25B2'), 5, 300 - 30, 25, 25)
  36. $hBtn4 = _SetButton($iBtn4)
  37.  
  38.  
  39. $iBtn5 = GUICtrlCreateButton(ChrW('0x25BA'), 120, 5, 25, 25)
  40. $hBtn5 = _SetButton($iBtn5)
  41. $iBtn6 = GUICtrlCreateButton(ChrW('0x25C4'), 500 - 140, 5, 25, 25)
  42. $hBtn6 = _SetButton($iBtn6)
  43. $iBtn7 = GUICtrlCreateButton(ChrW('0x25BA'), 120, 300 - 30, 25, 25)
  44. $hBtn7 = _SetButton($iBtn7)
  45. $iBtn8 = GUICtrlCreateButton(ChrW('0x25C4'), 500 - 140, 300 - 30, 25, 25)
  46. $hBtn8 = _SetButton($iBtn8)
  47. ; GUICtrlSetState(-1, $GUI_NOFOCUS)
  48.  
  49. $iDummy = GUICtrlCreateDummy()
  50.  
  51. $ContMenu = GUICtrlCreateContextMenu(GUICtrlCreateDummy())
  52. $hMenu = GUICtrlGetHandle($ContMenu)
  53. $iOpEpl = GUICtrlCreateMenuItem($LngOpEpl & @Tab & 'Enter', $ContMenu)
  54. $iCMdel = GUICtrlCreateMenuItem($LngDel & @Tab & 'Ctrl+Del', $ContMenu)
  55. $iCMDef = GUICtrlCreateMenuItem($LngDef & @Tab & 'Ctrl+Enter', $ContMenu)
  56. $iCMreg = GUICtrlCreateMenuItem($LngOpn & ' RegEdit' & @Tab & 'Ctrl+NumPad0', $ContMenu)
  57.  
  58. GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")
  59. ; GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
  60.  
  61. GUISetState()
  62. While 1
  63.     Switch GUIGetMsg()
  64.         Case $iOpEpl
  65.             MsgBox(0, '?', $LngOpEpl)
  66.         Case $iCMdel
  67.             MsgBox(0, '?', $LngDel)
  68.         Case $iCMDef
  69.             MsgBox(0, '?', $LngDef)
  70.         Case $iCMreg
  71.             MsgBox(0, '?', $LngOpn)
  72.         Case -3
  73.             Exit
  74.     EndSwitch
  75. WEnd
  76.  
  77. Func WM_COMMAND($hWnd, $Msg, $wParam, $lParam)
  78.     #forceref $hWnd, $Msg
  79.     Local $nNotifyCode = BitShift($wParam, 16)
  80.     Local $nID = BitAND($wParam, 0x0000FFFF)
  81.     Local $hCtrl = $lParam
  82.    
  83.     Switch $hCtrl
  84.         Case $hBtn1
  85.             Switch $nNotifyCode
  86.                 Case $BN_CLICKED
  87.                     $aPos = ControlGetPos($hGui, "", $iBtn1)
  88.                     Local $tpoint = DllStructCreate("int X;int Y")
  89.                     DllStructSetData($tpoint, "X", $aPos[0])
  90.                     DllStructSetData($tpoint, "Y", $aPos[1] + $aPos[3])
  91.                     _WinAPI_ClientToScreen($hGui, $tpoint)
  92.                     _GUICtrlMenu_TrackPopupMenu ($hMenu, $hGui, DllStructGetData($tpoint, "X"), DllStructGetData($tpoint, "Y"), 1)
  93.             EndSwitch
  94.             Return 0 ; Only workout clicking on the button
  95.         Case $hBtn2
  96.             Switch $nNotifyCode
  97.                 Case $BN_CLICKED
  98.                     $aPos = ControlGetPos($hGui, "", $iBtn2)
  99.                     Local $tpoint = DllStructCreate("int X;int Y")
  100.                     DllStructSetData($tpoint, "X", $aPos[0] + $aPos[2])
  101.                     DllStructSetData($tpoint, "Y", $aPos[1] + $aPos[3])
  102.                     _WinAPI_ClientToScreen($hGui, $tpoint)
  103.                     _GUICtrlMenu_TrackPopupMenu ($hMenu, $hGui, DllStructGetData($tpoint, "X"), DllStructGetData($tpoint, "Y"), 2)
  104.             EndSwitch
  105.             Return 0 ; Only workout clicking on the button
  106.         Case $hBtn3
  107.             Switch $nNotifyCode
  108.                 Case $BN_CLICKED
  109.                     $aPos = ControlGetPos($hGui, "", $iBtn3)
  110.                     Local $tpoint = DllStructCreate("int X;int Y")
  111.                     DllStructSetData($tpoint, "X", $aPos[0] + $aPos[2])
  112.                     DllStructSetData($tpoint, "Y", $aPos[1])
  113.                     _WinAPI_ClientToScreen($hGui, $tpoint)
  114.                     _GUICtrlMenu_TrackPopupMenu ($hMenu, $hGui, DllStructGetData($tpoint, "X"), DllStructGetData($tpoint, "Y"), 2, 0)
  115.             EndSwitch
  116.             Return 0 ; Only workout clicking on the button
  117.         Case $hBtn4
  118.             Switch $nNotifyCode
  119.                 Case $BN_CLICKED
  120.                     $aPos = ControlGetPos($hGui, "", $iBtn4)
  121.                     Local $tpoint = DllStructCreate("int X;int Y")
  122.                     DllStructSetData($tpoint, "X", $aPos[0])
  123.                     DllStructSetData($tpoint, "Y", $aPos[1])
  124.                     _WinAPI_ClientToScreen($hGui, $tpoint)
  125.                     _GUICtrlMenu_TrackPopupMenu ($hMenu, $hGui, DllStructGetData($tpoint, "X"), DllStructGetData($tpoint, "Y"), 1, 0)
  126.             EndSwitch
  127.             Return 0 ; Only workout clicking on the button
  128.         Case $hBtn5
  129.             Switch $nNotifyCode
  130.                 Case $BN_CLICKED
  131.                     $aPos = ControlGetPos($hGui, "", $iBtn5)
  132.                     Local $tpoint = DllStructCreate("int X;int Y")
  133.                     DllStructSetData($tpoint, "X", $aPos[0] + $aPos[2])
  134.                     DllStructSetData($tpoint, "Y", $aPos[1])
  135.                     _WinAPI_ClientToScreen($hGui, $tpoint)
  136.                     _GUICtrlMenu_TrackPopupMenu ($hMenu, $hGui, DllStructGetData($tpoint, "X"), DllStructGetData($tpoint, "Y"), 1)
  137.             EndSwitch
  138.             Return 0 ; Only workout clicking on the button
  139.         Case $hBtn6
  140.             Switch $nNotifyCode
  141.                 Case $BN_CLICKED
  142.                     $aPos = ControlGetPos($hGui, "", $iBtn6)
  143.                     Local $tpoint = DllStructCreate("int X;int Y")
  144.                     DllStructSetData($tpoint, "X", $aPos[0])
  145.                     DllStructSetData($tpoint, "Y", $aPos[1])
  146.                     _WinAPI_ClientToScreen($hGui, $tpoint)
  147.                     _GUICtrlMenu_TrackPopupMenu ($hMenu, $hGui, DllStructGetData($tpoint, "X"), DllStructGetData($tpoint, "Y"), 2)
  148.             EndSwitch
  149.             Return 0 ; Only workout clicking on the button
  150.         Case $hBtn7
  151.             Switch $nNotifyCode
  152.                 Case $BN_CLICKED
  153.                     $aPos = ControlGetPos($hGui, "", $iBtn7)
  154.                     Local $tpoint = DllStructCreate("int X;int Y")
  155.                     DllStructSetData($tpoint, "X", $aPos[0] + $aPos[2])
  156.                     DllStructSetData($tpoint, "Y", $aPos[1] + $aPos[3])
  157.                     _WinAPI_ClientToScreen($hGui, $tpoint)
  158.                     _GUICtrlMenu_TrackPopupMenu ($hMenu, $hGui, DllStructGetData($tpoint, "X"), DllStructGetData($tpoint, "Y"), 1, 0)
  159.             EndSwitch
  160.             Return 0 ; Only workout clicking on the button
  161.         Case $hBtn8
  162.             Switch $nNotifyCode
  163.                 Case $BN_CLICKED
  164.                     $aPos = ControlGetPos($hGui, "", $iBtn8)
  165.                     Local $tpoint = DllStructCreate("int X;int Y")
  166.                     DllStructSetData($tpoint, "X", $aPos[0])
  167.                     DllStructSetData($tpoint, "Y", $aPos[1] + $aPos[3])
  168.                     _WinAPI_ClientToScreen($hGui, $tpoint)
  169.                     _GUICtrlMenu_TrackPopupMenu ($hMenu, $hGui, DllStructGetData($tpoint, "X"), DllStructGetData($tpoint, "Y"), 2, 0)
  170.             EndSwitch
  171.             Return 0 ; Only workout clicking on the button
  172.     EndSwitch
  173.     Return $GUI_RUNDEFMSG
  174. EndFunc   ;==>WM_COMMAND
  175.  
  176. Func _SetButton($iBtn)
  177.     GUICtrlSetFont($iBtn, -1, -1, -1, 'Arial')
  178.     GUICtrlSetBkColor($iBtn, 0xEEEEEE)
  179.     ; GUICtrlSetBkColor($iBtn, $GUI_BKCOLOR_TRANSPARENT)
  180.     GUICtrlSetColor($iBtn, 0x0)
  181.     Return GUICtrlGetHandle($iBtn)
  182. EndFunc
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement