Jump to content

[Solved] Get Menu Name from Context Menu


IanN1990
 Share

Recommended Posts

So i have been working on this idea for the last idea with not much luck.

The following code brings up a context menu with 1 menu and 1 item. If you click the item, it retrives the item name you clicked.

Is there any way for clicking the "Menu" and once it has closed it tells me the menu that was clicked.

Code for Getting Menu Items

#include <GuiMenu.au3>
#include 'WindowsConstants.au3'
Local $GUIContextMenu = GUICreate("Context Menu", 1, 1, -5, -5, $WS_POPUP, $WS_EX_TOOLWINDOW)
local $MainContextMenu = GUICtrlCreateContextMenu()
local $ContextHandle = GUICtrlGetHandle($MainContextMenu)
local $MousePosition = mousegetpos()

$Example = GUICtrlCreateMenu("ExampleMenu", $MainContextMenu)
GUICtrlCreateMenuItem("ExampleItem", $Example)

$ContextMenu = _GUICtrlMenu_TrackPopupMenu($ContextHandle, $GUIContextMenu, $MousePosition[0]-10, $MousePosition[1]-10, 1, 1, 2)
$ContextMenuItem = _GUICtrlMenu_GetItemText($ContextHandle, $ContextMenu, False)
ConsoleWrite($ContextMenuItem)

Fail code that kinda shows the end result i am after. By Right clicking, it closes the context menu but can only bring up the name of the first menu. Not one that is highlighted or clicked ;(

#include <GuiMenu.au3>
#include 'WindowsConstants.au3'
Local $GUIContextMenu = GUICreate("Context Menu", 1, 1, -5, -5, $WS_POPUP, $WS_EX_TOOLWINDOW)
local $MainContextMenu = GUICtrlCreateContextMenu()
local $ContextHandle = GUICtrlGetHandle($MainContextMenu)
local $MousePosition = mousegetpos()

$hM_Module = DllCall("kernel32.dll", "hwnd", "GetModuleHandle", "ptr", 0)
DllCall("user32.dll", "hwnd", "SetWindowsHookEx", "int", $WH_MOUSE_LL, "ptr", DllCallbackGetPtr(DllCallbackRegister("MouseHook", "int", "int;ptr;ptr")), "hwnd", $hM_Module[0], "dword", 0)

GUICtrlCreateMenu("ExampleMenu", $MainContextMenu)
GUICtrlCreateMenu("ExampleMenu2", $MainContextMenu)

$ContextMenu = _GUICtrlMenu_TrackPopupMenu($ContextHandle, $GUIContextMenu, $MousePosition[0]-10, $MousePosition[1]-10, 1, 1, 2)
$ContextMenu = _GUICtrlMenu_GetItemText($ContextHandle, $ContextMenu, True)
ConsoleWrite($ContextMenu)

Func MouseHook($nCode, $wParam, $lParam)
$MouseHook = DllStructGetData(DllStructCreate("struct;long X;long Y;endstruct;dword mouseData;dword flags;dword time;ulong_ptr dwExtraInfo", $lParam), 3)
If $wParam = 0x00000205 then WinClose("[Class:#32768]") ;;Right click to close menu
EndFunc
Edited by IanN1990
Link to comment
Share on other sites

Good question, I have not encluded the full code into this snippet but this is rather code examples of what i am trying to achive. The full code searchs the pc and lists thousands of files, within hundreds of folders. Which so many items, listing every indivial menu item is not very pratical and also loses a sentense of real-time goodness. As if i downloaded a new file or added a new video, i would need to hardcode it into the event.

Reason for this is, because i wanted the ability to "click" a menu "which is normally folders" and open that folder directly letting me broswe the files in windows explorer. but for this to happen i need to know the name of the menu that has been clicked. Ego why i have started this topic :)

Link to comment
Share on other sites

Seams i completely missunderstood what you ment then. I have downloaded the UDF you linked, but truth be told dont understand it at all *I dont really work with GUIS alot, and this Context menu idea was my first attempt with it). I normally learn best from examples, but the example given with the download is a bit confusing.

So it will prob take me a while to understand it and then apply it to my problem amusing it will all work out.

Link to comment
Share on other sites

I have done an example, but the UDF only works if the GUI is showed (and I'm wondering why you are not using a GUI if you are using a contextmenu)

#include <WindowsConstants.au3>
#include "onEventFunc.au3"

Opt("GUIOnEventMode", 1)

$GUIContextMenu = GUICreate("Context Menu", 250, 250, -1, -1, $WS_POPUP, $WS_EX_TOOLWINDOW)

$MainContextMenu = GUICtrlCreateContextMenu()
$ContextHandle = GUICtrlGetHandle($MainContextMenu)
GUISetState()

$Example = GUICtrlCreateMenu("ExampleMenu", $MainContextMenu)
$ExampleItem = GUICtrlCreateMenuItem("ExampleItem", $Example)
SetOnEventA($ExampleItem, "_MenuItemEvent", $PARAMBYVAL, "ExampleItem")

While 1
Sleep(1000)
WEnd

Func _MenuItemEvent($sMenuItemName)
ConsoleWrite("$sMenuItemName: " & $sMenuItemName & @CrLf)
Exit
EndFunc

Br, FireFox.

Link to comment
Share on other sites

I tryed your code and though your code worked it should be noted it could only show me the menu-item "amusing that item has a variable name to it".

The full details of my script * a little big for this topic works like this*.

When the mouse is detected over desktop, a UDF called "MouseOnEvent" is triggered. Blocking Right-down and Up. So when down is pressed, instead of showing a windows context menu it shows my context menu. This menu scans though my folder loations "Desktop, videos, downloads, music" and generates them into a context menu. When a "File" is clicked, this ends up in $ContextMenuItem (From orginal code at the top) which the code can use to find the file on the computer and then open it.

The reason for this post is to see if there is any way i can "Click" a menu item "again i could use MouseOnEvent to allow a trigger and close the Context menu while retaining which "Menu" was highlighted or clicked. So i could again search for that folder and open it explorer.

So in my case, there is no GUI shown as all i want displayed is the context menu itself.

Also, if i am correct in asuming for your code to work above it i would need a variable for each Menu item "as its the variable that links it to the event" which isn't pratical as my case there are thousands of context menus

Edited by IanN1990
Link to comment
Share on other sites

Also, if i am correct in asuming for your code to work above it i would need a variable for each Menu item "as its the variable that links it to the event" which isn't pratical as my case there are thousands of context menus

No, you can set as param the path of the file which is displayed on the menu item.

Edit : And you can set more than one param.

Second idea: store in a 2D array the id of the menu item associated to the menu name, you set an event on all your menu items and when it's fired you check for the control id hovered.

Br, FireFox.

Edited by FireFox
Link to comment
Share on other sites

#include <WindowsConstants.au3>

#include <GUIConstantsEx.au3>

#include <GuiMenu.au3>



$hGui = GUICreate("WM_MENUSELECT", 590, 270)

$FileMenu = GUICtrlCreateContextMenu()

GUICtrlCreateMenuItem('Open', $FileMenu)

GUICtrlSetState(-1, $GUI_CHECKED)

GUICtrlCreateMenuItem('Save', $FileMenu)

GUICtrlSetState(-1, $GUI_DISABLE)

$HelpMenu = GUICtrlCreateMenu('Help', $FileMenu)

GUICtrlCreateMenuItem('Web', $HelpMenu)

GUICtrlCreateMenuItem('Support', $HelpMenu)

GUICtrlCreateMenuItem('Delete', $HelpMenu)

GUICtrlCreateMenuItem('Exit', $HelpMenu)

GUISetState()



GUIRegisterMsg($WM_MENUSELECT, "WM_MENUSELECT")

Do

Until GUIGetMsg() = -3



Func WM_MENUSELECT($hWnd, $Msg, $wParam, $lParam)

    Local $ID, $Flags, $sText, $xy

    $ID = BitAND($wParam, 0xFFFF)

    $Flags = BitShift($wParam, 16)

    $sText = _GUICtrlMenu_GetItemText($lParam, $ID, False)

    $xy = MouseGetPos()

    ToolTip($sText, $xy[0] + 100, $xy[1] + 10)

EndFunc

Link to comment
Share on other sites

Though its now 4 am and i have to stop coding for the day to sleep i felt i should quickly respond.

@Azjio i tryed your code, and when i hover the mouse over the menu (Being Help) no tooltip is shown, while tooltips are shown for all the other menu-items. Sense my goal is to get the menu names it doesn't really work to well for me but sense now two respected members have both given menu examples not using _GUICtrlMenu_TrackPopupMenu i am thinking of re-writing my work.

Three Reasons:

_Track is a code freezer. Meaning once it reaches this line nothing else can run (Aside from hooks) so i cant enclude this into my main.exe, "in this instance the main.exe calls this .exe"

Because each time its called, it has be be re-generated it cant generate all the context menus at once "as it takes 3 seconds to load" so i have to split it up into sections

I think the answer for finding the menu name will require a normal context menu generation with the UDF metioned before, not with this trackpop

Full Context Menu code so far.

#Region Varaibles
   #NoTrayIcon
   #include 'MenuConstants.au3'
   #include 'RecFileListToArray.au3'
   local $GUIContextMenu = GUICreate("Custom Menu")
   local $MainContextMenu = GUICtrlCreateContextMenu()
   local $ContextHandle = GUICtrlGetHandle($MainContextMenu)
   local $ContextMenu
   local $ContextMenuText
   local $Winrar = " "
   local $MiddleClick=0
   local $MousePosition = MouseGetPos()
   local $Temp
   $MousePosition[0] += 1920
   $FilesSelected = StringSplit(ControlListView("Program Manager", "FolderView", "[CLASS:SysListView32; INSTANCE:1]", "GetSelected", 1), "|")
   ControlClick("Program Manager", "FolderView", "[Class:SysListView32]", "Left", 1, $MousePosition[0], $MousePosition[1])
   $FileAtMouse = ControlListView("[CLASS:Progman]", "FolderView", "SysListView321", "GetSelected")
   If $FileAtMouse <> "" Then $FileAtMouse = ControlListView("Program Manager", "FolderView", "[CLASS:SysListView32; INSTANCE:1]", "GetText",$FileAtMouse)
   #Endregion
;EndRegion Varaibles

#Region Generate Menus
   Select
      Case $FileAtMouse = ""
         $LvL1Computer = GUICtrlCreateMenu("Computer", $MainContextMenu)
         GUICtrlCreateMenuItem("Desktop", $LvL1Computer)
         GUICtrlCreateMenuItem("Videos", $LvL1Computer)
         GUICtrlCreateMenuItem("Favorites", $LvL1Computer)
         GUICtrlCreateMenuItem("Downloads", $LvL1Computer)
         GUICtrlCreateMenuItem("Music", $LvL1Computer)
         $LvL1New = GUICtrlCreateMenu("New", $MainContextMenu)
         GUICtrlCreateMenuItem(".Txt", $LvL1New)   
         GUICtrlCreateMenuItem(".Au3", $LvL1New)
         GUICtrlCreateMenuItem(".doc", $LvL1New)
         GUICtrlCreateMenuItem("Folder", $LvL1New)
         $SystemTools = GUICtrlCreateMenu("System Tools", $MainContextMenu)
         GUICtrlCreateMenuItem("Wallpapers", $SystemTools)
         GUICtrlCreateMenuItem("Screen Resoulation", $SystemTools)
         GUICtrlCreateMenuItem("Personalize", $SystemTools)
         GUICtrlCreateMenuItem("NVIDIA Control Panel", $SystemTools)
         GUICtrlCreateMenuItem("Control Panel", $SystemTools)
         GUICtrlCreateMenuItem("Task Manager", $MainContextMenu)
         $CopyFormant = DllCall("user32.dll", "int", "CountClipboardFormats")
         If $CopyFormant[0]=11 Then GUICtrlCreateMenuItem("Paste", $MainContextMenu)
      Case Else
         GUICtrlCreateMenuItem("Scan", $MainContextMenu)
         GUICtrlCreateMenuItem("Copy", $MainContextMenu)
         If StringRight($FileAtMouse, 4) = ".rar" Then GUICtrlCreateMenuItem("Extract Here", $MainContextMenu)
         If Not(StringRight($FileAtMouse, 4) = ".rar") Then GUICtrlCreateMenuItem("Add to Archive", $MainContextMenu)
         GUICtrlCreateMenuItem("Rename", $MainContextMenu)
         GUICtrlCreateMenuItem("Delete", $MainContextMenu)
         GUICtrlCreateMenuItem("Properties", $MainContextMenu)
   EndSelect
   #Endregion
;EndRegion Generate Menus

;$hM_Module = DllCall("kernel32.dll", "hwnd", "GetModuleHandle", "ptr", 0)
;DllCall("user32.dll", "hwnd", "SetWindowsHookEx", "int", 14, "ptr", DllCallbackGetPtr(DllCallbackRegister("MouseHook", "int", "int;ptr;ptr")), "hwnd", $hM_Module[0], "dword", 0)
;WinSetTrans($GUIContextMenu, "", 0)
;GUISetState(@SW_SHOW, $GUIContextMenu)
$ContextMenu = _GUICtrlMenu_TrackPopupMenu($ContextHandle, $GUIContextMenu, $MousePosition[0]-1930, $MousePosition[1]-10, 1, 1, 2)
$ContextMenuText = _GUICtrlMenu_GetItemText($ContextHandle, $ContextMenu, False)

#Region ContextMenu Click
   Select
      Case $ContextMenuText = "Scan"
         For $A = 1 To $FilesSelected[0]
            $FileText = ControlListView("Program Manager", "FolderView", "[CLASS:SysListView32; INSTANCE:1]", "GetText", $FilesSelected[$A])
            $Winrar = $Winrar & '"' & "D:Desktop" & $FileText & '" '
            If UBound($FilesSelected) = 2 Then $Winrar = (' "' & "D:Desktop" & $FileAtMouse & '" ')          
            Next  
         ;ShellExecute("C:Program FilesESETESET Smart Securityecls.exe /base-dir=" & $Winrar)
         ShellExecute("C:Program Files (x86)Malwarebytes' Anti-Malwarembam.exe", "Context Scan " & $Winrar)
      Case $ContextMenuText = ".txt"
         NewFile(4)
      Case $ContextMenuText = ".Au3"
         NewFile(11)
      Case $ContextMenuText = ".doc"
         NewFile(8)
      Case $ContextMenuText = "Folder"
         NewFile(14)
      Case $ContextMenuText = "Paste"
         RightClickMenu(9)
      Case $ContextMenuText = "Task Manager"
         Run("C:\Windows\System32\taskmgr.exe")
      Case $ContextMenuText = "NVIDIA Control Panel"
         Run("C:Program FilesNVIDIA CorporationControl Panel Clientnvcplui.exe")
      Case $ContextMenuText = "Screen Resoulation"
         Run("rundll32.exe shell32.dll,Control_RunDLL desk.cpl")
      Case $ContextMenuText = "Personalize"
         Run("rundll32.exe shell32.dll,Control_RunDLL desk.cpl,,2")  
      Case $ContextMenuText = "Add to Archive"
         For $A = 1 To $FilesSelected[0]
            $FileText = ControlListView("Program Manager", "FolderView", "[CLASS:SysListView32; INSTANCE:1]", "GetText", $FilesSelected[$A])
            $Winrar = $Winrar & '"' & "D:Desktop" & $FileText & '" '
            If UBound($FilesSelected) = 2 Then $Winrar = (' "' & "D:Desktop" & $FileAtMouse & '" ')          
         Next  
         Run('"C:Program FilesWinrarwinrar.exe" a -ep ' & '"' & "D:Desktop" & StringLeft($FileAtMouse, StringLen($FileAtMouse)-4) & '.rar"' & $Winrar)
      Case $ContextMenuText = "Extract Here"
         For $A = 1 To $FilesSelected[0]
            $FileText = ControlListView("Program Manager", "FolderView", "[CLASS:SysListView32; INSTANCE:1]", "GetText", $FilesSelected[$A])
            If UBound($FilesSelected) = 2 Then $FileText = $FileAtMouse
            Run('"C:Program FilesWinrarwinrar.exe" x "D:Desktop' & $FileText)
         Next
      Case $ContextMenuText = "Copy"
         For $A = 1 To $FilesSelected[0]
            If UBound($FilesSelected) = 2 Then ExitLoop
            ControlListView("Program Manager", "FolderView", "[CLASS:SysListView32; INSTANCE:1]", "Select", $FilesSelected[$A])
         Next
         ControlFocus("Program Manager", "FolderView", "[Class:SysListView32]")
         ControlSend("Program Manager", "FolderView", "[Class:SysListView32]", "^{C}")
      Case $ContextMenuText = "Delete"
         For $A = 1 To $FilesSelected[0]
            $FileText = ControlListView("Program Manager", "FolderView", "[CLASS:SysListView32; INSTANCE:1]", "GetText", $FilesSelected[$A])
            If UBound($FilesSelected) = 2 Then $FileText = $FileAtMouse
            FileRecycle("D:Desktop" & $FileText)
         Next
      Case $ContextMenuText = "Rename"
         ControlFocus("Program Manager", "FolderView", "[Class:SysListView32]")
         ControlSend("Program Manager", "FolderView", "[Class:SysListView32]", "{F2}")
      Case $ContextMenuText = "Properties"
         For $A = 1 To $FilesSelected[0]
            If UBound($FilesSelected) = 2 Then ExitLoop
            ControlListView("Program Manager", "FolderView", "[CLASS:SysListView32; INSTANCE:1]", "Select", $FilesSelected[$A])
         Next
         ControlFocus("Program Manager", "FolderView", "[Class:SysListView32]")
         ControlSend("Program Manager", "FolderView", "[Class:SysListView32]", "!{Enter}")
      Case $ContextMenuText = "Wallpapers"
         ShellExecute("D:Pictures001¦ Wallpapers & Display PicturesWallpapers")
      Case $ContextMenuText = "Control Panel"
         Run("C:\Windows\System32\control.exe")
      Case $ContextMenuText = "Videos"
         MutiContextMenu("D:Videos", $MainContextMenu)
      Case $ContextMenuText = "Desktop"
         MutiContextMenu("D:Desktop", $MainContextMenu)
      Case $ContextMenuText = "Favorites"
         MutiContextMenu("D:Favorites", $MainContextMenu)  
      Case $ContextMenuText = "Downloads"
         MutiContextMenu("D:Downloads", $MainContextMenu)    
      Case $ContextMenuText = "Music"
         MutiContextMenu("D:Music", $MainContextMenu)
      Case $ContextMenuText = ""
         WinActivate("[Class:Shell_TrayWnd]")
   EndSelect
   ControlListView("[CLASS:Progman]", "FolderView", "SysListView321", "SelectClear")
#Endregion
;EndRegion Generate Menus

#Region Functions
Func MutiContextMenu($Directory, $LvL0ContextMenu)
   GUIDelete($GUIContextMenu)
   GUICtrlDelete($MainContextMenu)
   GUICtrlDelete($ContextHandle)
   $GUIContextMenu = GUICreate("Custom Menu")
   $MainContextMenu = GUICtrlCreateContextMenu()
   $ContextHandle = GUICtrlGetHandle($MainContextMenu)
 
   $Directory = _RecFileListToArray($Directory, "*.*", 0, 1, 2, 2, "*.ini", "")
   For $A = 1 to $Directory[0]
      If StringInStr($Directory[$A], "", 0, 6) Then
         $FileName = StringInStr($Directory[$A], "", 0, 5)
            If StringInStr($Directory[$A], ".", 0, 1) Then
               $Level5 = GUICtrlCreateMenuItem(StringTrimLeft($Directory[$A], $FileName), $Level4)
            Else
               $Level5 = GUICtrlCreateMenu(StringTrimLeft($Directory[$A], $FileName), $Level4)
            EndIf
      Elseif StringInStr($Directory[$A], "", 0, 5) Then
         $FileName = StringInStr($Directory[$A], "", 0, 5)
            If StringInStr($Directory[$A], ".", 0, 1) Then
               $Level4 = GUICtrlCreateMenuItem(StringTrimLeft($Directory[$A], $FileName), $Level3)
            Else
               $Level4 = GUICtrlCreateMenu(StringTrimLeft($Directory[$A], $FileName), $Level3)
            EndIf
      Elseif StringInStr($Directory[$A], "", 0, 4) Then
         $FileName = StringInStr($Directory[$A], "", 0, 4)
            If StringInStr($Directory[$A], ".", 0, 1) Then
               $Level3 = GUICtrlCreateMenuItem(StringTrimLeft($Directory[$A], $FileName), $Level2)
            Else
               $Level3 = GUICtrlCreateMenu(StringTrimLeft($Directory[$A], $FileName), $Level2)
            EndIf
      ElseIf StringInStr($Directory[$A], "", 0, 3) Then
         $FileName = StringInStr($Directory[$A], "", 0, 3)
            If StringInStr($Directory[$A], ".", 0, 1) Then
               $Level2 = GUICtrlCreateMenuItem(StringTrimLeft($Directory[$A], $FileName), $Level1)
            Else
               $Level2 = GUICtrlCreateMenu(StringTrimLeft($Directory[$A], $FileName), $Level1)
            EndIf
      ElseIf StringInStr($Directory[$A], "", 0, 2) Then
         $FileName = StringInStr($Directory[$A], "", 0, 2)
            If StringInStr($Directory[$A], ".", 0, 1) Then
               $Level1 = GUICtrlCreateMenuItem(StringTrimLeft($Directory[$A], $FileName), $LvL0ContextMenu)
            Else
               $Level1 = GUICtrlCreateMenu(StringTrimLeft($Directory[$A], $FileName), $LvL0ContextMenu)
            EndIf
      EndIf
   Next

 ;  WinSetTrans($GUIContextMenu, "", 0)
  ; GUISetState(@SW_SHOW, $GUIContextMenu)
   $ContextMenu = _GUICtrlMenu_TrackPopupMenu($ContextHandle, $GUIContextMenu, MouseGetPos(0)-50, MouseGetPos(1)-10, 1, 1, 2)
   $ContextMenuText = _GUICtrlMenu_GetItemText($ContextHandle, $ContextMenu, False)

   If Not($ContextMenuText = "") Then
      $FileLocation = _FO_FileSearch("D:Videos", '*' & $ContextMenuText)    
      If $MiddleClick = 1 then $FileLocation[1] = StringLeft($FileLocation[1], (Stringlen($FileLocation[1]) - Stringlen($ContextMenuText))-1)
      ShellExecute($FileLocation[1])
   EndIf
EndFunc

Func RightClickMenu($Amount)
   ControlClick("Program Manager", "FolderView", "[Class:SysListView32]", "Right", 1, $MousePosition[0], $MousePosition[1])
   WinReady("[Class:#32768]")
   WinSetTrans("[Class:#32768]", "", 0)
   WinMove("[Class:#32768]", "", 1366, 768)
   ControlSend("[Class:#32768]", "", "", "{Up " & $Amount & "}")
   ControlSend("[Class:#32768]", "", "", "{Enter}")
EndFunc

Func NewFile($Amount)
   If WinGetText("Program Manager") = "" Then ControlShow('Program Manager', '', '[CLASS:SysListView32; INSTANCE:1]')
   ControlClick("Program Manager", "FolderView", "[Class:SysListView32]", "Right", 1, $MousePosition[0], $MousePosition[1])
   WinReady("[Class:#32768]")
   WinSetTrans("[Class:#32768]", "", 0)
   WinMove("[Class:#32768]", "", 1366, 768)
   ControlSend("[Class:#32768]", "", "", "{Up 3}")
   ControlSend("[Class:#32768]", "", "", "{Right}")
   WinSetTrans("[Class:#32768]", "", 0)
   WinMove("[Class:#32768]", "", 1366, 768)
   ControlSend("[Class:#32768]", "", "", "{Up " & $Amount & "}")
   ControlSend("[Class:#32768]", "", "", "{Enter}")
   WinReady(ControlListView("[CLASS:Progman]", "FolderView", "SysListView321", "GetSelected") > 0)
   ControlSend("Program Manager", "FolderView","[CLASS:Edit; INSTANCE:1]", "{Enter}")
EndFunc

Func MouseHook($nCode, $wParam, $lParam)
   ;My idea was to send lots of Enters into the context Menu, count the number of enters and then with the full-name, do a string split -number of times entered
   
   $MouseHook = DllStructGetData(DllStructCreate("struct;long X;long Y;endstruct;dword mouseData;dword flags;dword time;ulong_ptr dwExtraInfo", $lParam), 3)
   If $wParam = 0x00000208 then
      If $Temp = 0 Then
        
         ControlSend("[Class:#32768]", "", "", "{Up}")
         ControlSend("[Class:#32768]", "", "", "{Down}")
        
         for $i = 1 To 10
            If WinExists("Custom Menu") Then
            ControlSend("[Class:#32768]", "", "", "{Enter}")
             $Temp += 1
            ConsoleWrite($ContextMenuText)
            If Not($ContextMenuText = "") then ConsoleWrite("A")
            EndIf
         Next
   EndIf
 

      $MiddleClick += 1

   EndIf
EndFunc


Func WinReady($Class)
   While Not(WinExists($Class))
   Sleep(25)
   WEnd
EndFunc
#Endregion
;EndRegion Functions

#Region .Au3 Functions
Func _GUICtrlMenu_DestroyMenu($hMenu)
    Local $aResult = DllCall("User32.dll", "bool", "DestroyMenu", "handle", $hMenu)
    If @error Then Return SetError(@error, @extended, False)
    Return $aResult[0]
EndFunc   ;==>_GUICtrlMenu_DestroyMenu

Func _GUICtrlMenu_TrackPopupMenu($hMenu, $hWnd, $iX = -1, $iY = -1, $iAlignX = 1, $iAlignY = 1, $iNotify = 0, $iButtons = 0)
     If $iX = -1 Then $iX = _WinAPI_GetMousePosX()
     If $iY = -1 Then $iY = _WinAPI_GetMousePosY()
     Local $iFlags = 0
     Switch $iAlignX
         Case 1
             $iFlags = BitOR($iFlags, $TPM_LEFTALIGN)
         Case 2
             $iFlags = BitOR($iFlags, $TPM_RIGHTALIGN)
         Case Else
             $iFlags = BitOR($iFlags, $TPM_CENTERALIGN)
     EndSwitch
     Switch $iAlignY
         Case 1
             $iFlags = BitOR($iFlags, $TPM_TOPALIGN)
         Case 2
             $iFlags = BitOR($iFlags, $TPM_VCENTERALIGN)
         Case Else
             $iFlags = BitOR($iFlags, $TPM_BOTTOMALIGN)
     EndSwitch
     If BitAND($iNotify, 1) <> 0 Then $iFlags = BitOR($iFlags, $TPM_NONOTIFY)
     If BitAND($iNotify, 2) <> 0 Then $iFlags = BitOR($iFlags, $TPM_RETURNCMD)
     Switch $iButtons
         Case 1
             $iFlags = BitOR($iFlags, $TPM_RIGHTBUTTON)
         Case Else
             $iFlags = BitOR($iFlags, $TPM_LEFTBUTTON)
     EndSwitch
     Local $aResult = DllCall("User32.dll", "bool", "TrackPopupMenu", "handle", $hMenu, "uint", $iFlags, "int", $iX, "int", $iY, "int", 0, "hwnd", $hWnd, "ptr", 0)
     If @error Then Return SetError(@error, @extended, 0)
     Return $aResult[0]
EndFunc   ;==>_GUICtrlMenu_TrackPopupMenu

Func _GUICtrlMenu_GetItemText($hMenu, $iItem, $fByPos = True)
     Local $iByPos = 0
     If $fByPos Then $iByPos = $MF_BYPOSITION
     Local $aResult = DllCall("User32.dll", "int", "GetMenuStringW", "handle", $hMenu, "uint", $iItem, "wstr", 0, "int", 4096, "uint", $iByPos)
     If @error Then Return SetError(@error, @extended, 0)
     Return SetExtended($aResult[0], $aResult[3])
EndFunc   ;==>_GUICtrlMenu_GetItemText

Func _FO_FileSearch($sPath, $sMask = '*', $fInclude = True, $iDepth = 125, $iFull = 1, $iArray = 1, $iTypeMask = 1, $sLocale = 0)
     Local $vFileList
     If $sMask = '|' Then Return SetError(2, 0, '')
     If StringRight($sPath, 1) <> '' Then $sPath &= ''
     ; If Not StringRegExp($sPath, '(?i)^[a-z]:[^/:*?"<>|]*$') Or StringInStr($sPath, '') Then Return SetError(1, 0, '')
     If Not FileExists($sPath) Then Return SetError(1, 0, '')
     If $sMask = '*' Or $sMask = '' Then
         __FO_FileSearchAll($vFileList, $sPath, $iDepth)
         $vFileList = StringTrimRight($vFileList, 2)
     Else
         Switch $iTypeMask
             Case 0
                 If StringInStr($sMask, '*') Or StringInStr($sMask, '?') Or StringInStr($sMask, '.') Then
                     __FO_GetListMask($sPath, $sMask, $fInclude, $iDepth, $vFileList, $sLocale)
                 Else
                     __FO_FileSearchType($vFileList, $sPath, '|' & $sMask & '|', $fInclude, $iDepth)
                     $vFileList = StringTrimRight($vFileList, 2)
                 EndIf
             Case 1
                 __FO_GetListMask($sPath, $sMask, $fInclude, $iDepth, $vFileList, $sLocale)
             Case Else
                 If StringInStr($sMask, '*') Or StringInStr($sMask, '?') Or StringInStr($sMask, '.') Then Return SetError(2, 0, '')
                 __FO_FileSearchType($vFileList, $sPath, '|' & $sMask & '|', $fInclude, $iDepth)
                 $vFileList = StringTrimRight($vFileList, 2)
         EndSwitch
     EndIf
   If Not $vFileList Then Return SetError(3, 0, '')
     Switch $iFull
         Case 0
             $vFileList = StringRegExpReplace($vFileList, '(?m)^(?:.{' & StringLen($sPath) & '})(.*)$', '1')
         Case 2
             $vFileList = StringRegExpReplace($vFileList, '(?m)^(?:.*)(.*)$', '1')
         Case 3
             $vFileList = StringRegExpReplace($vFileList, '(?m)^(?:.*)([^]*?)(?:.[^.]+)?$', '1' & @CR)
             $vFileList = StringTrimRight($vFileList, 1)
     EndSwitch
     Switch $iArray
         Case 1
             $vFileList = StringSplit($vFileList, @CRLF, 1)
         Case 2
             $vFileList = StringSplit($vFileList, @CRLF, 3)
     EndSwitch
     Return $vFileList
EndFunc   ;==>_FO_FileSearch

Func __FO_GetListMask($sPath, $sMask, $fInclude, $iDepth, ByRef $sFileList, $sLocale)
     Local $aFileList, $i
     __FO_FileSearchMask($sFileList, $sPath, $iDepth)
     $sFileList = StringTrimRight($sFileList, 2)
     $sMask = StringReplace(StringReplace(StringRegExpReplace($sMask, '[][$^.{}()+]', '$0'), '?', '.'), '*', '.*?')
     If $sLocale Then
         $sMask = __FO_UserLocale($sMask, $sLocale)
     EndIf
     If $fInclude Then
         $aFileList = StringRegExp($sFileList, '(?mi)^(.+|(?:' & $sMask & '))(?:r|z)', 3)
         $sFileList = ''
         For $i = 0 To UBound($aFileList) - 1
             $sFileList &= $aFileList[$i] & @CRLF
         Next
     Else
         $sFileList = StringRegExpReplace($sFileList & @CRLF, '(?mi)^.+|(' & $sMask & ')rn', '')
     EndIf
     $sFileList = StringReplace(StringTrimRight($sFileList, 2), '|', '')
EndFunc   ;==>__FO_GetListMask

Func __FO_FileSearchMask(ByRef $sFileList, $sPath, $iDepth, $iCurD = 0)
   Local $sFile, $s = FileFindFirstFile($sPath & '*')
     If $s = -1 Then Return
     While 1
         $sFile = FileFindNextFile($s)
         If @error Then ExitLoop
         If @extended Then
             If $iCurD >= $iDepth Then ContinueLoop
             __FO_FileSearchMask($sFileList, $sPath & $sFile & '', $iDepth, $iCurD + 1)
         Else
             $sFileList &= $sPath & '|' & $sFile & @CRLF
         EndIf
     WEnd
     FileClose($s)
EndFunc   ;==>__FO_FileSearchMask
#EndRegion
;EndRegion .Au3 Functions
Edited by IanN1990
Link to comment
Share on other sites

New Code i have been working on this afternoon. The starting results are pleasing.

It can detect the Folder names, file names and it doesn't load everything at once so good for performance. Only when Video menu is hovered, it generates the videos I will keep working on this afternoon and edit this for updates or problems

#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
#include <GuiMenu.au3>
#include 'RecFileListToArray.au3'
#include 'MouseOnEvent.au3'
_MouseSetOnEvent($MOUSE_SECONDARYDOWN_EVENT, 'RightClick', '', 1)
$hGui = GUICreate("WM_MENUSELECT", 2, 2, 0, 0, $WS_POPUP, $WS_EX_TOOLWINDOW)
$FileMenu = GUICtrlCreateContextMenu()
$Test = GUICtrlCreateMenu('Videos', $FileMenu)

GUISetState()
GUIRegisterMsg($WM_MENUSELECT, "WM_MENUSELECT")

While 1
   sleep(250)
WEnd

Func RightClick ()
   WinSetOnTop($hGui, "", 1)
   winmove($hGui, "", Mousegetpos(0)-1, Mousegetpos(1)-1)
EndFunc


Func WM_MENUSELECT($hWnd, $Msg, $wParam, $lParam)
   $sText = _GUICtrlMenu_GetItemText($lParam, StringRight($wParam, 1), True)
   ConsoleWrite($sText  & @CRLF)
   If $sText = "Videos" then MutiContextMenu("D:Videos", $Test)
 EndFunc
 
 Func MutiContextMenu($Directory, $LvL0ContextMenu)
  $Directory = _RecFileListToArray($Directory, "*.*", 0, 1, 2, 2, "*.ini", "")
   For $A = 1 to $Directory[0]
      If StringInStr($Directory[$A], "", 0, 6) Then
         $FileName = StringInStr($Directory[$A], "", 0, 5)
            If StringInStr($Directory[$A], ".", 0, 1) Then
               $Level5 = GUICtrlCreateMenuItem(StringTrimLeft($Directory[$A], $FileName), $Level4)
            Else
               $Level5 = GUICtrlCreateMenu(StringTrimLeft($Directory[$A], $FileName), $Level4)
            EndIf
      Elseif StringInStr($Directory[$A], "", 0, 5) Then
         $FileName = StringInStr($Directory[$A], "", 0, 5)
            If StringInStr($Directory[$A], ".", 0, 1) Then
               $Level4 = GUICtrlCreateMenuItem(StringTrimLeft($Directory[$A], $FileName), $Level3)
            Else
               $Level4 = GUICtrlCreateMenu(StringTrimLeft($Directory[$A], $FileName), $Level3)
            EndIf
      Elseif StringInStr($Directory[$A], "", 0, 4) Then
         $FileName = StringInStr($Directory[$A], "", 0, 4)
            If StringInStr($Directory[$A], ".", 0, 1) Then
               $Level3 = GUICtrlCreateMenuItem(StringTrimLeft($Directory[$A], $FileName), $Level2)
            Else
               $Level3 = GUICtrlCreateMenu(StringTrimLeft($Directory[$A], $FileName), $Level2)
            EndIf
      ElseIf StringInStr($Directory[$A], "", 0, 3) Then
         $FileName = StringInStr($Directory[$A], "", 0, 3)
            If StringInStr($Directory[$A], ".", 0, 1) Then
               $Level2 = GUICtrlCreateMenuItem(StringTrimLeft($Directory[$A], $FileName), $Level1)
            Else
               $Level2 = GUICtrlCreateMenu(StringTrimLeft($Directory[$A], $FileName), $Level1)
            EndIf
      ElseIf StringInStr($Directory[$A], "", 0, 2) Then
         $FileName = StringInStr($Directory[$A], "", 0, 2)
            If StringInStr($Directory[$A], ".", 0, 1) Then
               $Level1 = GUICtrlCreateMenuItem(StringTrimLeft($Directory[$A], $FileName), $LvL0ContextMenu)
            Else
               $Level1 = GUICtrlCreateMenu(StringTrimLeft($Directory[$A], $FileName), $LvL0ContextMenu)
            EndIf
      EndIf
   Next

EndFunc
Link to comment
Share on other sites

One last question if anyone will be able to help.

With my orginal code, it took the name of the last thing clicked and then searched the computer for this file. Now with the code list above i am able to get folder and file names this idea doesn't work so well "as there are many folders with the same name". But as this style of coding offers more ways of doing things i was wondering if anyone knows of a way to get the full-names of every menu-item clicked.

I have tryed a few ideas but nothing i come up with seams to be any good.

Idea would be, if i clicked Desktop, New Folder 2 and then a file, New folder 2. It would say "File Clicked" = "DesktopNew Folder 2New Folder 4" but i see no pratical way of getting this result

#include 
#include 
#include 

$hGui = GUICreate("WM_MENUSELECT", 250, 250, 0, 0, $WS_POPUP, $WS_EX_TOOLWINDOW)
$FileMenu = GUICtrlCreateContextMenu()
$Test = GUICtrlCreateMenu('Desktop', $FileMenu)
$Test1 = GUICtrlCreateMenu('Computer', $FileMenu)
$Test2 = GUICtrlCreateMenu('New Folder 1', $Test)
$Test3 = GUICtrlCreateMenu('New Folder 2', $Test)
GUICtrlCreateMenuItem('New Folder 1', $Test3)
GUICtrlCreateMenuItem('New Folder 2', $Test3)
GUICtrlCreateMenuItem('New Folder 4', $Test3)
GUICtrlCreateMenuItem('New Folder 5', $Test3)

GUISetState()
GUIRegisterMsg($WM_MENUSELECT, "WM_MENUSELECT")

While 1
sleep(250)
WEnd

Func WM_MENUSELECT($hWnd, $Msg, $wParam, $lParam)
$ID = BitAND($wParam, 0xFFFF)
$FolderName = _GUICtrlMenu_GetItemText($lParam, $ID, True)
$FileName = _GUICtrlMenu_GetItemText($lParam, $ID, False)

If $Foldername <> "" then ConsoleWrite("FolderName: " & $FolderName & @CRLF)
If $FileName <> "" then ConsoleWrite("FileName: " & $FileName & @CRLF)
EndFunc
Link to comment
Share on other sites

_GUICtrlMenu_SetItemInfo -> $tagMENUITEMINFO -> ItemData (Application-defined value associated with the menu item)

_GUICtrlMenu_SetMenuInfo -> $tagMENUINFO -> MenuData (An application defined value)

When you create a menu set nesting level. Then buffer the recent data on the level.

To use the associative values, you need to create a menu using UDF

I haven't tried this thoughts aloud.

Link to comment
Share on other sites

After working on this for the last two days its coming to a close :) Though the code is a little mesy atm i will tidy it up with edits later :)

