Random Musings from the Intellectually Gifted. How's that for no ego? :pfft
I'm having a brain fart. Any help would be appreciated.

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?



Comments (Page 1)
3 Pages1 2 3 
on Jul 29, 2007
I'm part way there and have cut 300 plus lines of code down to around 40.

Code: vbscript
  1. '--Builds Right Click Menu
  2. Sub rcMenu
  3. Dim submenu,menu
  4. '--Gets Sub Folder Collection
  5. intSize = 0
  6. Set objFSO = CreateObject("Scripting.FileSystemObject")
  7. strFolderName = "C:\Programming\Projects\DesktopX\WIP\Reflector\Reflector\skins"
  8. 'strFolderName = DesktopX.ExecutableDirectory &"\skins"
  9. Set objFSO = CreateObject("Scripting.FileSystemObject")
  10. Set objFolder = objFSO.GetFolder(strFolderName)
  11. Set colSubfolders = objFolder.Subfolders
  12. '--Loads subfolder collection into array
  13. For Each objSubfolder In colSubfolders
  14. strFolderName = objSubfolder.Path
  15. ReDim Preserve arrFolders(intSize)
  16. arrFolders(intSize) = strFolderName
  17. intSize = intSize + 1
  18. Next
  19. '--Builds first part of submenu
  20. Set submenu = DesktopX.CreatePopupMenu
  21. submenu.AppendMenu 0, 1, "About Skin"
  22. submenu.AppendMenu &H00000008, 2, curSkin
  23. submenu.AppendMenu&H00000800,1000,1000 'Menu separator
  24. '--Iterates through subfolder collection & retrievs skin info
  25. For Each strFolder In arrFolders
  26. i = i+1
  27. strname = "skin" & i
  28. 'msgbox strname
  29. pathSkin=strFolder
  30. skin=pathSkin&"\skin.ini"
  31. skinArray=FileToArray(skin, False)
  32. nskin=skinArray(1) '1 Fields Skin Name
  33. posNum=2+i
  34. submenu.AppendMenu 0, posNum, nskin
  35. 'msgbox posNum&nskin
  36. Next
  37. '--Finish building submenu
  38. submenu.AppendMenu&H00000800,1001,1001 'Menu separator
  39. submenu.AppendMenu 0, 13, "Select"
  40. Set menu = DesktopX.CreatePopupMenu
  41. menu.AppendMenu &H00000010, submenu.MenuID, "Skins"
  42. menu.AppendMenu 0, 93, "About"
  43. menu.AppendMenu 0, 98, "Exit"
  44. 'menu.AppendMenu 0, 99, "DesktopX"
  45. Dim rtn
  46. rtn = menu.TrackPopupMenu(0, System.CursorX, System.CursorY)
  47. Select Case rtn
  48. Case 1
  49. Call aboutSkin
  50. Case posNum
  51. 'msgbox posNum
  52. skinPath=pathSkin
  53. Call applySkin(pathSkin,skin)
  54. Case 13
  55. file = System.FileOpenDialog("Select Skin File", "skin.ini", strFolderName, "*.ini|*.ini",0)'--Browse for all file types
  56. Set objFSO = CreateObject("Scripting.FileSystemObject")
  57. fPath=objFSO.GetParentFolderName(file)
  58. iFile= objFSO.GetFileName(file)
  59. skinPath=fPath
  60. Call applySkin(fPath,iFile)
  61. Set objFSO=nothing
  62. Case 93
  63. Call aboutBox
  64. Case 98
  65. DesktopX.Exit(0)
  66. End Select
  67. Set menu = nothing
  68. If rtn 99 Then
  69. Object_OnRButtonUp=True
  70. End If
  71. End Sub
