Advertisement
AZJIO

конт. меню кнопки

Nov 18th, 2011
430
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
AutoIt 2.51 KB | None | 0 0
  1. #include <GUIConstantsEx.au3>
  2. #include <WinAPI.au3>
  3.  
  4. $hGUI=GUICreate('My Program', 250, 260)
  5. $iExport=GUICtrlCreateButton('Start', 10, 10, 120, 22)
  6.  
  7.  
  8. $iExportContext = GUICtrlCreateDummy()
  9. $iExportContextMenu = GUICtrlCreateContextMenu($iExportContext)
  10. $iExportContextItem1 = GUICtrlCreateMenuItem('HTML', $iExportContextMenu)
  11. $iExportContextItem2 = GUICtrlCreateMenuItem('fuf', $iExportContextMenu)
  12. $iExportContextItem3 = GUICtrlCreateMenuItem('ещё', $iExportContextMenu)
  13. $iExportContextItem4 = GUICtrlCreateMenuItem('угу', $iExportContextMenu)
  14.  
  15. GUISetState ()
  16. GUIRegisterMsg(0x004E, "WM_NOTIFY")
  17. While 1
  18.     $msg = GUIGetMsg()
  19.     Switch $msg
  20.         Case $iExport
  21.             _GUICtrlButton_ContextMenuEx($hGUI, $iExport, $iExportContextMenu)
  22.         Case -3
  23.              Exit
  24.     EndSwitch
  25. WEnd
  26.  
  27. Func WM_NOTIFY($hWnd, $Msg, $wParam, $lParam)  
  28.     #forceref $hWnd, $Msg, $wParam
  29.     Local Const $BCN_HOTITEMCHANGE = -1249
  30.     Local $tNMBHOTITEM = DllStructCreate("hwnd hWndFrom;int IDFrom;int Code;dword dwFlags", $lParam)
  31.     Local $nNotifyCode = DllStructGetData($tNMBHOTITEM, "Code")
  32.     ; Local $nID = DllStructGetData($tNMBHOTITEM, "IDFrom")
  33.     ; Local $hCtrl = DllStructGetData($tNMBHOTITEM, "hWndFrom")
  34.     Local $dwFlags = DllStructGetData($tNMBHOTITEM, "dwFlags")
  35.    
  36.     Switch $nNotifyCode
  37.         Case $BCN_HOTITEMCHANGE ; Win XP and Above
  38.             If BitAND($dwFlags, 0x10) = 0x10 Then
  39.                 _GUICtrlButton_ContextMenuEx($hGUI, $iExport, $iExportContextMenu)
  40.                 ControlFocus($iExport, "", "Edit1")
  41.             ElseIf BitAND($dwFlags, 0x20) = 0x20 Then
  42.                 ; Send('{Enter}')
  43.                 ; Send('{DOWN}')
  44.             EndIf
  45.     EndSwitch
  46.     Return $GUI_RUNDEFMSG
  47. EndFunc
  48.  
  49. Func _GUICtrlButton_ContextMenuEx($hHandle, $iControlID, $iContextMenu)
  50.     Local $aControlGetPos, $hMenu, $iX, $iY
  51.     $hMenu = GUICtrlGetHandle($iContextMenu)
  52.     $aControlGetPos = ControlGetPos($hHandle, "", $iControlID)
  53.     $iX = $aControlGetPos[0]
  54.     $iY = $aControlGetPos[1] + $aControlGetPos[3]
  55.     _ClientToScreen($hHandle, $iX, $iY)
  56.     DllCall("user32.dll", "int", "TrackPopupMenuEx", "hwnd", $hMenu, "int", 0, "int", $iX, "int", $iY, "hwnd", $hHandle, "ptr", 0)
  57. EndFunc   ;==>_GUICtrlButton_ContextMenuEx
  58.  
  59. Func _ClientToScreen($hHandle, ByRef $iX, ByRef $iY)
  60.     Local $tPoint
  61.     $tPoint = DllStructCreate("int X;int Y")
  62.     DllStructSetData($tPoint, 1, $iX)
  63.     DllStructSetData($tPoint, 2, $iY)
  64.     _WinAPI_ClientToScreen($hHandle, $tPoint)
  65.     $iX = DllStructGetData($tPoint, 1)
  66.     $iY = DllStructGetData($tPoint, 2)
  67. EndFunc   ;==>_ClientToScreen
  68.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement