Jump to content
Sign in to follow this  
G11ntester

How to get menu item string from a resource dll?

Recommended Posts

G11ntester

Hi,

I want get item string from a resource dll.  The menu info in PE Explorer is like this: 

101 MENU
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
{
POPUP "Popup"
{
    MENUITEM "TEXT1", 1012
    MENUITEM "TEXT2", 1013
    MENUITEM "TEXT3", 1014
    MENUITEM "TEXT4", 1015
}
}

How can I get the string (for example: "Text1") from this dll? Thanks in advance!

I tried function "_GUICtrlMenu_LoadMenu" but could not make it work ...

#include <WinAPI.au3>
$hInstance=_WinAPI_LoadLibrary(@ScriptDir&"\resource.dll")
$hMenu= _GUICtrlMenu_LoadMenu ($hInstance, <what should I use here?>)
$string=_GUICtrlMenu_GetItemInfo($hMenu, 1012??)

Share this post


Link to post
Share on other sites
Yashied

#Include <APIConstants.au3>
#Include <WinAPIEx.au3>

Global Const $MFR_END = 0x0080
Global Const $MFR_POPUP = 0x0010

Global Const $tagMENUHEADER = 'WORD Version;WORD HeaderSize'
Global Const $tagNORMALMENUITEM = 'WORD Flags;WCHAR Text[4096]'
Global Const $tagPOPUPMENUITEM = 'WORD Flags;WORD ID;WCHAR Text[4096]'

$hLibrary = _WinAPI_LoadLibraryEx(@AutoItExe, $LOAD_LIBRARY_AS_DATAFILE)
$hInfo = _WinAPI_FindResource($hLibrary, $RT_MENU, 166)
$Length = _WinAPI_SizeOfResource($hLibrary, $hInfo)
$hResource = _WinAPI_LoadResource($hLibrary, $hInfo)
$pData = _WinAPI_LockResource($hResource)
If @Error Then
    Exit
EndIf

$tMENUHEADER = DllStructCreate($tagMENUHEADER, $pData)
Switch DllStructGetData($tMENUHEADER, 'Version')
    Case 0 ; Standard menu template

    Case Else
        Exit
EndSwitch

$Offset = DllStructGetSize($tMENUHEADER)
$Tab = @TAB

ConsoleWrite('166 MENU' & @CR)
ConsoleWrite('LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_UK' & @CR)
ConsoleWrite('{' & @CR)

While $Offset < $Length
    $Flags = DllStructGetData(DllStructCreate('WORD', $pData + $Offset), 1)
    If BitAND($Flags, $MFR_POPUP) Then
        $tMENUITEM = DllStructCreate($tagNORMALMENUITEM, $pData + $Offset)
        $Size = _WinAPI_StrLen(DllStructGetPtr($tMENUITEM, 'Text'))
        ConsoleWrite($Tab & 'POPUP "' & DllStructGetData($tMENUITEM, 'Text') & '"' & @CR)
        ConsoleWrite($Tab & '{' & @CR)
        $Offset += 2
        $Tab &= @TAB
    Else
        $tMENUITEM = DllStructCreate($tagPOPUPMENUITEM, $pData + $Offset)
        $Size = _WinAPI_StrLen(DllStructGetPtr($tMENUITEM, 'Text'))
        If $Size Then
            ConsoleWrite($Tab & 'MENUITEM "' & StringReplace(DllStructGetData($tMENUITEM, 'Text'), @TAB, '\t') & '", ' & DllStructGetData($tMENUITEM, 'ID') & @CR)
        Else
            ConsoleWrite($Tab & 'MENUITEM SEPARATOR' & @CR)
        EndIf
        $Offset += 4
        If BitAND($Flags, $MFR_END) Then
            $Tab = StringTrimRight($Tab, 1)
            ConsoleWrite($Tab & '}' & @CR)
        EndIf
    EndIf
    $Offset += 2 * ($Size + 1)
WEnd

ConsoleWrite('}' & @CR)

Share this post


Link to post
Share on other sites
G11ntester

Thanks, Yashied! I read through the corresponding functions in WinAPIEx.au3 and descriptions about resource structures on MSDN today, and learned a lot.

And I was awared that you are the author of WinAPIEx.au3, right?  Thanks again for providing these useful WinAPI related functions to us!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×