[Help] Dynamically Create Right Click Menu Or Portion
Saturday, July 28, 2007 by SirSmiley | Discussion: DesktopX
So, I'm working on my first "Skinnable" Widget/Gadget which uses the ImageMagick Com object
to create a reflective PNG. This came about after a request over at Aqua-soft.
My goal is to populate a portion of the right click menu with a list of the skins. At the moment
I'm using a Subfolder Collection to pull all of the Ini file's. Has anyone got an idea on how to
dynamically populate the right click menu with the names & calls?

Reply #3 Monday, July 30, 2007 2:39 PM
YES It can be done, its a pain but it can be done.. let me find the code i used for this in the Holiday Countdown Pro.
Reply #4 Monday, July 30, 2007 2:43 PM
Reply #5 Monday, July 30, 2007 2:54 PM
Sorry for the impatience. I've tried a couple of different things and know I should step away from the code for a bit but, when you're close to being finished it's hard to let it go.
Reply #6 Monday, July 30, 2007 4:51 PM
- 'Called when the script is executed
- Dim Item(10)
- Sub Object_OnScriptEnter
- For x = 1 To 10
- Item(x) = "Item " & x
- Next
- End Sub
- 'Called when the script is terminated
- Sub Object_OnScriptExit
- End Sub
- Function PopupMenu()
- Set SubMenu = nothing
- Set SubMenu = DesktopX.CreatePopupMenu
- For x = 1 To 10
- SubMenu.AppendMenu 0, x, Item(x)
- Next
- Set mainmenu = nothing
- Set mainmenu = DesktopX.CreatePopupMenu '-- Create Main Men
- mainmenu.AppendMenu &H00000010, SubMenu.MenuID, "Pick an Item..."
- mainmenu.AppendMenu &H00000800, 0, ""
- mainmenu.AppendMenu 0, 999, "Cancel"
- result = mainmenu.TrackPopupMenu(0, System.CursorX, System.CursorY)
- If result > 1 And result < 999 Then
- msgbox "You Selected " & Item(result)
- End If
- If result = 999 Then MsgBox "You clicked Cancel"
- End Function
- Function Object_OnLButtonUp(x, y, Dragged)
- If Dragged = False Then
- Call PopupMenu()
- End If
- End Function
I'm not sure I'm getting what you are trying to do, because it looks like its doing what i just posted here. Can you show me an example of what you want it to do, and where the data is coming from?
Reply #7 Monday, July 30, 2007 5:22 PM
The array is being built from a the collection of subfolders & redim is used within a For Each statement to add each folder into the array.
Example Folder Structure:
Main Folder
|
|- Skins Folder
|
--------------
| | |
Skin1 Skin2 Skin3
Then I went and put an additional For Each Statement within the submenu structure then forgot to use redim which obviously overwrites the previous variable.
- '--Gets Sub Folder Collection
- intSize = 0
- Set objFSO = CreateObject("Scripting.FileSystemObject")
- strFolderName = "C:\Programming\Projects\DesktopX\WIP\Reflector\Reflector\skins"
- 'strFolderName = DesktopX.ExecutableDirectory &"\skins"
- Set objFSO = CreateObject("Scripting.FileSystemObject")
- Set objFolder = objFSO.GetFolder(strFolderName)
- Set colSubfolders = objFolder.Subfolders
- '--Loads subfolder collection into array
- For Each objSubfolder In colSubfolders
- strFolderName = objSubfolder.Path
- ReDim Preserve arrFolders(intSize)
- arrFolders(intSize) = strFolderName
- intSize = intSize + 1
- Next
- 'This is the For Each Statement from within the submenu
- For Each strFolder In arrFolders
- i = i+1
- strname = "skin" & i
- 'msgbox strname
- pathSkin=strFolder
- skin=pathSkin&"\skin.ini"
- skinArray=FileToArray(skin, False)
- nskin=skinArray(1) '1 Fields Skin Name
- posNum=2+i
- submenu.AppendMenu 0, posNum, nskin
- 'msgbox posNum&nskin
- Next
Reply #10 Monday, July 30, 2007 7:09 PM
1. Get all skin subfolders into array. Done
2. Pull each skin.ini path into an array. Done
3. Pull the skin names from second line (variable1) of the skin.ini file into another array for display in the right click menu. Done
4. Build the right click menu. On clicking the skin name calls skin.ini into the applyskin sub & automatically updates the default settings file. Still working on this.
Reply #12 Monday, July 30, 2007 8:30 PM
Much appreciated. This got me going in the right direction.
I'll probably just upload it as a gadget & the object since I'm building it as a gadget. So, you'll be able to see what I'm trying to accomplish.
Reply #14 Tuesday, July 31, 2007 1:09 AM
Reply #15 Tuesday, July 31, 2007 7:01 AM
It could easily be setup to read the entire ini and all info at startup (or at a set interval in case of updates). Then read that into the menu.
Reply #16 Tuesday, July 31, 2007 11:07 AM
It could easily be setup to read the entire ini and all info at startup (or at a set interval in case of updates). Then read that into the menu.
Yeah, that's what I was doing. I just wondered if there were any benefits to retreiving the info on r-click instead. This is the r-click code I used for it:
- Function PopupMenu()
- Dim submenu
- Set mainmenu = nothing
- Set mainmenu = DesktopX.CreatePopupMenu '-- Create Main Menu
- Set submenu = DesktopX.CreatePopupMenu
- mainmenu.AppendMenu 0, 1, "Save Skin"
- mainmenu.AppendMenu &H00000010, submenu.MenuID, "Load Skin"
- mainmenu.AppendMenu &H00000800, 9998, ""
- mainmenu.AppendMenu 0, 2, "Minimize to Tray"
- mainmenu.AppendMenu 0, 3, "Close"
- mainmenu.AppendMenu &H00000800, 9999, ""
- mainmenu.AppendMenu 0, 4, "Preference"
- mainmenu.AppendMenu 0, 5, "About"
- 'Skins submenu
- For x = 0 To skincount
- submenu.AppendMenu 0, x+5, skinArr(x)
- Next
- '-- Save the results of mouse movements
- result = mainmenu.TrackPopupMenu(0, System.CursorX, System.CursorY)
- Select Case result
- Case 1
- savePrompt
- Case 2
- widget.Minimize
- Case 3
- widget.Close
- Case 4
- widget.OpenProperties
- Case 5
- msgbox "My about box"
- End Select
- If result > 5 Then
- selectskin = skinArr(result-6)
- Call loadSkin(2, selectskin)
- End If
- End Function
loadSkin is the sub that retrieves all the info (current skin, skin titles) on startup and when the user loads a skin.
Reply #17 Tuesday, July 31, 2007 11:11 AM

