Sign in to follow this  
Followers 0
billthecreator

Figuring out how to make a history

10 posts in this topic

#1 ·  Posted (edited)

So i have my weather program in my signature.

And i want to make menu items of the 5 resent searches made.

how would i go about doing that? So far i have that the menu items will

be called from an ini file.

The only problem i have is that i dont know how to get the message of each menu like that. shown below

$HistoryMen = GUICtrlCreateMenu("&History")
$HistoryVar = IniReadSection(@AppDataDir & "\WeatherTray\WeatherGadget.ini", "History")
If Not @error Then
    For $i = 1 To $HistoryVar[0][0]
    $Hist[$i]   = GUICtrlCreateMenuItem($HistoryVar[$i][1], $HistoryMen)    ;this part i got
    Next
EndIf


;its this whole part that i dont get
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $Hist[1] To $Hist[5]
            _GetWeatherInfo(StringTrimRight(GUICtrlRead(-1),8),1)
EndSwitch
Wend
Edited by billthecreator

[font=Microsoft Sans Serif]My Scripts: From Most recent to least.[/font]Countdown GUI | QLOCK TWO | FlipClock | Slot Machine My UDF:_GenerateRandomNoRepeat | _GuiSnap

Share this post


Link to post
Share on other sites



Not the greatest way to pull it off, but it works.

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

GUICreate("My GUI menu", 300, 200)

Global $aHist
Global $hHistoryMen = GUICtrlCreateMenu("&History")
Global $aHistoryVar = IniReadSection(@ScriptDir & "\WeatherGadget.ini", "History")
;~ _ArrayDisplay($aHistoryVar)

If Not @error Then
    Dim $aHist[$aHistoryVar[0][0] + 1]
    For $i = 1 To $aHistoryVar[0][0]
        $aHist[$i] = GUICtrlCreateMenuItem($aHistoryVar[$i][1], $hHistoryMen) ;this part i got
    Next
EndIf

GUISetState()

;its this whole part that i dont get
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $aHist[1] To $aHist[UBound($aHist) - 1]
            For $i = 1 To UBound($aHist) - 1
                If $nMsg = $aHist[$i] Then
                    ConsoleWrite($i & @CR)
                    _GetWeatherInfo(StringTrimRight(GUICtrlRead($aHist[$i]), 8), 1)
                EndIf
            Next
    EndSwitch
WEnd

Func _GetWeatherInfo($Parm1, $Parm2)
    ;
EndFunc   ;==>_GetWeatherInfo

Share this post


Link to post
Share on other sites

sorry. i cant seem to get it to work...

Well...you started off good by posting example code, but now you don't even state what it is you can't get to work.

I posted a self contained "working" example. If you can't figure it out from there or at least state what exactly you can't get to work, I'm not sure anyone can help you.

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Hi, untested

$HistoryMen = GUICtrlCreateMenu("&History")
$HistoryVar = IniReadSection(@AppDataDir & "\WeatherTray\WeatherGadget.ini", "History")
If Not @error Then
    For $i = 1 To $HistoryVar[0][0]
    $Hist[$i]   = GUICtrlCreateMenuItem($HistoryVar[$i][1], $HistoryMen)  ;this part i got
    Next
EndIf


;its this whole part that i dont get
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $Hist[1] To $Hist[Ubound($Hist) -1]
            _GetWeatherInfo(StringTrimRight(GUICtrlRead($nMsg, 1),8),1)
    EndSwitch
Wend

Edit: corrected Case & GUICtrlRead

Edited by smashly

Share this post


Link to post
Share on other sites

Another way:

Opt("GuiOnEventMode", 1)

$HistoryMen = GUICtrlCreateMenu("&History")
$HistoryVar = IniReadSection(@AppDataDir & "\WeatherTray\WeatherGadget.ini", "History")

If Not @error Then
    For $i = 1 To $HistoryVar[0][0]
        $Hist[$i] = GUICtrlCreateMenuItem($HistoryVar[$i][1], $HistoryMen) ;this part i got
        GUICtrlSetOnEvent($Hist[$i], "_GetWeatherInfo")
    Next
