Sign in to follow this  
Followers 0
sammy1983

Help with GUICtrlCreateCombo

9 posts in this topic

Hope anyone can help me with this. I am trying to create a GUICtrlCreateCombobox in which I am trying to pull the items list from another html page having content in a form of drop down (combobox). I am stuck here and no clue how to achieve this. Could you please help me? Thanks.

Share this post


Link to post
Share on other sites



 

You should show whatever code you tried.
And if you would like to show a little courtesy, you might consider replying to people who are trying to help you with >questions you have already posted.

 

 

Hey John,

First, please accept my apologies as I am just learning the navigation in Forum and I did not get any notification on the Message icon for the last post. As I myself searched Help and online scripts, I didn't check the reply. Honestly, I never thought people will respond to my queries. Going forward I'll keep an eye on my posts and reply them with courtesy. Please accept my apologies. Thanks John.

Share this post


Link to post
Share on other sites

@ Sammy1983

You try read from here and see if you can come right

http://www.autoitscript.com/autoit3/docs/functions.htm

Regards,

CHOVIE

 

Thanks CHOVIE but I think I should be more clear with my query. I have a HTML page where I have a dropdown menu with few items. Now I am trying to write code with autoit which can retrieve those items from that dropdown menu and show me as Autoit GUI.

I tried the below code available in help section:

Example()
 
Func Example()
    Local $msg
    GUICreate("My GUI combo") ; will create a dialog box that when displayed is centered
 
    GUICtrlCreateCombo("item1", 10, 10) ; create first item
    GUICtrlSetData(-1, "item2|item3", "item3") ; add other item snd set a new default
 
    GUISetState()
 
    ; Run the GUI until the dialog is closed
    While 1
        $msg = GUIGetMsg()
 
        If $msg = $GUI_EVENT_CLOSE Then ExitLoop
    WEnd
 
Though the output is what I wished, instead of specifying "item2|item3" in the code, it should retrieve the items from that 3rd party HTML page's dropdown menu.
 
$oForm1 = _IEFormGetObjByName ($oIE1, "Create")
$oQuery6 = _IEFormElementGetObjByName ($oForm1, "bug_severity")
_IEFormElementOptionSelect ($oQuery6, "normal", 1, "byText")
 
In the above code, it selects the item with the text "Normal" but I want a prompt from Autoit with all the items available and let me select the item manually.
 
I tried to explain my problem as much as I can but please let me know if you need more information. Somehow, I am stuck at this point to finish my project. Any help will be greatly appreciated. Thanks.

post-80752-0-26386900-1374931494_thumb.j

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Hi sammy1983,
 
I recently also pulled some HTML pages, parsed out data, and put it in a menu (mine was a ListBox).  I'm putting the code here as a sample for you.  I don't have enough time right now to tailor an example for you, but you should be able to figure it out from mine.  Word of warning - I used StringRegExp a lot, which can be really confusing to learn.  Don't worry too much about it, unless you find you want to use that function too.

#include <IE.au3>
#include <GUIConstantsEx.au3>
#include <ListBoxConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
Global $AnimeList[1][2], $ShowList[1][2], $hListAnime, $hListEpisodes
Global Const $Title = "Anime List v1.0", $Settings = @ScriptDir & "\Anime.ini", $domain = "http://www.animefo.com"
Global Enum $_URL, $_TITLE

Initialize()
Main()

Func Initialize()
    Local $ini, $i
    $AnimeList[0][0] = 0

    If FileExists($Settings) Then
        $ini = FileRead($Settings)
        If $ini <> "" Then
            $ini = StringSplit(StringStripCR($ini), @LF)
            If $ini[0] > 1 And $ini[1] = $Title Then
                ReDim $AnimeList[$ini[0] / 2][2]
                $AnimeList[0][0] = $ini[0] / 2 - 1
                For $i = 2 To $ini[0] - 1 Step 2
                    $AnimeList[$i / 2][$_URL] = $ini[$i]
                    $AnimeList[$i / 2][$_TITLE] = $ini[$i + 1]
                Next
            EndIf
        EndIf
    EndIf
    If $AnimeList[0][0] = 0 Then GetAnimeList()
EndFunc