Instead of before, loading a whole array of files and loading it all at once. It detects when your moving down the tree-structure and loads the next files. For example if i was to click "Computer/Videos" it then loads the next context menus for the folders / files and so force. Adds a nice "Real-time scanning" effect while being fast.

Also it can detect full-name as it processes down the tree. Overall i am happy with the work even though i know its prob not the best coding.

@Azjio once day when i get better at GUis i will come back to this and try your idea and i do perfer better soulations.

On a Off-topic. This is why i enjoy coding so much. The idea of before, 400 Lines, took 4 seconds to load, was a static load, and not as good. Now 200 lines, 0.200 to load, dimatic, is very good with more features. Its just a nice feeling :)

#NoTrayIcon
#include <GuiMenu.au3>
local $ContextMenu = GUICreate('',0, 0, 0, 0, -2147483648, 128)
Local $tStruct=DllStructCreate("struct;long X;long Y;endstruct")
local $Array[10]
local $Array1[10]
local $FullFileName
local $ExcludeList="D:|D:0"
local $ShellCommand = " "
local $MousePosition = MouseGetPos()
local $Exclude
local $FileName
$MousePosition[0] += 1920
$hM_Module = DllCall("kernel32.dll", "hwnd", "GetModuleHandle", "ptr", 0)
DllCall("user32.dll", "hwnd", "SetWindowsHookEx", "int", 14, "ptr", DllCallbackGetPtr(DllCallbackRegister("MouseHook", "int", "int;ptr;ptr")), "hwnd", $hM_Module[0], "dword", 0)
GUIRegisterMsg(287, "MenuHook")
AdlibRegister("MenuCheck", 500)

