Jump to content



Photo

Creating a menu based on data from INI


  • Please log in to reply
2 replies to this topic

#1 Yashied

Yashied

    Happy in Moscow

  • MVPs
  • 2,512 posts

Posted 05 January 2011 - 09:38 AM

Note that icons will only work in Windows Vista and later. Also need a WinAPIEx UDF library.

:x

Settings.ini

Plain Text         
[Menu] Open=File>Open Save=File>Save SaveAs=File>Save As... Copy=Edit>Copy Paste=Edit>Paste Separator=* Skin=Preferences>Interface>Skin Size=Preferences>Interface>Size Color=Preferences>Interface>Color Separator=Preferences>Interface>* Expert=Preferences>Interface>Advanced... Miscellaneous=Preferences>Miscellaneous... Separator=* Exit=Exit [Icon] Open=shell32.dll,45 Save=shell32.dll,258 SaveAs=shell32.dll,68 Copy=shell32.dll,134 Paste=shell32.dll,260 Skin=shell32.dll,303 Size=shell32.dll,240 Color=mspaint.exe,0 Expert=shell32.dll,300 Miscellaneous=shell32.dll,21 Exit=shell32.dll,131

Posted Image

Attached Files

  • Attached File  Menu.zip   6.61K   522 downloads

Edited by Yashied, 05 January 2011 - 09:48 AM.






#2 guinness

guinness

    guinness

  • MVPs
  • 10,299 posts

Posted 05 January 2011 - 10:08 AM

Wow! You never cease to amaze me. This is going in the Function Folder.

Example List: _AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_DesktopDimensions()_DisplayPassword()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUISetIcon()_Icon_Clear()/_Icon_Set()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringIsValid()_StringReplaceWholeWord()_StringStripChar()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()AutoIt SearchAutoIt3 PortableAutoItWinGetTitle()/AutoItWinSetTitle()CodingFileInstallrGeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIGetBkColor()LockFile()PasteBinSciTE JumpSignature CreatorWM_COPYDATAMore Examples...Updated: 11/04/2013


#3 guinness

guinness

    guinness

  • MVPs
  • 10,299 posts

Posted 21 January 2011 - 10:38 PM

So I was quite inspired by your TrayMenu with Icons from ico/exe files that I decided to have a go at creating a Function that could convert an Image File and then display in the TrayMenu. This is how I came about creating _GUICtrlMenu_SetItemImage() using the Forum as a basis to learn. :)

Note: I used this post >> http://www.autoitscript.com/forum/topic/115491-createbitmapfromicon/page__view__findpost__p__806834 from UEZ as a basis for creating the Function!

Of course I know it can be improved, especially tidying up the resources, but for now it works!

AutoIt         
#include <GDIPlus.au3> #include <GUIMenu.au3> Opt('TrayMenuMode', 3) _GDIPlus_Startup() Example() Func Example()     Local $hGUI = GUICreate('')     Local $iSettingsItem = TrayCreateMenu('Settings')     _GUICtrlMenu_SetItemBmp(TrayItemGetHandle(0), 0, _WinAPI_CreateSolidBitmap($hGUI, 0xFF00FF, 15, 15)) ; Set Image to Settings.     Local $iDisplayItem = TrayCreateItem('Display', $iSettingsItem)     Local $hImage_1 = _GUICtrlMenu_SetItemImage(@ScriptDir & 'Example.png', 0, $iSettingsItem) ; Set Image to Sub-Menu in Settings under Display.     TrayCreateItem('Printer', $iSettingsItem)     Local $hImage_2 = _GUICtrlMenu_SetItemImage(@ScriptDir & 'Example.png', 1, $iSettingsItem) ; Set Image to Sub-Menu in Settings under Printer.     TrayCreateItem('Delete')     Local $hImage_3 = _GUICtrlMenu_SetItemImage(@ScriptDir & 'Example.png', 1) ; Set Image to Delete.     TrayCreateItem('')     TrayCreateItem('About')     TrayCreateItem('')     Local $iExitItem = TrayCreateItem('Exit')     TraySetState()     While 1         Switch TrayGetMsg()             Case $iExitItem                 ExitLoop             Case $iDisplayItem                 MsgBox(0, 'Display/About', 'Display Or About Was Clicked!')         EndSwitch         Sleep(10)     WEnd     _WinAPI_DeleteObject($hImage_1) ; <<<< Delete Icon Image.     _WinAPI_DeleteObject($hImage_2) ; <<<< Delete Icon Image.     _WinAPI_DeleteObject($hImage_3) ; <<<< Delete Icon Image.     GUIDelete($hGUI)     _GDIPlus_Shutdown() EndFunc   ;==>Example Func _GUICtrlMenu_SetItemImage($hImageFile, $iIndex, $hWnd = 0, $iWidth = 35, $iHeight = 35) ; Set Image to Tray/GUI Menu.     $hWnd = TrayItemGetHandle($hWnd)     Local $hImage = _GDIPlus_BitmapCreateFromFile($hImageFile)     Local $iImageWidth = _GDIPlus_ImageGetWidth($hImage)     Local $iImageHeight = _GDIPlus_ImageGetHeight($hImage)     If ($iImageWidth < 0) Or ($iImageHeight < 0) Then         Return SetError(1, 0, 0)     EndIf     If $iImageWidth < $iImageHeight Then         $iImageWidth = $iWidth * $iImageWidth / $iImageHeight         $iImageHeight = $iHeight     Else         $iImageHeight = $iHeight * $iImageHeight / $iImageWidth         $iImageWidth = $iWidth     EndIf     Local $aResult = DllCall($ghGDIPDll, 'uint', 'GdipCreateBitmapFromScan0', 'int', $iWidth, 'int', $iHeight, 'int', 0, 'int', 0x0026200A, 'ptr', 0, 'int*', 0)     Local $hBitmap = $aResult[6]     Local $hContext = _GDIPlus_ImageGetGraphicsContext($hBitmap)     _GDIPlus_GraphicsDrawImageRect($hContext, $hImage, 0, 0, $iWidth, $iHeight)     Local $hIcon = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap)     _GUICtrlMenu_SetItemBmp($hWnd, $iIndex, $hIcon)     _GDIPlus_GraphicsDispose($hContext)     _GDIPlus_BitmapDispose($hBitmap)     Return SetError(0, 0, $hIcon) EndFunc   ;==>_GUICtrlMenu_SetItemImage

Edited by guinness, 08 October 2012 - 08:30 PM.

Example List: _AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_DesktopDimensions()_DisplayPassword()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUISetIcon()_Icon_Clear()/_Icon_Set()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringIsValid()_StringReplaceWholeWord()_StringStripChar()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()AutoIt SearchAutoIt3 PortableAutoItWinGetTitle()/AutoItWinSetTitle()CodingFileInstallrGeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIGetBkColor()LockFile()PasteBinSciTE JumpSignature CreatorWM_COPYDATAMore Examples...Updated: 11/04/2013





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users