Sign in to follow this  
Followers 0
3mustgetbeers

Hidden GUI still returning values

7 posts in this topic

Hi,

In the script I have, when you left click on the tray icon a gui is shown. The user enters a postcode into the gui & presses enter; an ini file is read for a corresponding value, copied to the clipboard and then hides. This all works great.

The problem I have is that after pressing enter to complete the function as highlighted above; whenever the user presses the enter key, the function still runs. This is no good as it pretty much renders the clipboard unusable.

Anyway, here is the code I have:

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Include <Misc.au3>
#include "constants.au3"
#Include <GuiToolBar.au3>
#include <Array.au3>
Global Const $INI_Path = ""
Opt("TrayOnEventMode", 1)
Opt("TrayMenuMode", 3)
TraySetState()
TraySetClick(8)
TraySetOnEvent($TRAY_EVENT_PRIMARYUP, "Search")
TraySetOnEvent($TRAY_EVENT_SECONDARYUP, "On_Exit")
$sToolTipText = "Tech Support Region Finder"
TraySetToolTip($sToolTipText)
Global $iIcon_X, $iIcon_Y
_Locate_Icon()
Local $GUI_Width = 65
Local $GUI_Height = 21
$Gui = GUICreate("TSRF", $GUI_Width+2, $GUI_Height+2, @DesktopWidth, @DesktopHeight, BitOR($WS_POPUP, $WS_THICKFRAME, $WS_SIZEBOX))
GUISetBkColor(0xFFFFFF)
$Input1 = GUICtrlCreateInput("Post Code", 0, 0, 65, 21)
GUIRegisterMsg(0x0084, "WM_NCHITTEST")
$aTaskbar = WinGetPos("[CLASS:Shell_TrayWnd]", "")
$aWin = WinGetPos($GUI)
WinMove($GUI, "", @DesktopWidth - $aWin[2], @DesktopHeight - $aWin[3] - $aTaskbar[3])
GUISetState(@SW_HIDE)
While 1
if _IsPressed("0D") AND WinExists($Gui) Then
  $Input = GuiCtrlRead($Input1)
  $TechRegion = IniRead($INI_Path & "data.ini",$Input,"Tech","NOT FOUND")
  ClipPut($TechRegion)
  GUISetState(@SW_HIDE)
EndIf
WEnd
Func WM_NCHITTEST($hWnd, $iMsg, $iwParam, $ilParam)
    #forceref $hWnd, $iMsg, $iwParam, $ilParam
    Return $HTCAPTION
EndFunc
Func _Locate_Icon   ()
    Local $aPos = WinGetPos("[Class:Shell_TrayWnd]", "")
    $iIcon_X = $aPos[0]
    $iIcon_Y = $aPos[1]
    Local $hSysTray_Handle = ControlGetHandle("[Class:Shell_TrayWnd]", "", "[Class:ToolbarWindow32;Instance:1]")
    $aPos = ControlGetPos("[Class:Shell_TrayWnd]", "", "[Class:ToolbarWindow32;Instance:1]")
    If @error Then Return
    $iIcon_X += $aPos[0]
    $iIcon_Y += $aPos[1]
    Local $iSysTray_ButCount = _GUICtrlToolbar_ButtonCount($hSysTray_Handle)
    If $iSysTray_ButCount = 0 Then Return
    For $iSysTray_ButtonNumber = 0 To $iSysTray_ButCount - 1
        Local $sText = _GUICtrlToolbar_GetButtonText($hSysTray_Handle, $iSysTray_ButtonNumber)
        If StringInStr($sText, $sToolTipText) > 0 Then
            $aPos = _GUICtrlToolbar_GetButtonRect($hSysTray_Handle, $iSysTray_ButtonNumber)
            $iIcon_X += $aPos[0]
            $iIcon_Y += $aPos[1]
            ExitLoop
        EndIf
        If $iSysTray_ButtonNumber = $iSysTray_ButCount - 1 Then Return 1
    Next
    Return 0
EndFunc
Func Search()
    GUISetState(@SW_SHOW)
EndFunc
Func On_Exit()
    Exit
EndFunc

I assume it is something to do with the while loop here:

While 1
if _IsPressed("0D") AND WinExists($Gui) Then
  $Input = GuiCtrlRead($Input1)
  $TechRegion = IniRead($INI_Path & "data.ini",$Input,"Tech","NOT FOUND")
  ClipPut($TechRegion)
  GUISetState(@SW_HIDE)
EndIf
WEnd

Though as far as I can see I am telling it to wait for the user to press enter and when the GUI is active. I'm guessing that its something to do with the handle I am using for the gui??

Cheers

Share this post


Link to post
Share on other sites



Though as far as I can see I am telling it to wait for the user to press enter and when the GUI is active. I'm guessing that its something to do with the handle I am using for the gui??