$FilesSelected = StringSplit(ControlListView("Program Manager", "FolderView", "[CLASS:SysListView32; INSTANCE:1]", "GetSelected", 1), "|")
ControlClick("Program Manager", "FolderView", "[Class:SysListView32]", "Left", 1, $MousePosition[0], $MousePosition[1])
$FileAtMouse = ControlListView("[CLASS:Progman]", "FolderView", "SysListView321", "GetSelected")
If $FileAtMouse <> "" Then $FileAtMouse = ControlListView("Program Manager", "FolderView", "[CLASS:SysListView32; INSTANCE:1]", "GetText",$FileAtMouse)
   
#Region Generate Menus
   $MainContextMenu = GUICtrlCreateContextMenu()
   Select
      Case $FileAtMouse = ""
         $LvL1Computer = GUICtrlCreateMenu("Computer", $MainContextMenu)
         GUICtrlCreateMenu("Desktop", $LvL1Computer)
         GUICtrlCreateMenu("Videos", $LvL1Computer)
         GUICtrlCreateMenu("Favorites", $LvL1Computer)
         GUICtrlCreateMenu("Downloads", $LvL1Computer)
         GUICtrlCreateMenu("Music", $LvL1Computer)
         $LvL1New = GUICtrlCreateMenu("New", $MainContextMenu)
         GUICtrlCreateMenuItem(".Txt", $LvL1New)   
         GUICtrlCreateMenuItem(".Au3", $LvL1New)
         GUICtrlCreateMenuItem(".doc", $LvL1New)
         GUICtrlCreateMenuItem("Folder", $LvL1New)
         $SystemTools = GUICtrlCreateMenu("System Tools", $MainContextMenu)
         GUICtrlCreateMenuItem("Wallpapers", $SystemTools)
         GUICtrlCreateMenuItem("Screen Resoulation", $SystemTools)
         GUICtrlCreateMenuItem("Personalize", $SystemTools)
         GUICtrlCreateMenuItem("NVIDIA Control Panel", $SystemTools)
         GUICtrlCreateMenuItem("Control Panel", $SystemTools)
         GUICtrlCreateMenuItem("Task Manager", $MainContextMenu)
         $CopyFormant = DllCall("user32.dll", "int", "CountClipboardFormats")
      Case Else
         GUICtrlCreateMenuItem("Scan", $MainContextMenu)
         GUICtrlCreateMenuItem("Copy", $MainContextMenu)
         If $CopyFormant[0]=11 Then GUICtrlCreateMenuItem("Paste", $MainContextMenu)
         If StringRight($FileAtMouse, 4) = ".rar" Then GUICtrlCreateMenuItem("Extract Here", $MainContextMenu)
         If Not(StringRight($FileAtMouse, 4) = ".rar") Then GUICtrlCreateMenuItem("Add to Archive", $MainContextMenu)
         GUICtrlCreateMenuItem("Rename", $MainContextMenu)
         GUICtrlCreateMenuItem("Delete", $MainContextMenu)
         GUICtrlCreateMenuItem("Properties", $MainContextMenu)
   EndSelect
   ControlClick("", "", $ContextMenu, "Right", 1, 0, 0)
   #Endregion
