Имя пользователя:
Пароль:
 

Показать сообщение отдельно

Новый участник


Сообщения: 25
Благодарности: 0

Профиль | Отправить PM | Цитировать


Спасибо, madmasles!
я тут написал немного другую функцию. она мне больше подходит, так как менюшки, с которыми я работаю, периодически меняются (количество пунктов меню, очередность). поэтому после каждого изменения для каждого пункта в меню измерять его положение относительно окошка, мне не очень хочется. вот код функции:

Код: Выделить весь код
; #Функция# -----------------------------------------------------------------------------------------------------------------------------
; Имя....................: SelectItemFromMonitorMenu
; Описание ..............: Выбирает пункт контекстного меню для иконки вашего приложения в трее 
; Параметры .............: $item - текст пункта меню (например: "Exit")
; Возвращаемые значения .: Успешно      - 1
;                          Ошибка       - 0
; Заметки ...............: $your_applications_window_title - title окошка вашего приложения, которое отображается в трее. 
;                                Вы можете его увидеть в секции ToolsBar в AutoIt Window Info, если наведете на курсор на иконку в трее.
; -----------------------------------------------------------------------------------------------------------------------------------------
#Include <GuiToolBar.au3>
#include <GuiMenu.au3>

Func SelectItemFromMonitorMenu($item)
	Opt("MouseCoordMode", 1)
	$ind = 0
	$hWnd = ControlGetHandle("[CLASS:Shell_TrayWnd]","","[CLASS:ToolbarWindow32; TEXT:Notification Area]")
	if $hWnd = "" Then
		ConsoleWrite("Can't get hwnd of bottom toolbar.")
		Return 0
	EndIf
	
	$tray_icon_count = _GUICtrlToolbar_ButtonCount($hWnd)
	
	For $i = 0 to $tray_icon_count
		$command_id = _GUICtrlToolbar_IndexToCommand($hWnd, $i)
		$text = _GUICtrlToolbar_GetButtonText($hWnd, $command_id)
		if StringInStr($text,$your_applications_window_title) = 0 Then
			ContinueLoop
		Else
			$index = $i
			ExitLoop
		EndIf
	Next
	
	_GUICtrlToolbar_ClickIndex($hWnd, $index, "right") 
	Sleep(100)
	
	$cur_pos = MouseGetPos()
	if IsArray($cur_pos) = 0 Then
		ConsoleWrite("Can't get position of current mouse coordinate")
		Return 0
	EndIf

	if WinExists("[Class:#32768]") = 0 Then
		ConsoleWrite("Context menu is not appeared for tray icon.")
		Return 0
	Else
		$h_win = WinGetHandle("[Class:#32768]")
		if $h_win = "" Then
			ConsoleWrite("Can't get hwnd for application's context menu window.")
			Return 0
		EndIf
	
		$hMenu = _SendMessage($h_win, $MN_GETHMENU,0,0)
		
		$it_index = _GUICtrlMenu_FindItem($hMenu, $item,True)
		if $it_index = -1 Then
			ConsoleWrite("Can't find item " & $item & " in the application's context menu window.", $fail)
			Return 0
		EndIf
		
		$it_pos = _GUICtrlMenu_GetItemRect($h_win, $hMenu, $it_index)
		if IsArray($it_pos) = 0 Then
			ConsoleWrite("Can't get position of item " & $item & " in the application's context menu window.", $fail)
			Return 0
		EndIf
		
		MouseClick("left", $it_pos[0] + ($it_pos[2]-$it_pos[0])/2, $it_pos[1] + ($it_pos[3]-$it_pos[1])/2)
	EndIf
	
    MouseMove($cur_pos[0], $cur_pos[1])
	Return 1
EndFunc

Отправлено: 10:42, 26-05-2010 | #3