Shouldn't you then replace WinExists with WinActive?

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Thanks for the replies!

Water; I've replaced with WinActive; however it does the exact same thing :D

Admiral; I was under the assumption that I needed the _IsPressed so the gui knows when enter is pressed - or is there another way to do this??

Cheers!

Share this post


Link to post
Share on other sites

3mustgetbeers,

You need to use an Accelerator key to capture the ENTER press - it is like a HotKey but only works when your GUI is active. :oops:

This seems to work as you require:

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <Misc.au3>
#include "constants.au3"
#include <GuiToolBar.au3>
#include <Array.au3>

Opt("TrayOnEventMode", 1)
Opt("TrayMenuMode", 3)

Global Const $INI_Path = ""
Global $iIcon_X, $iIcon_Y
Local $GUI_Width = 65
Local $GUI_Height = 21

TraySetState()
TraySetClick(8)
TraySetOnEvent($TRAY_EVENT_PRIMARYUP, "Search")
TraySetOnEvent($TRAY_EVENT_SECONDARYUP, "On_Exit")

$sToolTipText = "Tech Support Region Finder"
TraySetToolTip($sToolTipText)

_Locate_Icon()

$Gui = GUICreate("TSRF", $GUI_Width + 2, $GUI_Height + 2, @DesktopWidth, @DesktopHeight, BitOR($WS_POPUP, $WS_THICKFRAME, $WS_SIZEBOX))
GUISetBkColor(0xFFFFFF)
$Input1 = GUICtrlCreateInput("Post Code", 0, 0, 65, 21)

; Create a dummy control for the Accelerator to fire <<<<<<<<<<<<<<<<<<<<<<<<
$hDummy = GUICtrlCreateDummy()

$aTaskbar = WinGetPos("[CLASS:Shell_TrayWnd]", "")
$aWin = WinGetPos($Gui)
WinMove($Gui, "", @DesktopWidth - $aWin[2], @DesktopHeight - $aWin[3] - $aTaskbar[3])
GUISetState(@SW_HIDE)

; Set accelerator for Enter to fire the dummy <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
Local $AccelKeys[1][2] = [["{ENTER}", $hDummy]]
GUISetAccelerators($AccelKeys)

GUIRegisterMsg(0x0084, "WM_NCHITTEST")

While 1

    Switch GUIGetMsg()
        Case $hDummy ; If the dummy is fired <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
            $Input = GUICtrlRead($Input1)
            $TechRegion = IniRead($INI_Path & "data.ini", $Input, "Tech", "NOT FOUND")
            Beep() ; Just to show it only works when the GUI is active <<<<<<
            ClipPut($TechRegion)
            GUISetState(@SW_HIDE)
    EndSwitch
WEnd

Func WM_NCHITTEST($hWnd, $iMsg, $iwParam, $ilParam)
    #forceref $hWnd, $iMsg, $iwParam, $ilParam
    Return $HTCAPTION
EndFunc   ;==>WM_NCHITTEST

Func _Locate_Icon()
    Local $aPos = WinGetPos("[Class:Shell_TrayWnd]", "")
    $iIcon_X = $aPos[0]
    $iIcon_Y = $aPos[1]
    Local $hSysTray_Handle = ControlGetHandle("[Class:Shell_TrayWnd]", "", "[Class:ToolbarWindow32;Instance:1]")
    $aPos = ControlGetPos("[Class:Shell_TrayWnd]", "", "[Class:ToolbarWindow32;Instance:1]")
    If @error Then Return
    $iIcon_X += $aPos[0]
    $iIcon_Y += $aPos[1]
    Local $iSysTray_ButCount = _GUICtrlToolbar_ButtonCount($hSysTray_Handle)
    If $iSysTray_ButCount = 0 Then Return
    For $iSysTray_ButtonNumber = 0 To $iSysTray_ButCount - 1
        Local $sText = _GUICtrlToolbar_GetButtonText($hSysTray_Handle, $iSysTray_ButtonNumber)
        If StringInStr($sText, $sToolTipText) > 0 Then
            $aPos = _GUICtrlToolbar_GetButtonRect($hSysTray_Handle, $iSysTray_ButtonNumber)
            $iIcon_X += $aPos[0]
            $iIcon_Y += $aPos[1]
            ExitLoop
        EndIf
        If $iSysTray_ButtonNumber = $iSysTray_ButCount - 1 Then Return 1
    Next
    Return 0
EndFunc   ;==>_Locate_Icon

Func Search()
    GUISetState(@SW_SHOW)
EndFunc   ;==>Search

Func On_Exit()
    Exit
EndFunc   ;==>On_Exit

All clear? :D

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

M23

Ahh! Never heard of accelerator key before but yes, worked a treat!

Cheers!

Share this post


Link to post
Share on other sites

3mustgetbeers,

My pleasure. Useful things accelerator keys - I use them a lot. :D

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

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