Func Main()
    GUICreate($Title, 300, 400)
    GUICtrlCreateLabel("Anime", 10, 10, 280, Default, $SS_CENTER)
    GUICtrlSetFont(-1, 12)
    $hListAnime = GUICtrlCreateList("", 10, 31, 280, 100)
    For $i = 1 To $AnimeList[0][0]
        GUICtrlSetData($hListAnime, $AnimeList[$i][$_TITLE])
    Next
    $hButton = GUICtrlCreateButton("Play!", 105, 340, 90)
    ChangeAnime()
    GUISetState()

    Local $Anime
    While 1
        Switch GUIGetMsg()
            Case $hButton
                If GUICtrlSendMsg($hListEpisodes, $LB_GETCURSEL, 0, 0) <> -1 Then PlayShow()
            Case $hListAnime
                If GUICtrlRead($hListAnime) <> $Anime Then
                    $Anime = GUICtrlRead($hListAnime)
                    GUICtrlDelete($hListEpisodes)
                    ChangeAnime()
                EndIf
            Case $GUI_EVENT_CLOSE
                Exit
        EndSwitch
    WEnd
EndFunc

Func PlayShow()
    Local Const $htmlPath = @ScriptDir & "\Anime.html"
    Local $url, $page, $versions, $pos1, $pos2, $versions, $i

    ; Get Versions
    $url = $ShowList[GUICtrlSendMsg($hListEpisodes, $LB_GETCURSEL, 0, 0) + 1][$_URL]
    $page = BinaryToString(InetRead($domain & $url))
    $pos1 = StringInStr($page, 'class="version cf"')
    $pos2 = StringInStr($page, '</ul>', 0, 1, $pos1)
    $versions = StringRegExp(StringMid($page, $pos1, $pos2 - $pos1), '(?i).+?href="(.+?)">(.+?)</a>', 3)

    ; Get URLs
    For $i = 0 To UBound($versions) - 1 Step 2
        $page = BinaryToString(InetRead($domain & $versions[$i]))
        $url = StringRegExp(StringStripWS($page, 4), '(?i)id="playbox".+?src="(.+?)"', 1)
        $versions[$i] = $url[0]
    Next

    ; Build HTML File
    Local $html = FileOpen($htmlPath, 2)
    If $html = -1 Then
        MsgBox(16, $Title, "Cannot built HTML output file: " & @LF & $htmlPath)
        Return
    EndIf
    FileWriteLine($html, '<html><head>')
    FileWriteLine($html, '<title>' & GUICtrlRead($hListEpisodes) & '</title>')
    FileWriteLine($html, '<style>')
    FileWriteLine($html, 'body {background-color: #000;}')
    FileWriteLine($html, 'ul {list-style-type: none;}')
    FileWriteLine($html, 'li {display: inline; border: 1px solid #fff; margin: 5px; padding: 3px;}')
    FileWriteLine($html, 'li:hover {background-color: #77f;}')
    FileWriteLine($html, '</style>')
    FileWriteLine($html, '</head>')
    FileWriteLine($html, '<body>')
    FileWriteLine($html, '<ul>')
    For $i = 0 To UBound($versions) - 1 Step 2
        FileWriteLine($html, '<li><a target="Video" href="' & $versions[$i] & '">' & $versions[$i + 1] & '</a></li>')
    Next
    FileWriteLine($html, '</ul>')
    FileWriteLine($html, '<hr />')
    FileWriteLine($html, '<iframe name="Video" src="' & $versions[0] & '" width=95% height=95% seamless=seamless></iframe>')
    FileWriteLine($html, '</body>')
    FileClose($html)
    ShellExecute($htmlPath)
EndFunc

Func ChangeAnime()
    Local $i, $url, $key, $page, $links, $index = 0
    ReDim $ShowList[1][2]

    $url = $AnimeList[GUICtrlSendMsg($hListAnime, $LB_GETCURSEL, 0, 0) + 2][$_URL]
    $key = "/watchcartoon-"
    $page = BinaryToString(InetRead($domain & $url))
    $links = StringRegExp($page, '(?i)<a .*?href="(.+?)">(.+?)</a>', 3)

    For $i = 0 To UBound($links) - 1 Step 2
        If StringLeft($links[$i], StringLen($key)) = $key Then
            $index += 1
            ReDim $ShowList[$index + 1][2]
            $ShowList[0][0] = $index
            $ShowList[$index][0] = $links[$i]
            $ShowList[$index][1] = $links[$i + 1]
        EndIf
    Next

    $hListEpisodes = GUICtrlCreateList("", 10, 140, 280, 200, BitOR($WS_BORDER, $WS_VSCROLL))
    For $i = 1 To $ShowList[0][0]
        GUICtrlSetData($hListEpisodes, $ShowList[$i][1])
    Next