;EndRegion Generate Menus

Do
Until GUIGetMsg() = -3

Func MenuCheck()
   $Pos = Mousegetpos()
   DllStructSetData($tStruct, 'x', $Pos[0])
   DllStructSetData($tStruct, 'y', $Pos[1])
   If WinGetTitle(DllCall("user32.dll", "hwnd", "WindowFromPoint", "struct", $tStruct)) > "" Then ProcessClose("Context Menu.exe")
EndFunc

Func MouseHook($nCode, $wParam, $lParam)
   If $wParam = 0x207 then ControlSend("[Class:#32768]", "", "", "{Enter}")
EndFunc

Func MenuHook($hWnd, $Msg, $wParam, $lParam)
   If $lParam = "0x00000000" Then
      If $FullFileName = "D:" Then
         Execute($FullFileName)
      Else
         Select
            Case $FileName = "Scan"
               For $A = 1 To $FilesSelected[0]
                  $FileText = ControlListView("Program Manager", "FolderView", "[CLASS:SysListView32; INSTANCE:1]", "GetText", $FilesSelected[$A])
                  $ShellCommand = $ShellCommand & '"' & "D:Desktop" & $FileText & '" '
                  If UBound($FilesSelected) = 2 Then $ShellCommand = (' "' & "D:Desktop" & $FileAtMouse & '" ')          
                  Next  
               ;ShellExecute("C:Program FilesESETESET Smart Securityecls.exe /base-dir=" & $ShellCommand)
               ShellExecute("C:Program Files (x86)Malwarebytes' Anti-Malwarembam.exe", "Context Scan " & $ShellCommand)
            Case $FileName = ".txt"
               NewFile(4)
            Case $FileName = ".Au3"
               NewFile(11)
            Case $FileName = ".doc"
               NewFile(8)
            Case $FileName = "Folder"
               NewFile(14)
            Case $FileName = "Paste"
               RightClickMenu(9)
            Case $FileName = "Task Manager"
               Run("C:\Windows\System32\taskmgr.exe")
            Case $FileName = "NVIDIA Control Panel"
               Run("C:Program FilesNVIDIA CorporationControl Panel Clientnvcplui.exe")
            Case $FileName = "Screen Resoulation"
               Run("rundll32.exe shell32.dll,Control_RunDLL desk.cpl")
            Case $FileName = "Personalize"
               Run("rundll32.exe shell32.dll,Control_RunDLL desk.cpl,,2")  
            Case $FileName = "Add to Archive"
               For $A = 1 To $FilesSelected[0]
                  $FileText = ControlListView("Program Manager", "FolderView", "[CLASS:SysListView32; INSTANCE:1]", "GetText", $FilesSelected[$A])
                  $ShellCommand = $ShellCommand & '"' & "D:Desktop" & $FileText & '" '
                  If UBound($FilesSelected) = 2 Then $ShellCommand = (' "' & "D:Desktop" & $FileAtMouse & '" ')          
               Next  
               Run('"C:Program FilesWinrarwinrar.exe" a -ep ' & '"' & "D:Desktop" & StringLeft($FileAtMouse, StringLen($FileAtMouse)-4) & '.rar"' & $ShellCommand)
            Case $FileName = "Extract Here"
               For $A = 1 To $FilesSelected[0]
                  $FileText = ControlListView("Program Manager", "FolderView", "[CLASS:SysListView32; INSTANCE:1]", "GetText", $FilesSelected[$A])
                  If UBound($FilesSelected) = 2 Then $FileText = $FileAtMouse
                  Run('"C:Program FilesWinrarwinrar.exe" x "D:Desktop' & $FileText)
               Next
            Case $FileName = "Copy"
               For $A = 1 To $FilesSelected[0]
                  If UBound($FilesSelected) = 2 Then ExitLoop
                  ControlListView("Program Manager", "FolderView", "[CLASS:SysListView32; INSTANCE:1]", "Select", $FilesSelected[$A])
               Next
               ControlFocus("Program Manager", "FolderView", "[Class:SysListView32]")
               ControlSend("Program Manager", "FolderView", "[Class:SysListView32]", "^{C}")
            Case $FileName = "Delete"
               For $A = 1 To $FilesSelected[0]
                  $FileText = ControlListView("Program Manager", "FolderView", "[CLASS:SysListView32; INSTANCE:1]", "GetText", $FilesSelected[$A])
                  If UBound($FilesSelected) = 2 Then $FileText = $FileAtMouse
                  FileRecycle("D:Desktop" & $FileText)
               Next
            Case $FileName = "Rename"
               ControlFocus("Program Manager", "FolderView", "[Class:SysListView32]")
               ControlSend("Program Manager", "FolderView", "[Class:SysListView32]", "{F2}")
            Case $FileName = "Properties"
               For $A = 1 To $FilesSelected[0]
                  If UBound($FilesSelected) = 2 Then ExitLoop
                  ControlListView("Program Manager", "FolderView", "[CLASS:SysListView32; INSTANCE:1]", "Select", $FilesSelected[$A])
               Next
               ControlFocus("Program Manager", "FolderView", "[Class:SysListView32]")
               ControlSend("Program Manager", "FolderView", "[Class:SysListView32]", "!{Enter}")
            Case $FileName = "Wallpapers"
               ShellExecute("D:Pictures001¦ Wallpapers & Display PicturesWallpapers")
            Case $FileName = "Control Panel"
            Run("C:\Windows\System32\control.exe")
         EndSelect
      EndIf
   ControlListView("[CLASS:Progman]", "FolderView", "SysListView321", "SelectClear")  
   Exit
   EndIf
      
   $wParam = BitAND($wParam, 0xFFFF)
   $MenuHandle = _GUICtrlMenu_GetItemID($lParam, $wParam)
   $Foldername = _GUICtrlMenu_GetItemText($lParam, $wParam, True)
   $FileName = _GUICtrlMenu_GetItemText($lParam, $wParam, False)

   If $Foldername <> "" Then $wParam = $Foldername & ""
   If $FileName <> "" Then $wParam = $FileName
 
   For $i=0 to 10
      If $Array[$i] = $lParam Then
         If Not($Array[$i+1] = "") then
            $Array[$i+1] = ""
            $Array1[$i+1] = ""
         EndIf
         $Array1[$i] = $wParam
         ExitLoop
      Elseif $Array[$i] = "" Then
         $Array[$i] = $lParam
         $Array1[$i] = $wParam
         ExitLoop
      EndIf
   Next   

   If $Array1[0] = "Computer" then $Array1[0] = "D:"
   If $Array1[0] = "D:" Then
      $FullFileName = ""
      For $i=0 to Ubound($Array1)-1
         If $Array1[$i] = "" then ExitLoop
         $FullFileName &= $Array1[$i]   
      Next
      
      $ExcludeList1 = StringSplit($ExcludeList, "|")
      For $i = 1 to Ubound($ExcludeList1) - 1
         If $ExcludeList1[$i] = $FullFileName then $Exclude = 1
      Next
   
      If $Exclude=0 then
         $Test = _FileListToArray($FullFileName)
         For $i = 1 to ubound($Test) - 1
            If StringInStr($Test[$i],".") <> 0 then
               GUICtrlCreateMenuItem($Test[$i], $MenuHandle)
            Else
               GUICtrlCreateMenu($Test[$i], $MenuHandle)
            EndIf
         Next   
      EndIf