on Jul 30, 2007
Hello... Is anyone out there?
on Jul 30, 2007
Sorry.. i read this this morning, and didnt see what you were looking for.

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.
on Jul 30, 2007
Ok, i have to work on this.. let me change some things.. give me about 2hrs
on Jul 30, 2007
No problem. Thanks.

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.
on Jul 30, 2007
ok, create a new object (for testing this out) Copy/paste the following code into it:
Code: vbscript
  1. 'Called when the script is executed
  2. Dim Item(10)
  3. Sub Object_OnScriptEnter
  4. For x = 1 To 10
  5. Item(x) = "Item " & x
  6. Next
  7. End Sub
  8. 'Called when the script is terminated
  9. Sub Object_OnScriptExit
  10. End Sub
  11. Function PopupMenu()
  12. Set SubMenu = nothing
  13. Set SubMenu = DesktopX.CreatePopupMenu
  14. For x = 1 To 10
  15. SubMenu.AppendMenu 0, x, Item(x)
  16. Next
  17. Set mainmenu = nothing
  18. Set mainmenu = DesktopX.CreatePopupMenu '-- Create Main Men
  19. mainmenu.AppendMenu &H00000010, SubMenu.MenuID, "Pick an Item..."
  20. mainmenu.AppendMenu &H00000800, 0, ""
  21. mainmenu.AppendMenu 0, 999, "Cancel"
  22. result = mainmenu.TrackPopupMenu(0, System.CursorX, System.CursorY)
  23. If result > 1 And result < 999 Then
  24. msgbox "You Selected " & Item(result)
  25. End If
  26. If result = 999 Then MsgBox "You clicked Cancel"
  27. End Function
  28. Function Object_OnLButtonUp(x, y, Dragged)
  29. If Dragged = False Then
  30. Call PopupMenu()
  31. End If
  32. 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?
on Jul 30, 2007
Okay. I think your script just pointed out where I was going wrong.

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.


Code: vbscript
  1. '--Gets Sub Folder Collection
  2. intSize = 0
  3. Set objFSO = CreateObject("Scripting.FileSystemObject")
  4. strFolderName = "C:\Programming\Projects\DesktopX\WIP\Reflector\Reflector\skins"
  5. 'strFolderName = DesktopX.ExecutableDirectory &"\skins"
  6. Set objFSO = CreateObject("Scripting.FileSystemObject")
  7. Set objFolder = objFSO.GetFolder(strFolderName)
  8. Set colSubfolders = objFolder.Subfolders
  9. '--Loads subfolder collection into array
  10. For Each objSubfolder In colSubfolders
  11. strFolderName = objSubfolder.Path
  12. ReDim Preserve arrFolders(intSize)
  13. arrFolders(intSize) = strFolderName
  14. intSize = intSize + 1
  15. Next
  16. 'This is the For Each Statement from within the submenu
  17. For Each strFolder In arrFolders
  18. i = i+1
  19. strname = "skin" & i
  20. 'msgbox strname
  21. pathSkin=strFolder
  22. skin=pathSkin&"\skin.ini"
  23. skinArray=FileToArray(skin, False)
  24. nskin=skinArray(1) '1 Fields Skin Name
  25. posNum=2+i
  26. submenu.AppendMenu 0, posNum, nskin
  27. 'msgbox posNum&nskin
  28. Next
on Jul 30, 2007
So, its working?
on Jul 30, 2007
on Jul 30, 2007
It's getting there. I've nested an array within an array. In simple terms what I'm trying to accomplish.

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.
on Jul 30, 2007
Ok, so.. the part you needed help with is done?
on Jul 30, 2007
It would take a lot more than one thread to help me out!

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.
on Jul 30, 2007
Let me know if i can help more (email works)
on Jul 31, 2007
This is interesting. I was doing something like this for a skinnable clock. Wouldn't it be easier to retrieve all the information and set the arrays in a separate sub on startup and any time the information changes instead of in the r-click function?
on Jul 31, 2007
I use this same setup for the Holiday Countdown Pro, and i read things into a recordset, this works great for me because i can use it like a temporary database. I read the info into the recordset at the beginning of the program. Then any time i need to update/edit/add i can modify the recordset, then with the right-click it reads the recordset as a loop (like above).

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.
3 Pages1 2 3