EndIf

While 1
    Sleep(100)
WEnd

Func _GetWeatherInfo()
    ConsoleWrite("Menu Item ID: " & @GUI_CtrlId & @CRLF)
EndFunc

:)

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

Another way:

Opt("GuiOnEventMode", 1)

$HistoryMen = GUICtrlCreateMenu("&History")
$HistoryVar = IniReadSection(@AppDataDir & "\WeatherTray\WeatherGadget.ini", "History")

If Not @error Then
    For $i = 1 To $HistoryVar[0][0]
        $Hist[$i] = GUICtrlCreateMenuItem($HistoryVar[$i][1], $HistoryMen) ;this part i got
        GUICtrlSetOnEvent($Hist[$i], "_GetWeatherInfo")
    Next
EndIf

While 1
    Sleep(100)
WEnd

Func _GetWeatherInfo()
    ConsoleWrite("Menu Item ID: " & @GUI_CtrlId & @CRLF)
EndFuncoÝ÷ Ûú®¢×¡ë'¶ØZµØ¬i¹^¶ º(¶k ~éܶ*'j[(ûayû§rبZ(ÉbëaÆ®¶­sdgVæ2ôvWEvVFW$æfòb33c¶æfòÒb33c´VFEFÂb33c¶÷BÒ 7vF6b33c¶÷@ 66R bb33c¶æfòÒb33c´VFEF÷"b33c¶æfòÒgV÷C²gV÷C²FVà &WGW&âõ6WDW'&÷"ÂgV÷C²gV÷C²oÝ÷ Ú0Â¥te
ÚåIëNKÞÝ7èx¬·Mú«¨´g­Yæ­êÈú*ºe¢jëwvÚ.±ëayø«²ÚZ­©µêí¡·°«Z¦Þê®j[%G§¢¹­çîËb¢{jY^vX¤zØb±«­¢+Ù}Ñ]Ñ¡É%¹¼¡MÑÉ¥¹QÉ¥µI¥¡Ð¡U%
ÑɱI ÀÌØí1°È¤°à¤°Ä

ill try it...

Edited by billthecreator

[font=Microsoft Sans Serif]My Scripts: From Most recent to least.[/font]Countdown GUI | QLOCK TWO | FlipClock | Slot Machine My UDF:_GenerateRandomNoRepeat | _GuiSnap

Share this post


Link to post
Share on other sites

@billthecreator

also. if the function looks like this:

how would GUICtrlSetOnEvent($Hist[$i], "_GetWeatherInfo") look. cause i need to use the first parameter to be what a label equals

Opt("GuiOnEventMode", 1)

$HistoryMen = GUICtrlCreateMenu("&History")
$HistoryVar = IniReadSection(@AppDataDir & "\WeatherTray\WeatherGadget.ini", "History")

If Not @error Then
    For $i = 1 To $HistoryVar[0][0]
        $Hist[$i] = GUICtrlCreateMenuItem($HistoryVar[$i][1], $HistoryMen) ;this part i got
        GUICtrlSetOnEvent($Hist[$i], "_MenuItemEvent")
    Next
EndIf

While 1
    Sleep(100)
WEnd

Func _MenuItemEvent()
    ConsoleWrite("Menu Item ID: " & @GUI_CtrlId & @CRLF)
    _GetWeatherInfo()
EndFunc

Func _GetWeatherInfo($info = $EditTip, $opt = 0)
    Switch $opt
        Case 0
            If $info = $EditTip Or $info = "" Then
                Return _SetError(0, "")
            EndIf
    EndSwitch
EndFunc   ;==>_GetWeatherInfo

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

OK

Thank you every body.

It is now working.

everything is OnEvent.

Cheers to all

also, please check out my weather program and see what I've done all thanks to your help.

Edited by billthecreator

[font=Microsoft Sans Serif]My Scripts: From Most recent to least.[/font]Countdown GUI | QLOCK TWO | FlipClock | Slot Machine My UDF:_GenerateRandomNoRepeat | _GuiSnap

Share this post


Link to post
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
Sign in to follow this  
Followers 0