$Exclude = 0
$ExcludeList &= $FullFileName & "|"
   EndIf
EndFunc

Func WinReady($Class)
   While Not(WinExists($Class))
   Sleep(25)
   WEnd
EndFunc

Func RightClickMenu($Amount)
   ControlClick("Program Manager", "FolderView", "[Class:SysListView32]", "Right", 1, $MousePosition[0], $MousePosition[1])
   WinReady("[Class:#32768]")
   WinSetTrans("[Class:#32768]", "", 0)
   WinMove("[Class:#32768]", "", 1366, 768)
   ControlSend("[Class:#32768]", "", "", "{Up " & $Amount & "}")
   ControlSend("[Class:#32768]", "", "", "{Enter}")
EndFunc

Func NewFile($Amount)
   If WinGetText("Program Manager") = "" Then ControlShow('Program Manager', '', '[CLASS:SysListView32; INSTANCE:1]')
   ControlClick("Program Manager", "FolderView", "[Class:SysListView32]", "Right", 1, $MousePosition[0], $MousePosition[1])
   WinReady("[Class:#32768]")
   WinSetTrans("[Class:#32768]", "", 0)
   WinMove("[Class:#32768]", "", 1366, 768)
   ControlSend("[Class:#32768]", "", "", "{Up 3}")
   ControlSend("[Class:#32768]", "", "", "{Right}")
   WinSetTrans("[Class:#32768]", "", 0)
   WinMove("[Class:#32768]", "", 1366, 768)
   ControlSend("[Class:#32768]", "", "", "{Up " & $Amount & "}")
   ControlSend("[Class:#32768]", "", "", "{Enter}")
   WinReady(ControlListView("[CLASS:Progman]", "FolderView", "SysListView321", "GetSelected") > 0)
   ControlSend("Program Manager", "FolderView","[CLASS:Edit; INSTANCE:1]", "{Enter}")
