Menu status check vs hilight reflection problem

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
GS SAHU
Posts: 37
Joined: 29 Sep 2014, 12:18

Menu status check vs hilight reflection problem

05 Nov 2015, 10:09

i am trying to hook menu by hilight value of a menu but when a menu have check status its reflect check status in place of hilight value.
check status value = 8
hilight value = 128

Code: Select all

#SingleInstance,Force
SetBatchLInes,-1
AutoTrim,Off 
DllCall("AllocConsole")
global stdout
global current_id
Run, Notepad.exe,,, pid
WinWait, Untitled - Notepad
hWnd := WinExist("ahk_pid" . pid)
hModule := DllCall("LoadLibrary", "Str", "user32.dll", "Ptr")
hMenu:=DllCall("user32\GetMenu","UInt",hWnd)
_CreateMenu(hWnd)
#IfWinActive, ahk_pid  pid
  while  WinExist("ahk_pid" . pid)
      GETMENU(hMenu)

Return
Esc::
DllCall("FreeLibrary", "Ptr", hModule)
ExitApp

GETMENU(hMenu)
{
stdout :=FileOpen("*", "w `n")
nMaxCount=100
  uFlag:=0x0400  ;MF_BYPOSITION
  menuitemcount:=DllCall("GetMenuItemCount",UInt,hMenu)
  Loop,%menuitemcount%
  {
    nPos:=A_Index-1

	hSubMenu:=DllCall("user32\GetSubMenu","UInt",hMenu,"int",nPos) 
    If hSubMenu>0
    {
      GETMENU(hSubMenu)
    }
    else
    {
    state := MenuState(hMenu,nPos)
  
    if (state = 128)
	{
	nID := DllCall("GetMenuItemID", "Uint", hMenu, "Uint", nPos)
    VarSetCapacity(lpString,100,0)
    length:=DllCall("user32\GetMenuString","UInt",hMenu,"UINT",nPos,"STR",lpString,"int",nMaxCount,"UINT",uFlag) 
	 
      if (current_id <> nID)
      {
       stdout.Write( nPos	. "state " . state . lpString . " " . nID . "`n")
      state := 0
      current_id := nID
        
      }
     
	}
    
    If (current_id <> 0)
    {
        ; If mouse clicked or Enter pressed
        
        If (_IsPressed("01") || _IsPressed("0D") || GetKeyState("Enter","P") || GetKeyState("LButton","P"))
        {       
            ; This is where you do what the selection is there for!!!!!!!!!
            stdout.Write("You selected " . current_id . "`n")
            ; Prevent "double tap"
            current_id := 0
            keystate := ""
            ; Wait until mouse/Enter released
            While, (_IsPressed("0D") || _IsPressed("01"))
                Sleep 10
            
        }
    }
     
    
    }
  }
  
}

MenuState(hSubMenu, index)
{
VarSetCapacity(mii,48,0)
NumPut(48, mii, 0)
; Set the mask to whatever you want to retrieve.
; In this case I set it to MIIM_STATE=1.
NumPut(1, mii, 4)
; Note that menu item positions are zero-based.
DllCall("GetMenuItemInfo", "UInt", hSubMenu, "UInt", index, "UInt", true, "UInt", &mii)
; Get the state field out of the struct.
fState := NumGet(mii, 12)
return fState
}

_IsPressed(sHexKey)
{
	; $hexKey must be the value of one of the keys.
	; _Is_Key_Pressed will return 0 if the key is not pressed, 1 if it is.
	Rt := DllCall("GetAsyncKeyState", "int", "0x" . sHexKey)
	Return (RT & 0x8000) <> 0
}

;Create Menu
_CreateMenu(hWndTarget)
{
IDM_TEST := 0
STR_TEST := "AHK"
MF_BYPOSITION = 0x400
MF_SEPARATOR = 0x800
MF_STRING = 0x000
MF_POPUP:=16
hMenu := DllCall("GetMenu", Int, hWndTarget)
hItem1 := DllCall("CreateMenu")
Result := DllCall("AppendMenu", Int, hMenu, Int, MF_POPUP, "Ptr", hItem1, Str, "Ahk")
DllCall("InsertMenu", "int", hItem1, "int", 0, "int", MF_BYPOSITION | MF_STRING, "int", 50001, "str", "item1")
DllCall("InsertMenu", "int", hItem1, "int", 1, "int", MF_BYPOSITION | MF_STRING, "int", 50002, "str", "item2")
DllCall("SetMenu", "Ptr", hItem1,"Ptr", hMenu)
DllCall("DrawMenuBar", "Int", hWndTarget)
}
above code successfully hook menu. but there is two problem.
1. use cpu in large amount.
2. which menu reflect check status(8) i can not got hilight value(128).

if you have any help pls. tell me.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: bob65536, tomaxtoro and 169 guests