Jump to content

GUICtrlCreateMenuItem


Recommended Posts

hello I have a problem.

I made ​​this script, working with dynamic variables, I I can not figure out how to use$Itemnew

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <File.au3>
$Form1 = GUICreate("Form1", 615, 438, 192, 124)
$MenuItem1 = GUICtrlCreateMenu("File")
$MenuItem2 = GUICtrlCreateMenuItem("Add Keywords", $MenuItem1)
$MenuItem3 = GUICtrlCreateMenu("Recent files", $MenuItem1)
$MenuItem5 = GUICtrlCreateMenuItem("Clear List Recent", $MenuItem1)
$MenuItem6 = GUICtrlCreateMenuItem("Exit", $MenuItem1)
GUISetState(@SW_SHOW)


If FileExists(@ScriptDir&"\"&"recently.txt") Then
$total_lines = _FileCountLines(@ScriptDir&"\"&"recently.txt")
$read_file = FileOpen(@ScriptDir&"\"&"recently.txt", 0)
For $firstline = 1 To $total_lines
Global $Itemnew = GUICtrlCreateMenuItem(FileReadLine($read_file, $firstline), $MenuItem3)
Next
FileClose($read_file)
Else
$write = FileOpen(@ScriptDir&"\"&"recently.txt", 1)
FileClose($write)
EndIf


While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE, $MenuItem6
Exit
Case $MenuItem5
FileDelete(@ScriptDir&"\"&"recently.txt")
GUICtrlDelete($MenuItem3)
GUICtrlCreateMenu("Recent Files", $MenuItem1, 1)
Case $MenuItem2
$open_file = FileOpenDialog("Add Keywords List", @ScriptDir& "\", "Txt (*.txt)", 1)
If Not @error Then
$write2 = FileOpen(@ScriptDir&"\"&"recently.txt", 1)
FileWriteLine($write2,$open_file)
FileClose($write2)
GUICtrlCreateMenuItem($open_file, $MenuItem3)
EndIf
;Case $Itemnew
;MsgBox(0,"test",GUICtrlRead($Itemnew))

EndSwitch
WEnd
Link to comment
Share on other sites

  • Moderators

incepator,

I would do it like this: ;)

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <File.au3>

Global $aRecent, $aMenu_CID[1] = [0]

$sRecent = @ScriptDir & "\recently.txt"

$Form1 = GUICreate("Form1", 615, 438, 192, 124)
$Menu1 = GUICtrlCreateMenu("File")
$MenuItem2 = GUICtrlCreateMenuItem("Add Keywords", $Menu1)
$Menu2 = GUICtrlCreateMenu("Recent files", $Menu1)
$MenuItem5 = GUICtrlCreateMenuItem("Clear List Recent", $Menu1)
$MenuItem6 = GUICtrlCreateMenuItem("Exit", $Menu1)
GUISetState(@SW_SHOW)


If FileExists($sRecent) Then
    _FileReadToArray($sRecent, $aRecent)
    If IsArray($aRecent) Then
        For $i = 1 To $aRecent[0]
            $aMenu_CID[0] += 1
            ReDim $aMenu_CID[$aMenu_CID[0] + 1]
            $aMenu_CID[$aMenu_CID[0]] = GUICtrlCreateMenuItem($aRecent[$i], $Menu2)
        Next
    EndIf
Else
    $write = FileOpen($sRecent, 1)
    FileClose($write)
EndIf

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE, $MenuItem6
            Exit
        Case $MenuItem5
            $write = FileOpen($sRecent, 2)
            FileClose($write)
            GUICtrlDelete($Menu2)
            $Menu2 = GUICtrlCreateMenu("Recent Files", $Menu1, 1)
            Global $aMenu_CID[1] = [0]
        Case $MenuItem2
            $open_file = FileOpenDialog("Add Keywords List", @ScriptDir & "\", "Txt (*.*)", 1)
            If Not @error Then
                $write = FileOpen($sRecent, 1)
                FileWriteLine($write, @CRLF & $open_file)
                FileClose($write)
                $aMenu_CID[0] += 1
                ReDim $aMenu_CID[$aMenu_CID[0] + 1]
                $aMenu_CID[$aMenu_CID[0]] = GUICtrlCreateMenuItem($open_file, $Menu2)
            EndIf
        Case Else
            For $i = 1 To $aMenu_CID[0]
                If $nMsg = $aMenu_CID[$i] Then
                    $sText = GUICtrlRead($aMenu_CID[$i], 1)
                    ConsoleWrite($sText & @CRLF)
                    ExitLoop
                EndIf
            Next
    EndSwitch
WEnd

Any questions? :)

M23

Edited by Melba23
Typo

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • Moderators

incepator,

There was a typo in the code - you need to download the new version above. ;)

M23

Edited by Melba23
Need a new keyboard or new fingers!

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • Moderators

incepator,

I want to do something...

So what is stopping you? Or do you mean "I want you to do something"? ;)

M23

Edit: My version is all done - any sign of yours? :)

Edited by Melba23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • Moderators

incepator,

I did it this way: ;)

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <File.au3>
#include <Array.au3>

Global $aRecent, $aMenu_CID[1][2] = [[0]] ; 2D array to hold both CID and text <<<<<<<<<<<<<<<<<

$sRecent = @ScriptDir & "\recently.txt"

$Form1 = GUICreate("Form1", 615, 438, 192, 124)
$Menu1 = GUICtrlCreateMenu("File")
$MenuItem2 = GUICtrlCreateMenuItem("Add Keywords", $Menu1)
$Menu2 = GUICtrlCreateMenu("Recent files", $Menu1)
$MenuItem5 = GUICtrlCreateMenuItem("Clear List Recent", $Menu1)
$MenuItem6 = GUICtrlCreateMenuItem("Exit", $Menu1)
GUISetState(@SW_SHOW)

If FileExists($sRecent) Then
    _FileReadToArray($sRecent, $aRecent)
    If IsArray($aRecent) Then
        For $i = 1 To $aRecent[0]
            $aMenu_CID[0][0] += 1
            ReDim $aMenu_CID[$aMenu_CID[0][0] + 1][2]
            $aMenu_CID[$aMenu_CID[0][0]][0] = GUICtrlCreateMenuItem($aRecent[$i], $Menu2)
            $aMenu_CID[$aMenu_CID[0][0]][1] = $aRecent[$i]
        Next
    EndIf
Else
    $write = FileOpen($sRecent, 1)
    FileClose($write)
EndIf

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE, $MenuItem6
            Exit
        Case $MenuItem5
            $write = FileOpen($sRecent, 2)
            FileClose($write)
            GUICtrlDelete($Menu2)
            $Menu2 = GUICtrlCreateMenu("Recent Files", $Menu1, 1)
            Global $aMenu_CID[1][2] = [[0]]
        Case $MenuItem2
            $open_file = FileOpenDialog("Add Keywords List", @ScriptDir & "\", "Txt (*.*)", 1)
            If Not @error And _ArraySearch($aMenu_CID, $open_file, 1, 0, 0, 0, 1, 1) = -1 Then ; Search array to see if it exists already  <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
                $write = FileOpen($sRecent, 1)
                FileWriteLine($write, @CRLF & $open_file)
                FileClose($write)
                $aMenu_CID[0][0] += 1
                ReDim $aMenu_CID[$aMenu_CID[0][0] + 1][2]
                $aMenu_CID[$aMenu_CID[0][0]][0] = GUICtrlCreateMenuItem($open_file, $Menu2)
                $aMenu_CID[$aMenu_CID[0][0]][1] = $open_file
            EndIf
        Case Else
            For $i = 1 To $aMenu_CID[0][0]
                If $nMsg = $aMenu_CID[$i][0] Then
                    $sText = $aMenu_CID[$i][1]
                    ConsoleWrite($sText & @CRLF)
                    ExitLoop
                EndIf
            Next
    EndSwitch
WEnd

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • Moderators

incepator,

at the moment is too complicated for me to understand

Then ask questions as I suggested - otherwise you will never learn. ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

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...