Показать полную графическую версию : [решено] Контекстное меню
Dreadfulangel
18-09-2009, 17:29
Подскажите как работать с контекстным меню?
Как можно вызвать определенный пукт контекстного меню в любой программе, без эмуляцией нажатий клавиш клавиатуры.
Как можно вызвать определенный пукт контекстного меню в любой программе »
Что не устраивает в этом примере?
#include <WindowsConstants.au3>
#include <SendMessage.au3>
#include <GuiMenu.au3>
;
Run (http://www.autoitscript.com/autoit3/docs/functions/Run.htm)("TaskMgr.exe")
WinWait (http://www.autoitscript.com/autoit3/docs/functions/WinWait.htm)("[CLASS:#32770;REGEXPTITLE:.*Windows.*]", "", 5)
$hTskMgr = WinGetHandle (http://www.autoitscript.com/autoit3/docs/functions/WinGetHandle.htm)("[CLASS:#32770;REGEXPTITLE:.*Windows.*]")
If (http://www.autoitscript.com/autoit3/docs/keywords.htm#If) Not (http://www.autoitscript.com/autoit3/docs/keywords.htm#Not) WinExists (http://www.autoitscript.com/autoit3/docs/functions/WinExists.htm)($hTskMgr) Then (http://www.autoitscript.com/autoit3/docs/keywords.htm#Then) Exit (http://www.autoitscript.com/autoit3/docs/keywords.htm#Exit) 1
$nCurrentTab = ControlCommand (http://www.autoitscript.com/autoit3/docs/functions/ControlCommand.htm)($hTskMgr, "", "SysTabControl321", "CurrentTab")
$nSubMenu_Item = 4 ;Change to 3th submenu (zero-based), now it will only show the "About" window.
If (http://www.autoitscript.com/autoit3/docs/keywords.htm#If) $nCurrentTab = 1 Then (http://www.autoitscript.com/autoit3/docs/keywords.htm#Then) $nSubMenu_Item += 1
$hMenu = _GUICtrlMenu_GetMenu($hTskMgr)
;Theese two is to activate the menu, strange bug, but GetItemSubMenu fails if the menu was not used (clicked)
ControlSend (http://www.autoitscript.com/autoit3/docs/functions/ControlSend.htm)($hTskMgr, "", $hMenu, "!_")
ControlClick (http://www.autoitscript.com/autoit3/docs/functions/ControlClick.htm)($hTskMgr, "", "SysTabControl321")
$hSubMenu = _GUICtrlMenu_GetItemSubMenu($hMenu, $nSubMenu_Item)
;2 = Shutdown, 3 = Restart (2 and 3 it's zero-based item from the top of menu)
$iItemID = _GUICtrlMenu_GetItemID($hSubMenu, 2)
$sItemText = _GUICtrlMenu_GetItemText($hSubMenu, $iItemID, 0)
If (http://www.autoitscript.com/autoit3/docs/keywords.htm#If) MsgBox (http://www.autoitscript.com/autoit3/docs/functions/MsgBox.htm)(262144+36, "GetItemText", StringFormat (http://www.autoitscript.com/autoit3/docs/functions/StringFormat.htm)("Item text: %s\nExecute?", $sItemText)) = 6 Then (http://www.autoitscript.com/autoit3/docs/keywords.htm#Then) _
_SendMessage($hTskMgr, $WM_COMMAND, $iItemID, 0)
И темы нужно называть более конкретно.
Dreadfulangel
20-09-2009, 18:19
В этом примере работаем с обычным меню, а необходимо с контекстным, которое появляется при нажатии правой кнопкой мыши.
В этом примере работаем с обычным меню, а необходимо с контекстным »
Тогда вот пример на редакторе реестра, где используются заранее известные ID-элементов (посмотреть можно с Reshacker):
#include <WindowsConstants.au3>
#include <SendMessage.au3>
;
If (http://www.autoitscript.com/autoit3/docs/keywords.htm#If) Not (http://www.autoitscript.com/autoit3/docs/keywords.htm#Not) ProcessExists (http://www.autoitscript.com/autoit3/docs/functions/ProcessExists.htm)("Regedit.exe") Then (http://www.autoitscript.com/autoit3/docs/keywords.htm#Then)
Run (http://www.autoitscript.com/autoit3/docs/functions/Run.htm)("Regedit.exe")
WinWait (http://www.autoitscript.com/autoit3/docs/functions/WinWait.htm)("[CLASS:RegEdit_RegEdit]")
EndIf (http://www.autoitscript.com/autoit3/docs/keywords.htm#EndIf)
$hRegEdit = WinGetHandle (http://www.autoitscript.com/autoit3/docs/functions/WinGetHandle.htm)("[CLASS:RegEdit_RegEdit]")
WinActivate (http://www.autoitscript.com/autoit3/docs/functions/WinActivate.htm)($hRegEdit)
_SendMessage($hRegEdit, $WM_COMMAND, 659, 0) ;Пункт "Экспортировать"
;_SendMessage($hRegEdit, $WM_COMMAND, 675, 0) ;Пункт "Копировать имя раздела"
Dreadfulangel
20-09-2009, 22:50
Большое спасибо за помощь. Теперь всё понятно.
В моём случае несколько особый тип меню наверное...
http://i.imagehost.org/0477/Snap6.png
Меню отображает плагины к программе, которые она как хост загружает динамически.
То-есть прога сканирует папку и загружает все возможные anyfilename.dll модули которые там находит.
Это я о том, что ResHacker здесь безполезен. Не знаю на сколько это обычная ситуация, но думаю
здесь подходит только нажатие по текст-содержимому паттерна. Знать бы как!
Первый пример довольно сложноватый я не осилил разобраться, тем боелее с TaskMgr.exe я уже как-то
сталкивался, одно из самых трудных окон! :) Может что попроще б?
Можно ли зделать Select на определённое слово в меню? (Кстати, я не вижу тут особой разницы простое или контекстное)
© OSzone.net 2001-2012
vBulletin v3.6.4, Copyright ©2000-2025, Jelsoft Enterprises Ltd.