EndFunc

Func GetAnimeList()
    Local $regexp, $url, $page, $links, $CurrentPage, $NextPage, $LastPage, $i, $ini
    Local $hwnd = GUICreate($Title, 300, 70, Default, Default, $WS_CAPTION)
    Local $hLabel = GUICtrlCreateLabel("Retrieving index page...", 10, 10, 280)
    Local $hProgress = GUICtrlCreateProgress(10, 30, 280, 30)
    GUISetState()

    $regexp = '(?i)<a .*href="(.+)"><img src=".+" alt="(.+)" /></a>'
    $url = "/cartoon-category-browser"
    $page = BinaryToString(InetRead($domain & $url))
    $LastPage = StringRegExp($page, '(?i)<a .*href=".+".*>(.+)</a>[.\r\n]*<a .*href=".+".*>Next</a>*', 3)
    $LastPage = $LastPage[0]

    For $CurrentPage = 1 To $LastPage
        GUICtrlSetData($hLabel, "Parsing page " & $CurrentPage & " of " & $LastPage & "...")
        GUICtrlSetData($hProgress, $CurrentPage * 100 / $LastPage)
        $links = StringRegExp($page, $regexp, 3)
        For $i = 0 To UBound($links) - 1 Step 2
            $AnimeList[0][0] += 1
            ReDim $AnimeList[$AnimeList[0][0] + 1][2]
            $AnimeList[$AnimeList[0][0]][$_URL] = $links[$i]
            $AnimeList[$AnimeList[0][0]][$_TITLE] = $links[$i + 1]
        Next
        If $CurrentPage <> $LastPage Then
            $NextPage = StringRegExp($page, '(?i)<a .*href="(.+)".*>Next</a>*', 3)
            $NextPage = $NextPage[0]
            $page = BinaryToString(InetRead($domain & $NextPage))
        EndIf
    Next
    GUIDelete($hwnd)

    $ini = FileOpen($Settings, 2)
    If $ini = -1 Then
        MsgBox(16, $Title, "Error accessings settings file:" & @LF & $Settings & @LF & "Cannot save settings")
    Else
        FileWrite($ini, $Title & @CRLF)
        For $i = 1 To $AnimeList[0][0]
            FileWrite($ini, $AnimeList[$i][$_URL] & @CRLF)
            FileWrite($ini, $AnimeList[$i][$_TITLE] & @CRLF)
        Next
        FileClose($ini)
    EndIf
EndFunc

 
 
 

Hey John,
 
First, please accept my apologies as I am just learning the navigation in Forum and I did not get any notification on the Message icon for the last post. As I myself searched Help and online scripts, I didn't check the reply. Honestly, I never thought people will respond to my queries. Going forward I'll keep an eye on my posts and reply them with courtesy. Please accept my apologies. Thanks John.


Check out the "Follow this Topic" option at the top-right.  You'll find it quite useful.  :)

Edited by Artisan

Share this post


Link to post
Share on other sites

Hi sammy1983,

 

I recently also pulled some HTML pages, parsed out data, and put it in a menu (mine was a ListBox).  I'm putting the code here as a sample for you.  I don't have enough time right now to tailor an example for you, but you should be able to figure it out from mine.  Word of warning - I used StringRegExp a lot, which can be really confusing to learn.  Don't worry too much about it, unless you find you want to use that function too.

#include <IE.au3>
#include <GUIConstantsEx.au3>
#include <ListBoxConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
Global $AnimeList[1][2], $ShowList[1][2], $hListAnime, $hListEpisodes
Global Const $Title = "Anime List v1.0", $Settings = @ScriptDir & "\Anime.ini", $domain = "http://www.animefo.com"
Global Enum $_URL, $_TITLE

