Jump to content

GuiCtrlRead and GUICtrlSetData values not updated


remin
 Share

Go to solution Solved by AutID,

Recommended Posts

I created a search GUI with an InputBox and a Button to empty the input box.

I read the inputbox using GuiCtrlRead and empty the input box using GUICtrlSetData.

When I click a search button or click the "empty inputbox" button, everything works fine.

However after having done the 1st search and I click again on the search button

or whatever other button the input box field is not updated 

GUICtrlRead($RWSearch)  --> gives a value '0'

What did I wrong?

Same thing when I empty the input box.

The 1st time it works well.

When I empty the inputbox after having done a search it doesn't

work anymore. Nothing happens.

My search GUI is always on TOP so I don't reuse the hotkey between searches.

(The GUI is not deleted after a search), 

 

My code:

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <String.au3>
#include <GuiButton.au3>
#include <Constants.au3>

HotKeySet("^4", "searchmenu")


While 1
    Sleep(10000)
WEnd

Func searchmenu()

global $url
Send("^c")
$InEditBox = ClipGet()

;========GUI=============
 $Form5 =         GUICreate("Search Menu", 345, 410, 100, 100)
 $RWSearch =      GUICtrlCreateInput($InEditBox,                      16,  10, 270, 25)
 $clipc =         GUICtrlCreateButton("x",                           300,  10,  15, 20)
 $textGoogle  =   GUICtrlCreateLabel("Google:",                       20,  50, 100, 20)
 $bsearch =       GUICtrlCreateButton("Search",                      110,  50,  60, 20)
 $bimages =       GUICtrlCreateButton("Images",                      175,  50,  60, 20)

GUISetState(@SW_SHOW)
;========GUI=============

While 1
$nMsg = GUIGetMsg()
Switch $nMsg

   Case $GUI_EVENT_CLOSE
        GuiDelete($Form5)
        ExitLoop

      Case $clipc
           ; empty inputbox
           GUICtrlSetData($RWSearch, "")

      Case $bsearch
           ; search text in google 
           $RWSearch = GUICtrlRead($RWSearch)
           $RWSearch = StringRegExpReplace($RWSearch, "(\s+)", "+")
           $url = "https://www.google.com/search?q=" & $RWSearch
           SearchMenuExec()

      Case $bimages
           ; search images in google
           $RWSearch = GUICtrlRead($RWSearch)
           $RWSearch = StringRegExpReplace($RWSearch, "(\s+)", "+")
           $url = "http://images.google.com/images?hl=en&q=" & $RWSearch
           SearchMenuExec()

EndSwitch
 WEnd
EndFunc

Func SearchMenuExec()
  ClipPut($url)
  ShellExecute($url) 
EndFunc
Edited by remin
Link to comment
Share on other sites

Hi Remin,

  It is working fine for me, I did notice that every time you hit CTRL + 4 it opens a new GUI. Did you want that?

Maybe deleting the GUI after the search would solve some of the problems you are having, and the hotkey will just open anew GUI every time.

Link to comment
Share on other sites

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <String.au3>
#include <GuiButton.au3>
#include <Constants.au3>

HotKeySet("^4", "searchmenu")
Global $url


While 1
    Sleep(10000)
WEnd

Func searchmenu()

    Send("^c")
    $InEditBox = ClipGet()

    ;========GUI=============
    $Form5 = GUICreate("Search Menu", 345, 410, 100, 100)
    $RWSearch = GUICtrlCreateInput($InEditBox, 16, 10, 270, 25)
    $clipc = GUICtrlCreateButton("x", 300, 10, 15, 20)
    $textGoogle = GUICtrlCreateLabel("Google:", 20, 50, 100, 20)
    $bsearch = GUICtrlCreateButton("Search", 110, 50, 60, 20)
    $bimages = GUICtrlCreateButton("Images", 175, 50, 60, 20)

    GUISetState(@SW_SHOW)
    ;========GUI=============

    While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg

            Case $GUI_EVENT_CLOSE
                GUIDelete($Form5)
                ExitLoop
                Return 0

            Case $clipc
                ; empty inputbox
                GUICtrlSetData($RWSearch, "")
                ExitLoop
            Case $bsearch
                ; search text in google
                $RWSearch = GUICtrlRead($RWSearch)
                $RWSearch = StringRegExpReplace($RWSearch, "(\s+)", "+")
                $url = "https://www.google.com/search?q=" & $RWSearch
                SearchMenuExec()
                ExitLoop

            Case $bimages
                ; search images in google
                $RWSearch = GUICtrlRead($RWSearch)
                $RWSearch = StringRegExpReplace($RWSearch, "(\s+)", "+")
                $url = "http://images.google.com/images?hl=en&q=" & $RWSearch
                SearchMenuExec()
                ExitLoop

        EndSwitch
    WEnd
    GUIDelete()

EndFunc   ;==>searchmenu



Func SearchMenuExec()
    ClipPut($url)
    ShellExecute($url)
EndFunc   ;==>SearchMenuExec

Link to comment
Share on other sites

@Billo,

Thank you for your reply.

I forgot to write in my question that my search GUI is always on TOP so I don't reuse the hotkey between searches.

(The GUI is not deleted after a search), 

(I'll update my question)

Edited by remin
Link to comment
Share on other sites

No Problem,

  it seems to me the idea was pretty cool to be able to hotkey paste anything you've hi-lited into your search box and then hit search or image and have the gui disappear until needed again.

  anyway, thats what the one does that I posted above. just like yours with a few minor changes.

Good luck.

Link to comment
Share on other sites

  • Solution

Maybe something like this? I tried to clean it up a bit but it still is very bad formated. Clean up whatever you dont need and remove the #includes that are useless...

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <String.au3>
#include <GuiButton.au3>
#include <Constants.au3>

HotKeySet("^4", "searchmenu")
Global $url


While 1
Sleep(10000)
WEnd

Func searchmenu()

Send("^c")
$InEditBox = ClipGet()

;========GUI=============
$Form5 = GUICreate("Search Menu", 345, 410, 100, 100)
$RWSearch = GUICtrlCreateInput($InEditBox, 16, 10, 270, 25)
$clipc = GUICtrlCreateButton("x", 300, 10, 15, 20)
$textGoogle = GUICtrlCreateLabel("Google:", 20, 50, 100, 20)
$bsearch = GUICtrlCreateButton("Search", 110, 50, 60, 20)
$bimages = GUICtrlCreateButton("Images", 175, 50, 60, 20)
GUISetState(@SW_SHOW)
;========GUI=============

While 1
$nMsg = GUIGetMsg()
Switch $nMsg

Case $GUI_EVENT_CLOSE
GUIDelete($Form5)
Exit
Case $clipc
; empty inputbox
GUICtrlSetData($RWSearch, "")
Case $bsearch
; search text in google
$RWSearch1 = GUICtrlRead($RWSearch)
$RWSearch2 = StringRegExpReplace($RWSearch1, "(\s+)", "+")
$url = "https://www.google.com/search?q=" & $RWSearch2
SearchMenuExec()
Case $bimages
; search images in google
$RWSearch1 = GUICtrlRead($RWSearch)
$RWSearch2 = StringRegExpReplace($RWSearch1, "(\s+)", "+")
$url = "http://images.google.com/images?hl=en&q=" & $RWSearch2
SearchMenuExec()
EndSwitch
WEnd
EndFunc ;==>searchmenu



Func SearchMenuExec()
ClipPut($url)
ShellExecute($url)
EndFunc ;==>SearchMenuExec
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

×
×
  • Create New...