Sign in to follow this  
Followers 0
remin

GuiCtrlRead and GUICtrlSetData values not updated

8 posts in this topic

#1 ·  Posted (edited)

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



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

#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

#4 ·  Posted (edited)

@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

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

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

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

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  
Followers 0

  • Similar Content

    • IAMK
      By IAMK
      Hello,
       
      I have a script which uses a GUI with two buttons. It gets shown and hidden., and pressing the buttons (including their hotkeys) highlights the button, making you able to press enter the next time.
      However, I don't want that.
       
      I've tried using WinActivate() to make enter do things on another program, but the enter is still tied to the AutoIT GUI (which still has the button highlighted).
       
      Here's the important part of my code:
      $MY_GUI = GUICreate("Check.exe", 400, 300, ((@DesktopWidth / 2) - 200), -500) WinSetOnTop($MY_GUI, "", 1) ;Keeps the window on the top. $Button1 = GUICtrlCreateButton("Pass (Ctrl+P)", 40, 250, 120, 40, $WS_GROUP) GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif") $Button2 = GUICtrlCreateButton("Fail (Ctrl+F)", 240, 250, 120, 40, $WS_GROUP) GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif") $GUIText = GUICtrlCreateLabel("", 20, 10, 360, 230) GUICtrlSetFont(-1, 13, 400, 0, "MS Sans Serif") GUICtrlSetData($GUIText, Execute($stepMessage[$step])) $showGUI = "True" GUISetState(@SW_SHOW) While($showGUI = "True") $buttonPressed = GUIGetMsg() Switch $buttonPressed Case $Button1 ;Pass $pass = "True" $buttonPressed = 0 $showGUI = "False" GUISetState(@SW_HIDE) Case $Button2 ;Fail $buttonPressed = 0 $showGUI = "False" GUISetState(@SW_HIDE) While($message = "") $message = InputBox("Check.exe", "Please enter the reason the step failed." & @CRLF, "", "", 300, 200, ((@DesktopWidth / 2) - 150), -400) WEnd Return $message EndSwitch WEnd Local $pass = "False" ;Whether "Pass" or "Fail" was pressed. Local $failLog = xxxfunc($pass) ;Returns a message to log if the step failed. ##THIS CALLS THE CODE SNIPPET ABOVE## FileWrite($file, _Now() & ": Step " & $step & getStatus($pass) & "and took " & Ceiling(TimerDiff($timer) / 1000) & " seconds." & @CRLF) If($failLog <> "") Then FileWrite($file, "Logged comment: " & $failLog & @CRLF) EndIf WinActivate("[TITLE:ProgramName]") ;Hotkeys: HotKeySet("^{p}", "pressPass") HotKeySet("^{f}", "pressFail") Func pressPass() $buttonPressed = $Button1 EndFunc Func pressFail() $buttonPressed = $Button2 EndFunc  
      The GUI's button/hotkey pressing works correctly.
      The same WinActivate code works in another script of mine.
      Together, WinActivate is not take "Active" away from the GUI's last-pressed button. How do I fix this?
       
      Thank you in advance.
    • funkey
      By funkey
      Hello,
      it's quite often, that someone asks how to change the texts of the MsgBox buttons or the InputBox buttons or how to change the position of ta MsgBox. Since years I use CBT hooks for that, but now I made a small UDF out of it for the ease of use. Of course you can build your own GUI or use already existing UDFs to do the same, but I like this way and you can hack (hook) the inbuild InputBox.
       
      HookDlgBox.au3
      #include-once #include <WinAPI.au3> Global Const $tagCBT_CREATEWND = "ptr lpcs;HWND tagCBT_CREATEWND" Global Const $tagCREATESTRUCT = "ptr lpCreateParams;handle hInstance;HWND hMenu;HWND hwndParent;int cy;int cx;int y;int x;LONG style;ptr lpszName;ptr lpszClass;DWORD dwExStyle" Global $g__hProcDlgBox = DllCallbackRegister("__DlgBox_CbtHookProc", "int", "int;int;int") Global $g__TIdDlgBox = _WinAPI_GetCurrentThreadId() Global $g__hHookDlgBox = _WinAPI_SetWindowsHookEx($WH_CBT, DllCallbackGetPtr($g__hProcDlgBox), 0, $g__TIdDlgBox) Global Const $g__MaxDlgBtns = 5 ; maximum of 5 buttons to rename text Global Const $g__MaxDlgItemId = 11 ; maximun ID of buttons to search is 11 as this is the maximun used in Messagebox Global $g__DlgBoxPosX, $g__DlgBoxPosY, $g__DlgBoxWidth, $g__DlgBoxHeight Global $g__aDlgBoxBtnText[$g__MaxDlgBtns] Global $g__DlgBtnCount = 0 _DlgBox_SetDefaults() OnAutoItExitRegister("__DlgBox_UnregisterHook") Func _DlgBox_SetButtonNames($TxtBtn1 = Default, $TxtBtn2 = Default, $TxtBtn3 = Default, $TxtBtn4 = Default, $TxtBtn5 = Default) $g__aDlgBoxBtnText[0] = $TxtBtn1 $g__aDlgBoxBtnText[1] = $TxtBtn2 $g__aDlgBoxBtnText[2] = $TxtBtn3 $g__aDlgBoxBtnText[3] = $TxtBtn4 $g__aDlgBoxBtnText[4] = $TxtBtn5 $g__DlgBtnCount = @NumParams EndFunc ;==>_DlgBox_SetButtonNames Func _DlgBox_SetPosition($x = Default, $y = Default) ;only for MsgBox, not working and not needed for InputBox $g__DlgBoxPosX = $x $g__DlgBoxPosY = $y EndFunc ;==>_DlgBox_SetPosition Func _DlgBox_SetSize($w = Default, $h = Default) $g__DlgBoxWidth = $w $g__DlgBoxHeight = $h EndFunc ;==>_DlgBox_SetSize Func _DlgBox_SetDefaults() $g__DlgBoxPosX = Default $g__DlgBoxPosY = Default $g__DlgBoxWidth = Default $g__DlgBoxHeight = Default For $i = 0 To UBound($g__aDlgBoxBtnText) - 1 $g__aDlgBoxBtnText[$i] = Default Next EndFunc ;==>_DlgBox_SetDefaults Func __DlgBox_CbtHookProc($nCode, $wParam, $lParam) Local $tcw, $tcs Local $iSearch = 0 Local $ahBtn[$g__DlgBtnCount] If $nCode < 0 Then Return _WinAPI_CallNextHookEx($g__hHookDlgBox, $nCode, $wParam, $lParam) EndIf Switch $nCode Case 3 ;5=HCBT_CREATEWND If _WinAPI_GetClassName(HWnd($wParam)) = "#32770" Then ;Dialoig window class $tcw = DllStructCreate($tagCBT_CREATEWND, $lParam) $tcs = DllStructCreate($tagCREATESTRUCT, DllStructGetData($tcw, "lpcs")) If $g__DlgBoxPosX <> Default Then DllStructSetData($tcs, "x", $g__DlgBoxPosX) If $g__DlgBoxPosY <> Default Then DllStructSetData($tcs, "y", $g__DlgBoxPosY) If $g__DlgBoxWidth <> Default Then DllStructSetData($tcs, "cx", $g__DlgBoxWidth) If $g__DlgBoxHeight <> Default Then DllStructSetData($tcs, "cy", $g__DlgBoxHeight) EndIf Case 5 ;5=HCBT_ACTIVATE For $i = 1 To $g__MaxDlgItemId If IsHWnd(_WinAPI_GetDlgItem($wParam, $i)) Then If $g__aDlgBoxBtnText[$iSearch] <> Default Then _WinAPI_SetDlgItemText($wParam, $i, $g__aDlgBoxBtnText[$iSearch]) $iSearch += 1 If $iSearch >= UBound($ahBtn) Then ExitLoop EndIf Next EndSwitch Return _WinAPI_CallNextHookEx($g__hHookDlgBox, $nCode, $wParam, $lParam) EndFunc ;==>__DlgBox_CbtHookProc Func __DlgBox_UnregisterHook() _WinAPI_UnhookWindowsHookEx($g__hHookDlgBox) DllCallbackFree($g__hProcDlgBox) EndFunc ;==>__DlgBox_UnregisterHook Func _WinAPI_SetDlgItemText($hDlg, $nIDDlgItem, $lpString) Local $aRet = DllCall('user32.dll', "int", "SetDlgItemText", _ "hwnd", $hDlg, _ "int", $nIDDlgItem, _ "str", $lpString) Return $aRet[0] EndFunc ;==>_WinAPI_SetDlgItemText  
      Simple example to see how to use it
      #include "HookDlgBox.au3" _DlgBox_SetButtonNames("1", "two", "3") MsgBox(4, "Test 1", "Custom button texts") _DlgBox_SetPosition(20, 20) MsgBox(66, "Test 2", "Custom position and button texts") _DlgBox_SetButtonNames("Submit", "Don't submit", "Don't know") InputBox("Test 3", "Where were you born?", "Planet Earth") _DlgBox_SetSize(800, 800) InputBox("Test 4", "Where were you born?", "Planet Earth") _DlgBox_SetSize(Default, 800) MsgBox(66, "Test 5", "Strange but working") _DlgBox_SetButtonNames(Default, "Wait", "What?") _DlgBox_SetSize(Default, Default) _DlgBox_SetPosition(500, 500) MsgBox(66, "Test 6", "So far so good!") _DlgBox_SetDefaults() MsgBox(6, "Test 7", "Default position and button texts") Hope you like it.
       
      Best regards
      funkey
      HookDlgBox Example.au3
      HookDlgBox.au3
    • fatpig
      By fatpig
      Dear AutoIT Community.
      I am currently working on a program that will display lots of images in a scroll down GUI.
      I create the GUI based on the number of images, which works fine.
      But all images I place using GuiCtrlCreatePic above a threshold of around 32000 pixels (cant say exactly) are placed at negative locations and finally will reach 0 again
      and will then populate on top of the images placed there before.
      For $i = 1 To $Images[0] ; Get picture dimensions $hImage = _GDIPlus_ImageLoadFromFile($ImgRep & $Images[$i]) $iX = _GDIPlus_ImageGetWidth($hImage) $iY = _GDIPlus_ImageGetHeight($hImage) _GDIPlus_ImageDispose($hImage) ; Resize & place images in GUI $Pic[$i] = GUICtrlCreatePic($ImgRep & $Images[$i], $Spacer, Round($yPos, 0), $MaxImgWidth, $MaxImgWidth * ($iY / $iX)) $yPos = $yPos + $MaxImgWidth * ($iY / $iX) + $Spacer $log = $log & "|" & $yPos $currentlut = $Images[1] Next I have found a limit at 32767 pixels for some GUI elements when googling around.
      Can someone tell me how to circumvent that?
      thanks!
      cheers
      Felix
    • Shirdish_chakravarthi
      By Shirdish_chakravarthi
      Hello Guys this is my gui and i need the numeric value typed in the highlighted  inputbox. if this value is greater than 1 i need to perform some operations
      \
       
      Here is the summary about that field which i got from wininfo tool

      i tried writing the code as shown below.. but the msgbox is popping up empty value..when the same code is pasted under some button action i am able to access the value present in the field..but when placed alone as written in the attached script i am unable to fetch it... 

      here i am using the valu present in the field

      can you guys tell me what's wrong??? or how can i get that value?
       
      My_GUI.au3