Initialize()
Main()

Func Initialize()
    Local $ini, $i
    $AnimeList[0][0] = 0

    If FileExists($Settings) Then
        $ini = FileRead($Settings)
        If $ini <> "" Then
            $ini = StringSplit(StringStripCR($ini), @LF)
            If $ini[0] > 1 And $ini[1] = $Title Then
                ReDim $AnimeList[$ini[0] / 2][2]
                $AnimeList[0][0] = $ini[0] / 2 - 1
                For $i = 2 To $ini[0] - 1 Step 2
                    $AnimeList[$i / 2][$_URL] = $ini[$i]
                    $AnimeList[$i / 2][$_TITLE] = $ini[$i + 1]
                Next
            EndIf
        EndIf
    EndIf
    If $AnimeList[0][0] = 0 Then GetAnimeList()
EndFunc

Func Main()
    GUICreate($Title, 300, 400)
    GUICtrlCreateLabel("Anime", 10, 10, 280, Default, $SS_CENTER)
    GUICtrlSetFont(-1, 12)
    $hListAnime = GUICtrlCreateList("", 10, 31, 280, 100)
    For $i = 1 To $AnimeList[0][0]
        GUICtrlSetData($hListAnime, $AnimeList[$i][$_TITLE])
    Next
    $hButton = GUICtrlCreateButton("Play!", 105, 340, 90)
    ChangeAnime()
    GUISetState()

    Local $Anime
    While 1
        Switch GUIGetMsg()
            Case $hButton
                If GUICtrlSendMsg($hListEpisodes, $LB_GETCURSEL, 0, 0) <> -1 Then PlayShow()
            Case $hListAnime
                If GUICtrlRead($hListAnime) <> $Anime Then
                    $Anime = GUICtrlRead($hListAnime)
                    GUICtrlDelete($hListEpisodes)
                    ChangeAnime()
                EndIf
            Case $GUI_EVENT_CLOSE
                Exit
        EndSwitch
    WEnd
EndFunc

Func PlayShow()
    Local Const $htmlPath = @ScriptDir & "\Anime.html"
    Local $url, $page, $versions, $pos1, $pos2, $versions, $i

    ; Get Versions
    $url = $ShowList[GUICtrlSendMsg($hListEpisodes, $LB_GETCURSEL, 0, 0) + 1][$_URL]
    $page = BinaryToString(InetRead($domain & $url))
    $pos1 = StringInStr($page, 'class="version cf"')
    $pos2 = StringInStr($page, '</ul>', 0, 1, $pos1)
    $versions = StringRegExp(StringMid($page, $pos1, $pos2 - $pos1), '(?i).+?href="(.+?)">(.+?)</a>', 3)

    ; Get URLs
    For $i = 0 To UBound($versions) - 1 Step 2
        $page = BinaryToString(InetRead($domain & $versions[$i]))
        $url = StringRegExp(StringStripWS($page, 4), '(?i)id="playbox".+?src="(.+?)"', 1)
        $versions[$i] = $url[0]
    Next

    ; Build HTML File
    Local $html = FileOpen($htmlPath, 2)
    If $html = -1 Then
        MsgBox(16, $Title, "Cannot built HTML output file: " & @LF & $htmlPath)
        Return
    EndIf
    FileWriteLine($html, '<html><head>')
    FileWriteLine($html, '<title>' & GUICtrlRead($hListEpisodes) & '</title>')
    FileWriteLine($html, '<style>')
    FileWriteLine($html, 'body {background-color: #000;}')
    FileWriteLine($html, 'ul {list-style-type: none;}')
    FileWriteLine($html, 'li {display: inline; border: 1px solid #fff; margin: 5px; padding: 3px;}')
    FileWriteLine($html, 'li:hover {background-color: #77f;}')
    FileWriteLine($html, '</style>')
    FileWriteLine($html, '</head>')
    FileWriteLine($html, '<body>')
    FileWriteLine($html, '<ul>')
    For $i = 0 To UBound($versions) - 1 Step 2
        FileWriteLine($html, '<li><a target="Video" href="' & $versions[$i] & '">' & $versions[$i + 1] & '</a></li>')
    Next
    FileWriteLine($html, '</ul>')
    FileWriteLine($html, '<hr />')
    FileWriteLine($html, '<iframe name="Video" src="' & $versions[0] & '" width=95% height=95% seamless=seamless></iframe>')
    FileWriteLine($html, '</body>')
    FileClose($html)
    ShellExecute($htmlPath)
