Jump to content
Sign in to follow this  
remin

GuiCtrlRead and GUICtrlSetData values not updated

Recommended Posts

remin

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

Share this post


Link to post
Share on other sites
l3ill

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.

Share this post


Link to post
Share on other sites
l3ill

#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

Share this post


Link to post
Share on other sites
remin

@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

Share this post


Link to post
Share on other sites
l3ill

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.

Share this post


Link to post
Share on other sites
remin

Tnx, but it is not what I want.

I want to keep the GUI, clicking on a button and read with every search the inputbox again.

Share this post


Link to post
Share on other sites
AutID

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

Share this post


Link to post
Share on other sites
remin

Wow.. great thank you.

That resolved my question  :)

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  

  • Similar Content

    • nacerbaaziz
      By nacerbaaziz
      Hello my friends
      I have an inquiry and I hope to find the answer here
      I want to create a graphical user interface
      but I want to hide the system menu
      I mean the window menu
      Is this possible?
      If is possible please give me how to do that
      Thanks in advance
    • helmar
      By helmar
      I was playing around with simple GUI creation.  I tend to like parameter driven coding (in prior life (years ago) as Clipper/FoxPro/dBase coder).  Just wanted to see what I could do with a GUI.
      #Region options, includes Opt('MustDeclareVars', 1) Opt("GUIOnEventMode", 1) ; Change to OnEvent mode #include <GUIConstantsEx.au3> #EndRegion options, includes Global Const $nCols = 2, $nRows = 6, $nSpacer = 10, $nBtnWidth = 150, $nBtnHeight = 30 Global $xName = 0, $xID = 0 Global $nGUIWidth = ($nCols * $nBtnWidth) + (($nCols + 1) * $nSpacer) Global $nGUIHeight = ($nRows * $nBtnHeight) + (($nRows + 1) * $nSpacer) Global $hMainGUI = GUICreate("Calculated GUI", $nGUIWidth, $nGUIHeight, -1, -1) For $xRows = 1 to $nRows ;in this arrangement, tabbing is left to right, then next row For $xCols = 1 to $nCols ;reverse the order of this line with the prior line for top to bottom tabbing, then next col $xName += 1 $xID += 1 Global $Dummy = GUICtrlCreateButton("Button" & $xName, _ ($nBtnWidth * ($xCols - 1)) + (($xCols - 1) * $nSpacer) + $nSpacer, _ ($nBtnHeight* ($xRows - 1)) + (($xRows - 1) * $nSpacer) + $nSpacer, _ $nBtnWidth, _ $nBtnHeight) GUICtrlSetOnEvent($xID+2, "Handler") Next Next GUISetOnEvent($GUI_EVENT_CLOSE, "CloseApp") GUISetState(@SW_SHOW) While 1 Sleep(10) WEnd Func CloseApp() Exit EndFunc Func Handler() MsgBox(0,0,"Button " & @GUI_CtrlId - 2) EndFunc  
    • jasontj
      By jasontj
      Hello.  I'm working on converting another script from IE to Firefox.  I can't seem to get a handle on the field "Defendant" to fill in a last, first name on this page:
      http://www.hcdistrictclerk.com/Edocs/Public/Search.aspx?Tab=tabCriminal
      I also can't seem to submit the form.   I've tried the code below... stuff may be commented out that I have tested.
       
          _FFOpenUrl("http://www.hcdistrictclerk.com/Edocs/Public/Search.aspx?Tab=tabCriminal")    
          _FFLoadWait()
          $oTextFN = _FSObjGet("ctl00_ctl00_ctl00_ContentPlaceHolder1_ContentPlaceHolder2_ContentPlaceHolder2_tabSearch_tabCriminal_txtCrimDefendant", "ID")
          
          _FFObj($oTextFN, "value", "Smith, John")    
          $subButton = _FFObjGet("ctl00$ctl00$ctl00$ContentPlaceHolder1$ContentPlaceHolder2$ContentPlaceHolder2$btnSearch", "name")
          _FFClick($subButton)
          _FFLoadWait()
          
      ;    _FFFormSubmit()
      ;    _FFLoadWait()
       
      Any help from the experts on here would be greatly appreciated.  
       
      Jason
       
       
       
       
    • XinYoung
      By XinYoung
      For fun, I'm building an app that opens a webpage and refreshes it every 30 seconds.
      But once the script performs _IEAction($oIE, "refresh"), the GUI closes.
      Any help is appreciated.
       

      #include <ButtonConstants.au3>
      #include <EditConstants.au3>
      #include <GUIConstantsEx.au3>
      #include <StaticConstants.au3>
      #include <WindowsConstants.au3>
      #include <WinAPIFiles.au3>
      #include <Array.au3>
      #include <File.au3>
      #include <Excel.au3>
      #include <DateTimeConstants.au3>
      #include <MsgBoxConstants.au3>
      #include <WinAPIShellEx.au3>
      #include <MsgBoxConstants.au3>
      #include <Date.au3>
      #include <ComboConstants.au3>
      #include <guimenu.au3>
      #include <IE.au3>
      HotKeySet("{F4}", "_Exit")
      ;Open the file(s) in the selected folder
      $extension = ".txt"
      $app2openWith = @SystemDir & "\notepad.exe"
      Func Begin()
          Global $loopTrick = 0
          #Region ### START Koda GUI section ### Form=c:\users\mchu\downloads\autoit\my code\form1.kxf
          Global $UI = GUICreate("Hit Em Up!", 256, 113, -1, -1)
          GUISetBkColor(0x000000)
          $menu = _GUICtrlMenu_GetSystemMenu($UI)
          _GUICtrlMenu_EnableMenuItem($menu, $SC_CLOSE, 1, False)
          Global $url = GUICtrlCreateInput("https://www.youtube.com/watch?v=dQw4w9WgXcQ", 81, 8, 160, 21)
          $Label1 = GUICtrlCreateLabel("Target:", 16, 8, 55, 17)
          GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif")
          GUICtrlSetColor(-1, 0x00FF00)
          Global $StartBut = GUICtrlCreateButton("Start", 16, 40, 67, 25)
          GUICtrlSetFont(-1, 13, 800, 0, "MS Sans Serif")
          GUICtrlSetBkColor(-1, 0x008000)
          $Label2 = GUICtrlCreateLabel("(Press F4 to Exit)", 96, 40, 8000, 17)
          GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif")
          GUICtrlSetColor(-1, 0x00FF00)
          GUISetState(@SW_SHOW)
          #EndRegion ### END Koda GUI section ###
          While 1
              $UIfunc = GUIGetMsg()
              Select
                  Case $UIfunc = $GUI_EVENT_CLOSE
                      _Exit()
                  Case $UIfunc = $StartBut
                      If GUICtrlRead($url) = "" Then
                          MsgBox(48, "Um...", "Give me a target you idiot.")
                      Else
                          GUICtrlSetState($url, $GUI_DISABLE)
                          GUICtrlSetState($StartBut, $GUI_DISABLE)
                          Start()
                      EndIf
              EndSelect
          WEnd
      EndFunc   ;==>Begin
      Func Start()
          If $loopTrick = 0 Then
              Global $oIE = _IECreate(GUICtrlRead($url))
              _IELoadWait($oIE)
              Again()
          ElseIf $loopTrick = 1 Then
              Sleep(3000)
              _IEAction($oIE, "refresh")
              Sleep(3000)
              Start()
          EndIf
      EndFunc   ;==>Start
      Func Again()
          $loopTrick = 1
          Start()
      EndFunc   ;==>Again
      Func _Exit()
          Exit
      EndFunc   ;==>_Exit
    • kcvinu
      By kcvinu
      Hi all,
      I have a button created with _GUICtrlButton_Create function. I know that this function returns a handle of button instead of an ID. So i have obtain control ID by calling _WinAPI_GetDlgCtrlID function. After that i have tried the GUICtrlSetBkColor function. But it didnt worked. Any suggestions will be appreciated. Thanks in advance. 
      Note : - The window which carries this button is not created with native gui create function. Instead, it is created with CreateWindowEx api function.
×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.