incepator Posted November 9, 2012 Share Posted November 9, 2012 I have a problem, can someone help me to make it appear that we have selected from the list MenuItem ? this is problem probably: $all_items expandcollapse popup#include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <ProgressConstants.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <File.au3> #include <Array.au3> $Form1 = GUICreate("Form1", 146, 442, 323, 175) $Label1 = GUICtrlCreateLabel("test", 24, 40, 35, 24) GUICtrlSetColor(-1, 0x000080) GUICtrlSetCursor (-1, 0) GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT) $OptionsDummy = GUICtrlCreateDummy() $OptionsContext = GUICtrlCreateContextMenu($OptionsDummy) $all_dir2 = _FileListToArray(@ScriptDir&"\"&"All_Dir", "*", 2) If IsArray($all_dir2) Then For $ii = 1 To $all_dir2[0] $all_items = GUICtrlCreateMenuItem($all_dir2[$ii], $OptionsContext) Next EndIf GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Label1 ShowMenu($Form1, $nMsg, $OptionsContext) Case $all_items MsgBox(0,"",GUICtrlRead($all_items,1)) EndSwitch WEnd Func ShowMenu($hWnd, $CtrlID, $nContextID) Local $arPos, $x, $y Local $hMenu = GUICtrlGetHandle($nContextID) $arPos = ControlGetPos($hWnd, "", $CtrlID) $x = $arPos[0] $y = $arPos[1] + $arPos[3] ClientToScreen($hWnd, $x, $y) TrackPopupMenu($hWnd, $hMenu, $x, $y) EndFunc Func ClientToScreen($hWnd, ByRef $x, ByRef $y) Local $stPoint = DllStructCreate("int;int") DllStructSetData($stPoint, 1, $x) DllStructSetData($stPoint, 2, $y) DllCall("user32.dll", "int", "ClientToScreen", "hwnd", $hWnd, "ptr", DllStructGetPtr($stPoint)) $x = DllStructGetData($stPoint, 1) $y = DllStructGetData($stPoint, 2) $stPoint = 0 EndFunc Func TrackPopupMenu($hWnd, $hMenu, $x, $y) DllCall("user32.dll", "int", "TrackPopupMenuEx", "hwnd", $hMenu, "int", 0, "int", $x, "int", $y, "hwnd", $hWnd, "ptr", 0) EndFunc Link to comment Share on other sites More sharing options...
stormbreaker Posted November 9, 2012 Share Posted November 9, 2012 (edited) This does it: expandcollapse popup#include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <ProgressConstants.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <File.au3> #include <Array.au3> Global $all_items Global $x = 0 $Form1 = GUICreate("Form1", 146, 442, 323, 175) $Label1 = GUICtrlCreateLabel("test", 24, 40, 35, 24) GUICtrlSetColor(-1, 0x000080) GUICtrlSetCursor (-1, 0) GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT) $OptionsDummy = GUICtrlCreateDummy() $OptionsContext = GUICtrlCreateContextMenu($OptionsDummy) $all_dir2 = _FileListToArray(@ScriptDir & "\", "*", 2) If IsArray($all_dir2) Then Global $all_items[Int($all_dir2[0])+1] For $ii = 1 To $all_dir2[0] $all_items[$ii] = GUICtrlCreateMenuItem($all_dir2[$ii], $OptionsContext) Next EndIf GUISetState(@SW_SHOW) While 1 Local $x=0 $nMsg = GUIGetMsg() For $x = 1 to $all_dir2[0] If $nMsg = $all_items[$x] then MsgBox(0,"",GuiCtrlRead($all_items[$x], 1)) EndIf Next Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Label1 ShowMenu($Form1, $nMsg, $OptionsContext) EndSwitch WEnd Func ShowMenu($hWnd, $CtrlID, $nContextID) Local $arPos, $x, $y Local $hMenu = GUICtrlGetHandle($nContextID) $arPos = ControlGetPos($hWnd, "", $CtrlID) $x = $arPos[0] $y = $arPos[1] + $arPos[3] ClientToScreen($hWnd, $x, $y) TrackPopupMenu($hWnd, $hMenu, $x, $y) EndFunc Func ClientToScreen($hWnd, ByRef $x, ByRef $y) Local $stPoint = DllStructCreate("int;int") DllStructSetData($stPoint, 1, $x) DllStructSetData($stPoint, 2, $y) DllCall("user32.dll", "int", "ClientToScreen", "hwnd", $hWnd, "ptr", DllStructGetPtr($stPoint)) $x = DllStructGetData($stPoint, 1) $y = DllStructGetData($stPoint, 2) $stPoint = 0 EndFunc Func TrackPopupMenu($hWnd, $hMenu, $x, $y) DllCall("user32.dll", "int", "TrackPopupMenuEx", "hwnd", $hMenu, "int", 0, "int", $x, "int", $y, "hwnd", $hWnd, "ptr", 0) EndFunc EDIT: Corrected the code, for this last time. Edited November 9, 2012 by MKISH ---------------------------------------- :bye: Hey there, was I helpful? ---------------------------------------- My Current OS: Win8 PRO (64-bit); Current AutoIt Version: v3.3.8.1 Link to comment Share on other sites More sharing options...
incepator Posted November 9, 2012 Author Share Posted November 9, 2012 (edited) Thank you very much! UPDATEI made a small update.I changed the "label" - "test" with a "folder list", and from that list I want to display each subfolder.problem is now not working properly ...always get stuck somewhere off X_XThanks for your time!expandcollapse popup#include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <ProgressConstants.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <File.au3> #include <Array.au3> Global $all_items Global $x = 0$Form1 = GUICreate("Form1", 146, 442, 323, 175) $all_dir = _FileListToArray(@ScriptDir & "", "*", 2) For $i = 1 To $all_dir[0] $Label1 = GUICtrlCreateLabel($all_dir[$i], 24, 40*$i+5, 90, 24) Next$OptionsDummy = GUICtrlCreateDummy() $OptionsContext = GUICtrlCreateContextMenu($OptionsDummy) $all_dir2 = _FileListToArray(@ScriptDir & "" & GUICtrlRead($Label1), "*", 2) If IsArray($all_dir2) Then Global $all_items[Int($all_dir2[0])+1] For $ii = 1 To $all_dir2[0] $all_items[$ii] = GUICtrlCreateMenuItem($all_dir2[$ii], $OptionsContext) Next EndIf GUISetState(@SW_SHOW)While 1 Local $x=0 $nMsg = GUIGetMsg() For $x = 1 to $all_dir2[0] If $nMsg = $all_items[$x] then MsgBox(0,"",GuiCtrlRead($all_items[$x], 1)) EndIf Next Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Label1 ShowMenu($Form1, $nMsg, $OptionsContext) EndSwitch WEnd Func ShowMenu($hWnd, $CtrlID, $nContextID) Local $arPos, $x, $y Local $hMenu = GUICtrlGetHandle($nContextID) $arPos = ControlGetPos($hWnd, "", $CtrlID) $x = $arPos[0] $y = $arPos[1] + $arPos[3] ClientToScreen($hWnd, $x, $y) TrackPopupMenu($hWnd, $hMenu, $x, $y) EndFunc Func ClientToScreen($hWnd, ByRef $x, ByRef $y) Local $stPoint = DllStructCreate("int;int") DllStructSetData($stPoint, 1, $x) DllStructSetData($stPoint, 2, $y) DllCall("user32.dll", "int", "ClientToScreen", "hwnd", $hWnd, "ptr", DllStructGetPtr($stPoint)) $x = DllStructGetData($stPoint, 1) $y = DllStructGetData($stPoint, 2) $stPoint = 0 EndFunc Func TrackPopupMenu($hWnd, $hMenu, $x, $y) DllCall("user32.dll", "int", "TrackPopupMenuEx", "hwnd", $hMenu, "int", 0, "int", $x, "int", $y, "hwnd", $hWnd, "ptr", 0) EndFunc Edited November 10, 2012 by incepator Link to comment Share on other sites More sharing options...
incepator Posted November 11, 2012 Author Share Posted November 11, 2012 If you can help me I would be grateful, I need this script .. Thank you! Link to comment Share on other sites More sharing options...
stormbreaker Posted November 12, 2012 Share Posted November 12, 2012 (edited) I definitely suggest you to learn AutoIt (at least the very basics) and then ask for help.Thank you very much! UPDATEI made a small update.The reason: Your update tells how much you know AutoIt. Don't take this as a rude comment (just a friendly advice), but seriously you should consider learning this, asking us for help without even knowing the While...WEnd and other basics of this language, is clearly asking us to write scripts for you. So far, you just modified GUICtrlCreateContextMenu Example-2 from help file.Regards,MKISH Edited November 12, 2012 by MKISH ---------------------------------------- :bye: Hey there, was I helpful? ---------------------------------------- My Current OS: Win8 PRO (64-bit); Current AutoIt Version: v3.3.8.1 Link to comment Share on other sites More sharing options...
incepator Posted November 12, 2012 Author Share Posted November 12, 2012 (edited) I managed to make functional script, but I wanted a better version and more correctly written, if possible... expandcollapse popup#include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <ProgressConstants.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <File.au3> #include <Array.au3> Global $all_items Global $x = 0 Global $all_dir2 $Form1 = GUICreate("Form1", 623, 442, 192, 124) $Label5 = GUICtrlCreateLabel("Folder 2", 24, 120, 35, 24) GUICtrlSetColor(-1, 0x000080) GUICtrlSetCursor (-1, 0) GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT) $OptionsDummy2 = GUICtrlCreateDummy() $OptionsContext42 = GUICtrlCreateContextMenu($OptionsDummy2) $Label4 = GUICtrlCreateLabel("Foder 1", 24, 160, 35, 24) GUICtrlSetColor(-1, 0x000080) GUICtrlSetCursor (-1, 0) GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT) $OptionsDummy = GUICtrlCreateDummy() $OptionsContext4 = GUICtrlCreateContextMenu($OptionsDummy) $all_dir2 = _FileListToArray(@ScriptDir & "Foder 1", "*", 2) $all_dir3 = _FileListToArray(@ScriptDir & "Folder 2", "*", 2) If IsArray($all_dir2) Then If IsArray($all_dir3) Then Global $all_items[Int($all_dir2[0])+1] Global $all_items2[Int($all_dir3[0])+1] For $ii = 1 To $all_dir2[0] $all_items[$ii] = GUICtrlCreateMenuItem($all_dir2[$ii], $OptionsContext4) Next For $iii = 1 To $all_dir3[0] $all_items2[$iii] = GUICtrlCreateMenuItem($all_dir3[$iii], $OptionsContext42) Next EndIf EndIf GUISetState(@SW_SHOW) While 1 Local $x=0 $nMsg = GUIGetMsg() For $x = 1 to $all_dir2[0] If $nMsg = $all_items[$x] then MsgBox(0,"",GuiCtrlRead($all_items[$x], 1)) EndIf Next For $x = 1 To $all_dir3[0] If $nMsg = $all_items2[$x] Then MsgBox(0,"",GUICtrlRead($all_items2[$x],1)) EndIf Next Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Label4 ShowMenu($Form1, $nMsg, $OptionsContext42) Case $Label5 ShowMenu($Form1, $nMsg, $OptionsContext4) EndSwitch WEnd Func ShowMenu($hWnd, $CtrlID, $nContextID) Local $arPos, $x, $y Local $hMenu = GUICtrlGetHandle($nContextID) $arPos = ControlGetPos($hWnd, "", $CtrlID) $x = $arPos[0] $y = $arPos[1] + $arPos[3] ClientToScreen($hWnd, $x, $y) TrackPopupMenu($hWnd, $hMenu, $x, $y) EndFunc Func ClientToScreen($hWnd, ByRef $x, ByRef $y) Local $stPoint = DllStructCreate("int;int") DllStructSetData($stPoint, 1, $x) DllStructSetData($stPoint, 2, $y) DllCall("user32.dll", "int", "ClientToScreen", "hwnd", $hWnd, "ptr", DllStructGetPtr($stPoint)) $x = DllStructGetData($stPoint, 1) $y = DllStructGetData($stPoint, 2) $stPoint = 0 EndFunc Func TrackPopupMenu($hWnd, $hMenu, $x, $y) DllCall("user32.dll", "int", "TrackPopupMenuEx", "hwnd", $hMenu, "int", 0, "int", $x, "int", $y, "hwnd", $hWnd, "ptr", 0) EndFunc Thank you! Edited November 12, 2012 by incepator Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now