EndFunc

Func ChangeAnime()
    Local $i, $url, $key, $page, $links, $index = 0
    ReDim $ShowList[1][2]

    $url = $AnimeList[GUICtrlSendMsg($hListAnime, $LB_GETCURSEL, 0, 0) + 2][$_URL]
    $key = "/watchcartoon-"
    $page = BinaryToString(InetRead($domain & $url))
    $links = StringRegExp($page, '(?i)<a .*?href="(.+?)">(.+?)</a>', 3)

    For $i = 0 To UBound($links) - 1 Step 2
        If StringLeft($links[$i], StringLen($key)) = $key Then
            $index += 1
            ReDim $ShowList[$index + 1][2]
            $ShowList[0][0] = $index
            $ShowList[$index][0] = $links[$i]
            $ShowList[$index][1] = $links[$i + 1]
        EndIf
    Next

    $hListEpisodes = GUICtrlCreateList("", 10, 140, 280, 200, BitOR($WS_BORDER, $WS_VSCROLL))
    For $i = 1 To $ShowList[0][0]
        GUICtrlSetData($hListEpisodes, $ShowList[$i][1])
    Next
EndFunc

Func GetAnimeList()
    Local $regexp, $url, $page, $links, $CurrentPage, $NextPage, $LastPage, $i, $ini
    Local $hwnd = GUICreate($Title, 300, 70, Default, Default, $WS_CAPTION)
    Local $hLabel = GUICtrlCreateLabel("Retrieving index page...", 10, 10, 280)
    Local $hProgress = GUICtrlCreateProgress(10, 30, 280, 30)
    GUISetState()

    $regexp = '(?i)<a .*href="(.+)"><img src=".+" alt="(.+)" /></a>'
    $url = "/cartoon-category-browser"
    $page = BinaryToString(InetRead($domain & $url))
    $LastPage = StringRegExp($page, '(?i)<a .*href=".+".*>(.+)</a>[.\r\n]*<a .*href=".+".*>Next</a>*', 3)
    $LastPage = $LastPage[0]

    For $CurrentPage = 1 To $LastPage
        GUICtrlSetData($hLabel, "Parsing page " & $CurrentPage & " of " & $LastPage & "...")
        GUICtrlSetData($hProgress, $CurrentPage * 100 / $LastPage)
        $links = StringRegExp($page, $regexp, 3)
        For $i = 0 To UBound($links) - 1 Step 2
            $AnimeList[0][0] += 1
            ReDim $AnimeList[$AnimeList[0][0] + 1][2]
            $AnimeList[$AnimeList[0][0]][$_URL] = $links[$i]
            $AnimeList[$AnimeList[0][0]][$_TITLE] = $links[$i + 1]
        Next
        If $CurrentPage <> $LastPage Then
            $NextPage = StringRegExp($page, '(?i)<a .*href="(.+)".*>Next</a>*', 3)
            $NextPage = $NextPage[0]
            $page = BinaryToString(InetRead($domain & $NextPage))
        EndIf
    Next
    GUIDelete($hwnd)

    $ini = FileOpen($Settings, 2)
    If $ini = -1 Then
        MsgBox(16, $Title, "Error accessings settings file:" & @LF & $Settings & @LF & "Cannot save settings")
    Else
        FileWrite($ini, $Title & @CRLF)
        For $i = 1 To $AnimeList[0][0]
            FileWrite($ini, $AnimeList[$i][$_URL] & @CRLF)
            FileWrite($ini, $AnimeList[$i][$_TITLE] & @CRLF)
        Next
        FileClose($ini)
    EndIf
EndFunc

 

 

 

Check out the "Follow this Topic" option at the top-right.  You'll find it quite useful.   :)

Thanks John.. Will follow henceforth..

Share this post


Link to post
Share on other sites

Hey Artisan.. Thanks for the code.. it worked superbly.. :)

Share this post


Link to post
Share on other sites

You're welcome on both counts.  ;) 

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