EndFunc

Func _FileListToArray($sPath, $sFilter = "*", $iFlag = 0)
    Local $hSearch, $sFile, $sFileList, $sDelim = "|"
    $sPath = StringRegExpReplace($sPath, "[/]+z", "") & ""
    If Not FileExists($sPath) Then Return SetError(1, 1, "")
    If StringRegExp($sFilter, "[/:><|]|(?s)As*z") Then Return SetError(2, 2, "")
    If Not ($iFlag = 0 Or $iFlag = 1 Or $iFlag = 2) Then Return SetError(3, 3, "")
    $hSearch = FileFindFirstFile($sPath & $sFilter)
    If @error Then Return SetError(4, 4, "")
    While 1
        $sFile = FileFindNextFile($hSearch)
        If @error Then ExitLoop
        If ($iFlag + @extended = 2) Then ContinueLoop
        $sFileList &= $sDelim & $sFile
    WEnd
    FileClose($hSearch)
    If Not $sFileList Then Return SetError(4, 4, "")
    Return StringSplit(StringTrimLeft($sFileList, 1), "|")
 EndFunc

**Edit As promised. An updated version. Much better qaulity but most workly will not work on others pcs. As its set up for my file-directory and tri-screen etc. but the coding is solid :)

Edited by IanN1990
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...