Not only is it easier you'll find it runs up the RAM if you put it into the right click since it calls the code every time you initiate the right click menu.
RomanDA, that's a great idea. It also is probably easier on resources & maybe less likely to break the code with repeated FSO calls?
I've created one little glitch. If you click the right click menu then don't click a menu item (ie. close the menu) for some reason it automatically calls/applies the first skin in the list. Haven't given much work into this but, I'm wondering if it's not related to the fact that I've made the For Next statement's zero based?
Reply #18 Tuesday, July 31, 2007 11:16 AM
I feel embarrassed to show mine.
Reply #19 Tuesday, July 31, 2007 1:37 PM
But, but, if you don't, then who will I snag all these useful codes snippets from?! I always learn something new from studying your scripts.
What about using Case Else? Like:
Case Else
object.state = object.state
I used that once when I was having trouble with closing the menu.
Reply #20 Tuesday, July 31, 2007 5:54 PM
I find the same from your. Your Script Helper saves me a great deal of time.
Please login to comment and/or vote for this skin.
Welcome Guest! Please take the time to register with us.
There are many great features available to you once you register, including:
- Richer content, access to many features that are disabled for guests like commenting on the forums and downloading skins.
- Access to a great community, with a massive database of many, many areas of interest.
- Access to contests & subscription offers like exclusive emails.
- It's simple, and FREE!







Reply #1 Sunday, July 29, 2007 2:38 PM