Leaderboard
Popular Content
Showing content with the highest reputation on 12/10/2015 in all areas
-
Maps 101: All you need to know about them!
argumentum and one other reacted to Kealper for a topic
Since it looks like some people were unsure of what I was trying to say in my benchmark, I've edited my post about the benchmark with this clarification:2 points -
_Service_UDF v4 : Build your own service with autoit code
cramaboule reacted to arcker for a topic
I can't be responsible for any impact of your script or services you would run in production. | _Services_UDF v4 | | By Arcker | Run your script as a service | Req. AutoIt 3.3.8.1 min, last beta recommended ( tested in 3.3.9.21 ) |_______________________________________ ++ Preparing v5 !! Checked on 27/04/2015 <> Updated on 10/23/2013 <> Updated 07/29/2013 <> Best practices Updated 24/02/2012 -- Removed GUI code, and old codes. == Warning : 26/02/2012 <> New Version (v3 ) : 29/07/2013 | Thx to ShminkyBoy, wraithdu, Udgeen and HolmesShelock for their great contributions. Special thx to bitboy, Downloads see end of this post : ServiceExample_v4, Services.au3, ServicesConstants.au3 Presentation Here is my _Service _ UDF With this UDF, you can compile your autoit script and run it as service. Any comments are welcome. Hope you'll like it, 1 - changelog Update V4 : 23/10/2013,27/04/2015 Update : V3 on 29/07/2013 Compile the service example to see how to do then you can use the main function for your proper scriptChoose an appropriate location and copy the script here.open a command prompt, and execute the compiled script with option –I ( must be admin right since vista )start / execute "services.msc" . You will see a service called "Autoit_service". you can execute "sc query" in a command prompt too.Launch it : it will run the previous compile script. The main function will be executed after the service_init.stop and relaunch the service as you wish. Examples / Session Change / uses v1 (lock, logon, etc) By HolmesShelock. Awesome work. Edit : this example doesn't use v2 or v3 method SessionChange Service.zip Example output to give you an idea Examples demos Synoptic And for End Users, I've tried to explain the service control manager and the way it works with programs. see below Best Practice, by arcker : /! please read this if you encounter stability issues I've had to rework on services.au3 to reflect threadsafe. Threadsafe means each dll call must be on "dllopened" instead of calling dll directly for example, if you need a function in kernel32.dll, you have to open it and call it after. That's contraignant since a lot of integrated functions in autoit are not programmed this way. If you take my services.au3, at the end, you'll see reworked function to handle this change. I've not tried services for a while, since i don't need it for now, but i can help you only if your provide whole script, to see how you call every functions. I can tell that fix stability issues in callback, but i don't think it's need for your script, as far as you don't use callback. Best Practice, by udgeen : Good news! Probably i've found the working method of integrating service.au3 with other projects I realised it after ASock.au3 project by Zatorg (please, sorry if im wrong) - ASock is asynck socket - tcp on event (uses ws2_32.dll). Asock & sqlite didnt work together. The only reason for that was..._ArrayDisplay() func with gui!!! Ok. I made special sqlite.au3 without dependences. It works, but my udf seemed too be much heavy to use at another project. Few weeks ago I returned to service.au3 and found TCP UDF, Event driven project based on ASock.au3. It seemed to work as example, but didn't work at all as service. In my variant of service_example.au3 i posted msdn words about service_main procedure, that it must contain all global vars of project I'll try to post that project as an another service_example.au3 in some weeks here. If it will works. Some advice: use SysInternals Process Explorer (free gui based), or kill.exe from support tools to stop suspended service process. U can start-stop service even net start/net stop commands. Use file logging while debuging. No need to install-uninstall service after every recompilation: only stop, recompile, start. See, if it was suspended (while stopping) - kill process. The only reason not to stop service correctly i've found for today is unclean exit: opened sockets, maybe some dlls. Edit : Arcker note: too bad, that would be too easy. unclean exit is not due to opened dll, but by some more internal exit checks or something. FAQ. 1 - Hey, I've got error 1063 or error 0, what does that mean ? It simply means that you intend to run your script in scite or directly by executing it. Your script has to be installed as service and run from it. Several ways to do it : You have to combine all Globals in one place: for example at the the begining. You have to make it with other udfs too... silly workThen sort Global Const and other Global statements. If u see something like global $x = 1 do that way: global $x leeve at top. $x =1 insert into module's (udf or project) Init func.U have to do it even with standart udf... or use only necessary functions from it in your own include. Or... maybe u have another plan?Try to build your project with modified udfs - does it works now? Hmm... But it have to Maybe later after everything will work fine i'll say "msdn is wrong, microsoft lies"... But maybe i'll say that microsoft - is not so bad, because autoit works in itnet start "yourservicename"Services.mscUse API provided _Service_start, Service_stop. 2 - I want to make a GUI ! It's not possible in a service. Create another process and communicate with your service by using IPC. 3 - I've to let the main function that way ? That's contraignant. Hey, a script intended to run as service is special no ? Autoit is not C++. The only way to have a "Main" in autoit is to have a function. If you find another way, please share it ServiceExample_ThreadSafe.au3 Services.au3 ServiceExample_v4.au3 ServicesConstants.au31 point -
Hi! Today I want to show you my current AutoIt project: The ISN AutoIt Studio. The ISN AutoIt Studio is a complete IDE made with AutoIt, for AutoIt! It includes a GUI designer, a code editor (with syntax highlighting, auto complete & intelisense), a file viewer, a backup system, trophies and a lot more features!! Here are some screenshots: Here some higlights: -> easy to create/manage/public your AutoIt-projects! ->integrated GUI-Editor (ISN Form Studio 2) ->integrated - file & projectmanager ->auto backupfunction for your Projects ->extendable with plugins! ->available in several languages ->trophies ->Syntax highlighting /Autocomplete / Intelisense ->Dynamic Script ->detailed overview of the project (total working hours, total size...) And much more!!! -> -> Click here to download ISN AutoIt Studio <- <- Here is the link to the german autoit forum where I posted ISN AutoIt Studio the first time: http://autoit.de/index.php?page=Thread&threadID=29742&pageNo=1 For more information visit my Homepage: https://www.isnetwork.at So….have fun with ISN AutoIt Studio! PS: Sorry for my bad English! ^^1 point
-
Theoretically its possible. But this would be a very deep change in the system of the ISN. (Especially the formstudio) The "lite" version of your idea is the extracode feature in the Formstudio where you can add any AutoIt Code to your Control.1 point
-
Help file should really be your first stop, always look at it with each function you use. $oIEextend = _IEAttach($hWnd, "hwnd")1 point
-
1 point
-
The code in first link in post 3 by mLipok is not too hard to implement based on the MSAA API. MSAccessibility.au3 below is an updated version of the API. Constants already included in AutoIt 3.3.14 are commented out, and IAccessible interface in CUIAutomation2.au3 by junkew is included. test.au3 #include <IE.au3> #include <GUIConstants.au3> #include <WinAPIConstants.au3> #include <WinAPI.au3> #include "MSAccessibility.au3" Global $aAccObjects[100][3], $iAccObjects = 0 Example() Func Example() ; Opens IE with three tabs Local $oIE1 = _IECreate("www.google.nl") _IELoadWait($oIE1) Local $hwndIE1 = _IEPropertyGet($oIE1, "hwnd") __IENavigate($oIE1, "http://www.nu.nl", 0, 0x800) _IELoadWait($oIE1) Local $oIE2 = Null Do Sleep(10) $oIE2 = _IEAttach('http://www.nu.nl', 'url', 1) Until Not @error Local $hwndIE2 = _IEPropertyGet($oIE2, "hwnd") __IENavigate($oIE1, "http://www.telegraaf.nl", 0, 0x800) _IELoadWait($oIE1) Local $oIE3 = Null Do Sleep(10) $oIE3 = _IEAttach('http://www.telegraaf.nl', 'url', 1) Until Not @error Local $hwndIE3 = _IEPropertyGet($oIE3, "hwnd") MsgBox(0, @ScriptLineNumber, 'test') Local $hChild = 0, $hWindow = WinGetHandle( "[CLASS:IEFrame]", "" ) ; Internet Explorer FindChildWindowByClass( $hWindow, $hChild, "DirectUIHWND" ) ; This function does not depend on a specific IE version ;ConsoleWrite( "$hChild = " & $hChild & @CRLF & @CRLF ) ; Accessible object Local $pChild, $oChild AccessibleObjectFromWindow( $hChild, $OBJID_CLIENT, $tIID_IAccessible, $pChild ) WalkTreeWithAccessibleChildren( $pChild, 0, 2 ) ; The tabs belongs to level 1 (zero based) ;ConsoleWrite( @CRLF ) ; Identifying the tabs by the level makes it independent of the localized string "Tab Row" For $i = 0 To $iAccObjects - 1 If $aAccObjects[$i][2] = 1 Then ExitLoop ; The tabs belongs to level 1 Next Local $iAccFirst = $i, $iAccCount = $iAccObjects - $i - 1 ; Index of first tab, number of tabs Local $hGui = GUICreate( "IE Tabs", 400, 160, -1, 300, -1, $WS_EX_TOPMOST ) Local $idBut1 = GUICtrlCreateButton( $aAccObjects[$iAccFirst][1], 10, 10, 380, 40 ) For $i = 1 To $iAccCount - 1 GUICtrlCreateButton( $aAccObjects[$iAccFirst+$i][1], 10, 10+$i*50, 380, 40 ) Next GUISetState() Local $iMsg While 1 $iMsg = GUIGetMsg() Switch $iMsg Case $idBut1 To $idBut1 + $iAccCount - 1 $aAccObjects[$iAccFirst+$iMsg-$idBut1][0].accDoDefaultAction(0) Case $GUI_EVENT_CLOSE ExitLoop EndSwitch WEnd ; Cleanup For $i = 0 To $iAccObjects - 1 $aAccObjects[$i][0] = 0 Next GUIDelete( $hGui ) Exit EndFunc Func FindChildWindowByClass( $hParent, ByRef $hFound, $sClass ) If Not $hParent Then Return Local $hChild = _WinAPI_GetWindow( $hParent, $GW_CHILD ) While $hChild If _WinAPI_GetClassName( $hChild ) = $sClass Then $hFound = $hChild Return EndIf FindChildWindowByClass( $hChild, $hFound, $sClass ) $hChild = _WinAPI_GetWindow( $hChild, $GW_HWNDNEXT ) WEnd EndFunc Func WalkTreeWithAccessibleChildren( $pAcc, $iLevel, $iLevels = 0 ) If $iLevels And $iLevel = $iLevels Then Return ; Create object Local $oAcc = ObjCreateInterface( $pAcc, $sIID_IAccessible, $dtagIAccessible ) If Not IsObj( $oAcc ) Then Return $oAcc.AddRef() Local $iChildCount, $iReturnCount, $tVarChildren ; Get children If $oAcc.get_accChildCount( $iChildCount ) Or Not $iChildCount Then Return If AccessibleChildren( $pAcc, 0, $iChildCount, $tVarChildren, $iReturnCount ) Then Return ; Indentation Local $sIndent = "" For $i = 0 To $iLevel - 1 $sIndent &= " " Next Local $vt, $oChildObj, $iChildElem, $sName ; For each child For $i = 1 To $iReturnCount ; $tVarChildren is an array of VARIANTs with information about the children $vt = BitAND( DllStructGetData( $tVarChildren, $i, 1 ), 0xFFFF ) If $vt = $VT_DISPATCH Then ; Child object $pChildObj = DllStructGetData( $tVarChildren, $i, 3 ) $aAccObjects[$iAccObjects][0] = ObjCreateInterface( $pChildObj, $sIID_IAccessible, $dtagIAccessible ) If IsObj( $aAccObjects[$iAccObjects][0] ) Then ;PrintObjectInfo( $aAccObjects[$iAccObjects], $CHILDID_SELF, $sIndent ) $aAccObjects[$iAccObjects][0].get_accName( $CHILDID_SELF, $sName ) $aAccObjects[$iAccObjects][1] = $sName $aAccObjects[$iAccObjects][2] = $iLevel $iAccObjects += 1 WalkTreeWithAccessibleChildren( $pChildObj, $iLevel + 1, $iLevels ) EndIf Else ; $vt = $VT_I4 ; Child element $iChildElem = DllStructGetData( $tVarChildren, $i, 3 ) ;PrintObjectInfo( $oAcc, $iChildElem, $sIndent ) EndIf Next EndFunc Func PrintObjectInfo( $oAcc, $iChild, $sIndent ) Local $sName, $iRole, $sRole, $iRoleLen Local $iState, $sState, $iStateLen, $x, $y, $w, $h If $iChild <> $CHILDID_SELF Then _ ConsoleWrite( $sIndent & "$iChildElem = " & $iChild & @CRLF ) $oAcc.get_accName( $iChild, $sName ) ConsoleWrite( $sIndent & "Name = " & $sName & @CRLF ) EndFunc MSAccessibility.au3 #include-once ;#include "CUIAutomation2.au3" ;Global Const $S_OK = 0x00000000 Global Const $S_FALSE = 0x00000001 ;Global Const $E_NOTIMPL = 0x80004001 ;Global Const $E_NOINTERFACE = 0x80004002 ;Global Const $E_FAIL = 0x80004005 Global Const $DISP_E_MEMBERNOTFOUND = 0x80020003 ;Global Const $E_OUTOFMEMORY = 0x8007000E ;Global Const $E_INVALIDARG = 0x80070057 Global Const $VT_EMPTY = 0 Global Const $VT_I4 = 3 Global Const $VT_DISPATCH = 9 ;Global Const $tagVARIANT = "word vt;word r1;word r2;word r3;ptr data; ptr;" If @AutoItX64 Then Global $tagVARIANT = "dword[6];" ; Use this form to be able to build an Else ; array in function AccessibleChildren. Global $tagVARIANT = "dword[4];" EndIf ;Global Const $tIID_IAccessible = CLSIDFromString( $sIID_IAccessible ) ;Global Const $sIID_IServiceProvider = "{6D5140C1-7436-11CE-8034-00AA006009FA}" ;Global Const $tIID_IServiceProvider = CLSIDFromString( $sIID_IServiceProvider ) ;Global Const $dtagIServiceProvider = "QueryService hresult(struct*;struct*;ptr*);" ; ========= MS Active Accessibility constants ========= ; Child ID for the object itself ; (in contrast to simple child elements of the object) Global Const $CHILDID_SELF = 0 ; Navigation constants Global Const $NAVDIR_MIN = 0 Global Const $NAVDIR_UP = 0x1 Global Const $NAVDIR_DOWN = 0x2 Global Const $NAVDIR_LEFT = 0x3 Global Const $NAVDIR_RIGHT = 0x4 Global Const $NAVDIR_NEXT = 0x5 Global Const $NAVDIR_PREVIOUS = 0x6 Global Const $NAVDIR_FIRSTCHILD = 0x7 Global Const $NAVDIR_LASTCHILD = 0x8 Global Const $NAVDIR_MAX = 0x9 ; Selection flags Global Const $SELFLAG_NONE = 0 Global Const $SELFLAG_TAKEFOCUS = 0x1 Global Const $SELFLAG_TAKESELECTION = 0x2 Global Const $SELFLAG_EXTENDSELECTION = 0x4 Global Const $SELFLAG_ADDSELECTION = 0x8 Global Const $SELFLAG_REMOVESELECTION = 0x10 Global Const $SELFLAG_VALID = 0x1f ; Object identifiers ;Global Const $OBJID_WINDOW = 0x00000000 Global Const $OBJID_SYSMENU = 0xFFFFFFFF ;Global Const $OBJID_TITLEBAR = 0xFFFFFFFE Global Const $OBJID_MENU = 0xFFFFFFFD Global Const $OBJID_CLIENT = 0xFFFFFFFC Global Const $OBJID_VSCROLL = 0xFFFFFFFB Global Const $OBJID_HSCROLL = 0xFFFFFFFA ;Global Const $OBJID_SIZEGRIP = 0xFFFFFFF9 ;Global Const $OBJID_CARET = 0xFFFFFFF8 ;Global Const $OBJID_CURSOR = 0xFFFFFFF7 ;Global Const $OBJID_ALERT = 0xFFFFFFF6 ;Global Const $OBJID_SOUND = 0xFFFFFFF5 Global Const $OBJID_QUERYCLASSNAMEIDX = 0xFFFFFFF4 Global Const $OBJID_NATIVEOM = 0xFFFFFFF0 ; Object roles Global Const $ROLE_SYSTEM_TITLEBAR = 0x1 Global Const $ROLE_SYSTEM_MENUBAR = 0x2 Global Const $ROLE_SYSTEM_SCROLLBAR = 0x3 Global Const $ROLE_SYSTEM_GRIP = 0x4 Global Const $ROLE_SYSTEM_SOUND = 0x5 Global Const $ROLE_SYSTEM_CURSOR = 0x6 Global Const $ROLE_SYSTEM_CARET = 0x7 Global Const $ROLE_SYSTEM_ALERT = 0x8 Global Const $ROLE_SYSTEM_WINDOW = 0x9 Global Const $ROLE_SYSTEM_CLIENT = 0xa Global Const $ROLE_SYSTEM_MENUPOPUP = 0xb Global Const $ROLE_SYSTEM_MENUITEM = 0xc Global Const $ROLE_SYSTEM_TOOLTIP = 0xd Global Const $ROLE_SYSTEM_APPLICATION = 0xe Global Const $ROLE_SYSTEM_DOCUMENT = 0xf Global Const $ROLE_SYSTEM_PANE = 0x10 Global Const $ROLE_SYSTEM_CHART = 0x11 Global Const $ROLE_SYSTEM_DIALOG = 0x12 Global Const $ROLE_SYSTEM_BORDER = 0x13 Global Const $ROLE_SYSTEM_GROUPING = 0x14 Global Const $ROLE_SYSTEM_SEPARATOR = 0x15 Global Const $ROLE_SYSTEM_TOOLBAR = 0x16 Global Const $ROLE_SYSTEM_STATUSBAR = 0x17 Global Const $ROLE_SYSTEM_TABLE = 0x18 Global Const $ROLE_SYSTEM_COLUMNHEADER = 0x19 Global Const $ROLE_SYSTEM_ROWHEADER = 0x1a Global Const $ROLE_SYSTEM_COLUMN = 0x1b Global Const $ROLE_SYSTEM_ROW = 0x1c Global Const $ROLE_SYSTEM_CELL = 0x1d Global Const $ROLE_SYSTEM_LINK = 0x1e Global Const $ROLE_SYSTEM_HELPBALLOON = 0x1f Global Const $ROLE_SYSTEM_CHARACTER = 0x20 Global Const $ROLE_SYSTEM_LIST = 0x21 Global Const $ROLE_SYSTEM_LISTITEM = 0x22 Global Const $ROLE_SYSTEM_OUTLINE = 0x23 Global Const $ROLE_SYSTEM_OUTLINEITEM = 0x24 Global Const $ROLE_SYSTEM_PAGETAB = 0x25 Global Const $ROLE_SYSTEM_PROPERTYPAGE = 0x26 Global Const $ROLE_SYSTEM_INDICATOR = 0x27 Global Const $ROLE_SYSTEM_GRAPHIC = 0x28 Global Const $ROLE_SYSTEM_STATICTEXT = 0x29 Global Const $ROLE_SYSTEM_TEXT = 0x2a Global Const $ROLE_SYSTEM_PUSHBUTTON = 0x2b Global Const $ROLE_SYSTEM_CHECKBUTTON = 0x2c Global Const $ROLE_SYSTEM_RADIOBUTTON = 0x2d Global Const $ROLE_SYSTEM_COMBOBOX = 0x2e Global Const $ROLE_SYSTEM_DROPLIST = 0x2f Global Const $ROLE_SYSTEM_PROGRESSBAR = 0x30 Global Const $ROLE_SYSTEM_DIAL = 0x31 Global Const $ROLE_SYSTEM_HOTKEYFIELD = 0x32 Global Const $ROLE_SYSTEM_SLIDER = 0x33 Global Const $ROLE_SYSTEM_SPINBUTTON = 0x34 Global Const $ROLE_SYSTEM_DIAGRAM = 0x35 Global Const $ROLE_SYSTEM_ANIMATION = 0x36 Global Const $ROLE_SYSTEM_EQUATION = 0x37 Global Const $ROLE_SYSTEM_BUTTONDROPDOWN = 0x38 Global Const $ROLE_SYSTEM_BUTTONMENU = 0x39 Global Const $ROLE_SYSTEM_BUTTONDROPDOWNGRID = 0x3a Global Const $ROLE_SYSTEM_WHITESPACE = 0x3b Global Const $ROLE_SYSTEM_PAGETABLIST = 0x3c Global Const $ROLE_SYSTEM_CLOCK = 0x3d Global Const $ROLE_SYSTEM_SPLITBUTTON = 0x3e Global Const $ROLE_SYSTEM_IPADDRESS = 0x3f Global Const $ROLE_SYSTEM_OUTLINEBUTTON = 0x40 ; Object state constants Global Const $STATE_SYSTEM_NORMAL = 0 Global Const $STATE_SYSTEM_UNAVAILABLE = 0x1 Global Const $STATE_SYSTEM_SELECTED = 0x2 Global Const $STATE_SYSTEM_FOCUSED = 0x4 ;Global Const $STATE_SYSTEM_PRESSED = 0x8 Global Const $STATE_SYSTEM_CHECKED = 0x10 Global Const $STATE_SYSTEM_MIXED = 0x20 Global Const $STATE_SYSTEM_INDETERMINATE = $STATE_SYSTEM_MIXED Global Const $STATE_SYSTEM_READONLY = 0x40 Global Const $STATE_SYSTEM_HOTTRACKED = 0x80 Global Const $STATE_SYSTEM_DEFAULT = 0x100 Global Const $STATE_SYSTEM_EXPANDED = 0x200 Global Const $STATE_SYSTEM_COLLAPSED = 0x400 Global Const $STATE_SYSTEM_BUSY = 0x800 Global Const $STATE_SYSTEM_FLOATING = 0x1000 Global Const $STATE_SYSTEM_MARQUEED = 0x2000 Global Const $STATE_SYSTEM_ANIMATED = 0x4000 ;Global Const $STATE_SYSTEM_INVISIBLE = 0x8000 Global Const $STATE_SYSTEM_OFFSCREEN = 0x10000 Global Const $STATE_SYSTEM_SIZEABLE = 0x20000 Global Const $STATE_SYSTEM_MOVEABLE = 0x40000 Global Const $STATE_SYSTEM_SELFVOICING = 0x80000 Global Const $STATE_SYSTEM_FOCUSABLE = 0x100000 Global Const $STATE_SYSTEM_SELECTABLE = 0x200000 Global Const $STATE_SYSTEM_LINKED = 0x400000 Global Const $STATE_SYSTEM_TRAVERSED = 0x800000 Global Const $STATE_SYSTEM_MULTISELECTABLE = 0x1000000 Global Const $STATE_SYSTEM_EXTSELECTABLE = 0x2000000 Global Const $STATE_SYSTEM_ALERT_LOW = 0x4000000 Global Const $STATE_SYSTEM_ALERT_MEDIUM = 0x8000000 Global Const $STATE_SYSTEM_ALERT_HIGH = 0x10000000 Global Const $STATE_SYSTEM_PROTECTED = 0x20000000 Global Const $STATE_SYSTEM_HASPOPUP = 0x40000000 Global Const $STATE_SYSTEM_VALID = 0x7fffffff ; Event constants ;#include "APIConstants.au3" ; AutoIt 3.3.8.0+ #include <APISysConstants.au3> ; AutoIt 3.3.10.0+ #cs Global Const $EVENT_MIN = 0x00000001 Global Const $EVENT_SYSTEM_SOUND = 0x00000001 Global Const $EVENT_SYSTEM_ALERT = 0x00000002 Global Const $EVENT_SYSTEM_FOREGROUND = 0x00000003 Global Const $EVENT_SYSTEM_MENUSTART = 0x00000004 Global Const $EVENT_SYSTEM_MENUEND = 0x00000005 Global Const $EVENT_SYSTEM_MENUPOPUPSTART = 0x00000006 Global Const $EVENT_SYSTEM_MENUPOPUPEND = 0x00000007 Global Const $EVENT_SYSTEM_CAPTURESTART = 0x00000008 Global Const $EVENT_SYSTEM_CAPTUREEND = 0x00000009 Global Const $EVENT_SYSTEM_MOVESIZESTART = 0x0000000A Global Const $EVENT_SYSTEM_MOVESIZEEND = 0x0000000B Global Const $EVENT_SYSTEM_CONTEXTHELPSTART = 0x0000000C Global Const $EVENT_SYSTEM_CONTEXTHELPEND = 0x0000000D Global Const $EVENT_SYSTEM_DRAGDROPSTART = 0x0000000E Global Const $EVENT_SYSTEM_DRAGDROPEND = 0x0000000F Global Const $EVENT_SYSTEM_DIALOGSTART = 0x00000010 Global Const $EVENT_SYSTEM_DIALOGEND = 0x00000011 Global Const $EVENT_SYSTEM_SCROLLINGSTART = 0x00000012 Global Const $EVENT_SYSTEM_SCROLLINGEND = 0x00000013 Global Const $EVENT_SYSTEM_SWITCHSTART = 0x00000014 Global Const $EVENT_SYSTEM_SWITCHEND = 0x00000015 Global Const $EVENT_SYSTEM_MINIMIZESTART = 0x00000016 Global Const $EVENT_SYSTEM_MINIMIZEEND = 0x00000017 Global Const $EVENT_SYSTEM_DESKTOPSWITCH = 0x00000020 Global Const $EVENT_OBJECT_CREATE = 0x00008000 Global Const $EVENT_OBJECT_DESTROY = 0x00008001 Global Const $EVENT_OBJECT_SHOW = 0x00008002 Global Const $EVENT_OBJECT_HIDE = 0x00008003 Global Const $EVENT_OBJECT_REORDER = 0x00008004 Global Const $EVENT_OBJECT_FOCUS = 0x00008005 Global Const $EVENT_OBJECT_SELECTION = 0x00008006 Global Const $EVENT_OBJECT_SELECTIONADD = 0x00008007 Global Const $EVENT_OBJECT_SELECTIONREMOVE = 0x00008008 Global Const $EVENT_OBJECT_SELECTIONWITHIN = 0x00008009 Global Const $EVENT_OBJECT_STATECHANGE = 0x0000800A Global Const $EVENT_OBJECT_LOCATIONCHANGE = 0x0000800B Global Const $EVENT_OBJECT_NAMECHANGE = 0x0000800C Global Const $EVENT_OBJECT_DESCRIPTIONCHANGE = 0x0000800D Global Const $EVENT_OBJECT_VALUECHANGE = 0x0000800E Global Const $EVENT_OBJECT_PARENTCHANGE = 0x0000800F Global Const $EVENT_OBJECT_HELPCHANGE = 0x00008010 Global Const $EVENT_OBJECT_DEFACTIONCHANGE = 0x00008011 Global Const $EVENT_OBJECT_ACCELERATORCHANGE = 0x00008012 Global Const $EVENT_OBJECT_INVOKED = 0x00008013 Global Const $EVENT_OBJECT_TEXTSELECTIONCHANGED = 0x00008014 Global Const $EVENT_OBJECT_CONTENTSCROLLED = 0x00008015 Global Const $EVENT_MAX = 0x7FFFFFFF Global Const $WINEVENT_INCONTEXT = 0x04 Global Const $WINEVENT_OUTOFCONTEXT = 0x00 Global Const $WINEVENT_SKIPOWNPROCESS = 0x02 Global Const $WINEVENT_SKIPOWNTHREAD = 0x01 #ce ; ========= MS Active Accessibility interface ========= ; Copied from CUIAutomation2.au3 by junkew Global Const $sIID_IAccessible="{618736E0-3C3D-11CF-810C-00AA00389B71}" Global $dtagIAccessible = "GetTypeInfoCount hresult(uint*);" & _ ; IDispatch "GetTypeInfo hresult(uint;int;ptr*);" & _ "GetIDsOfNames hresult(struct*;wstr;uint;int;int);" & _ "Invoke hresult(int;struct*;int;word;ptr*;ptr*;ptr*;uint*);" & _ "get_accParent hresult(ptr*);" & _ ; IAccessible "get_accChildCount hresult(long*);" & _ "get_accChild hresult(variant;idispatch*);" & _ "get_accName hresult(variant;bstr*);" & _ "get_accValue hresult(variant;bstr*);" & _ "get_accDescription hresult(variant;bstr*);" & _ "get_accRole hresult(variant;variant*);" & _ "get_accState hresult(variant;variant*);" & _ "get_accHelp hresult(variant;bstr*);" & _ "get_accHelpTopic hresult(bstr*;variant;long*);" & _ "get_accKeyboardShortcut hresult(variant;bstr*);" & _ "get_accFocus hresult(struct*);" & _ "get_accSelection hresult(variant*);" & _ "get_accDefaultAction hresult(variant;bstr*);" & _ "accSelect hresult(long;variant);" & _ "accLocation hresult(long*;long*;long*;long*;variant);" & _ "accNavigate hresult(long;variant;variant*);" & _ "accHitTest hresult(long;long;variant*);" & _ "accDoDefaultAction hresult(variant);" & _ "put_accName hresult(variant;bstr);" & _ "put_accValue hresult(variant;bstr);" Global Const $tIID_IAccessible = CLSIDFromString( $sIID_IAccessible ) ; ===================================================== Global Const $hdllOleacc = DllOpen( "oleacc.dll" ) OnAutoItExitRegister( "ExitMSAccessibility" ) Func ExitMSAccessibility() DllClose( $hdllOleacc ) EndFunc Func AccessibleChildren( $paccContainer, $iChildStart, $iChildren, ByRef $tVarChildren, ByRef $iObtained ) Local $sVarArray = "" For $i = 1 To $iChildren $sVarArray &= $tagVARIANT Next $tVarChildren = DllStructCreate( $sVarArray ) Local $aRet = DllCall( "oleacc.dll", "int", "AccessibleChildren", "ptr", $paccContainer, "int", $iChildStart, "int", $iChildren, "struct*", $tVarChildren, "int*", 0 ) If @error Then Return SetError(1, 0, $S_FALSE) If $aRet[0] Then Return SetError(2, 0, $aRet[0]) $iObtained = $aRet[5] Return $S_OK EndFunc Func AccessibleObjectFromEvent( $hWnd, $iObjectID, $iChildID, ByRef $pAccessible, ByRef $tVarChild ) Local $tVARIANT = DllStructCreate( $tagVARIANT ) Local $aRet = DllCall( $hdllOleacc, "int", "AccessibleObjectFromEvent", "hwnd", $hWnd, "dword", $iObjectID, "dword", $iChildID, "ptr*", 0, "struct*", $tVARIANT ) If @error Then Return SetError(1, 0, $S_FALSE) If $aRet[0] Then Return SetError(2, 0, $aRet[0]) $pAccessible = $aRet[4] $tVarChild = $aRet[5] Return $S_OK EndFunc Func AccessibleObjectFromPoint( $x, $y, ByRef $pAccessible, ByRef $tVarChild ) Local $tPOINT = DllStructCreate( "long;long" ) DllStructSetData( $tPOINT, 1, $x ) DllStructSetData( $tPOINT, 2, $y ) Local $tPOINT64 = DllStructCreate( "int64", DllStructGetPtr( $tPOINT ) ) Local $tVARIANT = DllStructCreate( $tagVARIANT ) Local $aRet = DllCall( $hdllOleacc, "int", "AccessibleObjectFromPoint", "int64", DllStructGetData( $tPOINT64, 1 ), "ptr*", 0, "struct*", $tVARIANT ) If @error Then Return SetError(1, 0, $S_FALSE) If $aRet[0] Then Return SetError(2, 0, $aRet[0]) $pAccessible = $aRet[2] $tVarChild = $aRet[3] Return $S_OK EndFunc Func AccessibleObjectFromWindow( $hWnd, $iObjectID, $tRIID, ByRef $pObject ) Local $aRet = DllCall( $hdllOleacc, "int", "AccessibleObjectFromWindow", "hwnd", $hWnd, "dword", $iObjectID, "struct*", $tRIID, "int*", 0 ) If @error Then Return SetError(1, 0, $S_FALSE) If $aRet[0] Then Return SetError(2, 0, $aRet[0]) $pObject = $aRet[4] Return $S_OK EndFunc Func WindowFromAccessibleObject( $pAccessible, ByRef $hWnd ) Local $aRet = DllCall( $hdllOleacc, "int", "WindowFromAccessibleObject", "ptr", $pAccessible, "hwnd*", 0 ) If @error Then Return SetError(1, 0, $S_FALSE) If $aRet[0] Then Return SetError(2, 0, $aRet[0]) $hWnd = $aRet[2] Return $S_OK EndFunc Func GetRoleText( $iRole, $sRole, $iRoleMax ) Local $aRet = DllCall( $hdllOleacc, "uint", "GetRoleTextW", "dword", $iRole, "ptr", $sRole, "uint", $iRoleMax ) If @error Then Return SetError(1, 0, 0) If Not $aRet[0] Then Return SetError(2, 0, 0) Return $aRet[0] EndFunc Func GetStateText( $iStateBit, $sStateBit, $iStateBitMax ) Local $aRet = DllCall( $hdllOleacc, "uint", "GetStateTextW", "dword", $iStateBit, "ptr", $sStateBit, "uint", $iStateBitMax ) If @error Then Return SetError(1, 0, 0) If Not $aRet[0] Then Return SetError(2, 0, 0) Return $aRet[0] EndFunc ; Copied form WinAPISys.au3 ; Authors: KaFu, Yashied, Jpm Func SetWinEventHook($iEventMin, $iEventMax, $pEventProc, $iProcessID = 0, $iThreadID = 0, $iFlags = 0) Local $Ret = DllCall('user32.dll', 'handle', 'SetWinEventHook', 'uint', $iEventMin, 'uint', $iEventMax, 'ptr', 0, _ 'ptr', $pEventProc, 'dword', $iProcessID, 'dword', $iThreadID, 'uint', $iFlags) If @error Then Return SetError(@error, @extended, 0) Return $Ret[0] EndFunc ; Copied form WinAPISys.au3 ; Authors: KaFu, Yashied, Jpm Func UnhookWinEvent($hEventHook) Local $Ret = DllCall('user32.dll', 'bool', 'UnhookWinEvent', 'handle', $hEventHook) If @error Then Return SetError(@error, @extended, False) Return $Ret[0] EndFunc ; Copied form WinAPICom.au3 ; Authors: Yashied, Jpm Func CoTaskMemFree($pMemory) DllCall('ole32.dll', 'none', 'CoTaskMemFree', 'ptr', $pMemory) If @error Then Return SetError(@error, @extended, 0) Return 1 EndFunc ; Copied and slightly modified from AutoItObject.au3 by the AutoItObject-Team Func CLSIDFromString( $sIID ) Local $tCLSID = DllStructCreate( "dword;word;word;byte[8]" ) Local $aRet = DllCall( "ole32.dll", "long", "CLSIDFromString", "wstr", $sIID, "struct*", $tCLSID ) If @error Then Return SetError(1, @error, 0) If $aRet[0] <> 0 Then Return SetError(2, $aRet[0], 0) Return $tCLSID EndFunc Func PrintElementInfo( $oElement, $iChild, $sIndent ) Local $sName, $iRole, $sRole, $iRoleLen Local $iState, $sState, $iStateLen Local $sValue, $x, $y, $w, $h If $iChild <> $CHILDID_SELF Then _ ConsoleWrite( $sIndent & "$iChildElem = " & $iChild & @CRLF ) $oElement.get_accName( $iChild, $sName ) ConsoleWrite( $sIndent & "$sName = " & $sName & @CRLF ) If $oElement.get_accRole( $iChild, $iRole ) = $S_OK Then ConsoleWrite( $sIndent & "$iRole = 0x" & Hex( $iRole ) & @CRLF ) $iRoleLen = GetRoleText( $iRole, 0, 0 ) + 1 $sRole = DllStructCreate( "wchar[" & $iRoleLen & "]" ) GetRoleText( $iRole, DllStructGetPtr( $sRole ), $iRoleLen ) ConsoleWrite( $sIndent & "$sRole = " & DllStructGetData( $sRole, 1 ) & @CRLF ) EndIf If $oElement.get_accState( $iChild, $iState ) = $S_OK Then ConsoleWrite( $sIndent & "$iState = 0x" & Hex( $iState ) & @CRLF ) $iStateLen = GetStateText( $iState, 0, 0 ) + 1 $sState = DllStructCreate( "wchar[" & $iStateLen & "]" ) GetStateText( $iState, DllStructGetPtr( $sState ), $iStateLen ) ConsoleWrite( $sIndent & "$sState = " & DllStructGetData( $sState, 1 ) & @CRLF ) EndIf If $oElement.get_accValue( $iChild, $sValue ) = $S_OK Then _ ConsoleWrite( $sIndent & "$sValue = " & $sValue & @CRLF ) IF $oElement.accLocation( $x, $y, $w, $h, $iChild ) = $S_OK Then _ ConsoleWrite( $sIndent & "$x, $y, $w, $h = " & $x & ", " & $y & ", " & $w & ", " & $h & @CRLF ) ConsoleWrite( @CRLF ) EndFunc All code is included in the zip: IETabs.7z1 point
-
UPDATE: With the addition of the ObjCreateInterface function and enhanced COM functionality by trancexxx, these interfaces are now accessible directly in AutoIt. I've rewritten the plugin as a native UDF which will work when compiled as x64 as well. I've attached the new UDF as well as updated plugin and UDF versions of my OSD Volume script. UDF Example: #include <_AudioEndpointVolume.au3> ; ## Get current volume levels $vol = _GetMasterVolumeLevel() ConsoleWrite("Get Vol Error: " & @error & @CRLF) ConsoleWrite("Volume: " & $vol & " (decibels)" & @CRLF) $vol = _GetMasterVolumeLevelScalar() ConsoleWrite("Get Vol Error: " & @error & @CRLF) ConsoleWrite("Volume: " & $vol & " (scalar)" & @CRLF) ; ## Set new volume levels ConsoleWrite("Set vol to -20db..." & @CRLF) _SetMasterVolumeLevel(-20) ConsoleWrite("Set Vol Error: " & @error & @CRLF) $vol = _GetMasterVolumeLevel() ConsoleWrite("Get Vol Error: " & @error & @CRLF) ConsoleWrite("Volume: " & $vol & " (decibels)" & @CRLF) ConsoleWrite("Set vol to scalar 30..." & @CRLF) _SetMasterVolumeLevelScalar(30) ConsoleWrite("Set Vol Error: " & @error & @CRLF) $vol = _GetMasterVolumeLevelScalar() ConsoleWrite("Get Vol Error: " & @error & @CRLF) ConsoleWrite("Volume: " & $vol & " (scalar)" & @CRLF) ; ## Get volume range information ConsoleWrite("Get range info..." & @CRLF) $aInfo = _GetVolumeRange() ConsoleWrite("Get Range Error: " & @error & @CRLF) ConsoleWrite("MinDB: " & $aInfo[0] & @CRLF) ConsoleWrite("MaxDB: " & $aInfo[1] & @CRLF) ConsoleWrite("Increment: " & $aInfo[2] & @CRLF) ; ## Set mute states ConsoleWrite("Set mute on..." & @CRLF) _SetMute(1) ConsoleWrite("Set Mute Error: " & @error & @CRLF) $mute = _GetMute() ConsoleWrite("Get Mute Error: " & @error & @CRLF) ConsoleWrite("Muted: " & $mute & @CRLF) Sleep(2000) ConsoleWrite("Set mute off..." & @CRLF) _SetMute(0) ConsoleWrite("Set Mute Error: " & @error & @CRLF) $mute = _GetMute() ConsoleWrite("Get Mute Error: " & @error & @CRLF) ConsoleWrite("Muted: " & $mute & @CRLF) ; ## Get volume step info ; ## Steps range from 0 to nStepCount - 1 ConsoleWrite("Get step info..." & @CRLF) $aInfo = _GetVolumeStepInfo() ConsoleWrite("Get Step Error: " & @error & @CRLF) ConsoleWrite("Current step: " & $aInfo[0] & @CRLF) ConsoleWrite("Total steps: 0 to " & $aInfo[1] - 1 & @CRLF) ConsoleWrite("Increase 5 steps..." & @CRLF) For $i = 1 To 5 _VolumeStepUp() Next $aInfo = _GetVolumeStepInfo() ConsoleWrite("Get Step Error: " & @error & @CRLF) ConsoleWrite("Current step: " & $aInfo[0] & @CRLF) ConsoleWrite("Decrease 2 steps..." & @CRLF) For $i = 1 To 2 _VolumeStepDown() Next $aInfo = _GetVolumeStepInfo() ConsoleWrite("Get Step Error: " & @error & @CRLF) ConsoleWrite("Current step: " & $aInfo[0] & @CRLF) OLD PLUGIN VERSION vista_vol_plugin.zip _AudioEndpointVolume.au3 VolumeOSD.zip VolumeOSD_plugin.zip1 point
-
Barcode Scan Detection
p90x reacted to Theultrahead for a topic
I've had to deal with a similar issue where I work. I wrote a little script that listens for a HotKey that would be "typed" by the barcode scanner. The barcode scanner you have seems to be like mine in that it basically emulates keyboard entry, at least for 1D. The 1D scanner I have will only scan a barcode if it is 3 characters or longer, so I printed out a barcode that typed /// when scanned. My script, upon seeing /// being "typed", would activate the window I needed scan into. HotKeySet("/", "Command") While 1 Sleep(100) WEnd Func Command() WinActivate ("WindowToScanInto") ControlFocus ( "WindowToScanInto", "", CertainControlID ) ;Uncomment the above line if you need to activate a particular control. EndFunc1 point -
Barcode Scan Detection
p90x reacted to JLogan3o13 for a topic
@p90x welcome to the forum. Are these applications written in AutoIt? If so, how about posting the code? Otherwise, you're asking us to first guess at what you're trying to do and then help you troubleshoot. Help us help you1 point -
I've been working on a fancy ListView for user input. When a cell is clicked, a temporary Combo or Input control is created. The user does their part, then the temporary control's data is transferred to the ListView and the temporary control is deleted. I'm quite pleased with how it's turned out, except for one puzzling "feature". If I use "Switch GUIGetMsg()" in the main loop, then the first time a user clicks on the form causes a temp control to be both created and processed. That only occurs on the first click and not on any subsequent clicks. If I use "$msg = GUIGetMsg(1)" with a Switch command, it works properly on every click. See code below. I have no idea why this is. Does anyone else? I'll use GUIGetMsg(1) if I must, but I prefer my code to be as simple as possible. #include #include #include #include #include Global Const $_INCL = 1, $_REGEX = 2, $_FILTER = 3 Global $h_TempCtrl, $TempCtrlStatus[3] = [False, -1, -1], $_ListViewY = 1 Switch @OSVersion Case "WIN_2000", "WIN_XP", "WIN_XPe", "WIN_2003" $_ListViewY = 0 EndSwitch $h_GUI = GUICreate("Form1", 594, 329) $h_ListView = GUICtrlCreateListView("#|Include or Not|Filter Type|Contents ", 24, 24, 545, 279, $LVS_SINGLESEL) $hG_LVitem1 = GUICtrlCreateListViewItem("1.|Include|StringRegExp|", $h_ListView) $hG_LVitem2 = GUICtrlCreateListViewItem("2.|Include|StringRegExp|", $h_ListView) $hG_LVitem3 = GUICtrlCreateListViewItem("3.|Include|StringRegExp|", $h_ListView) GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") GUIRegisterMsg($WM_COMMAND, "WM_COMMAND") GUISetState(@SW_SHOW) While 1 Switch GUIGetMsg() ;~ $msg = GUIGetMsg(1) ;~ Switch $msg[0] Case $GUI_EVENT_CLOSE Exit Case $h_TempCtrl If $h_TempCtrl <> 0 Then _GUICtrlTemp_Apply("$h_TempCtrl") EndIf EndSwitch WEnd Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam) #forceref $hWnd, $iMsg, $wParam ; Catch ListView messages Local $hWndFrom, $iCode, $tNMHDR $tNMHDR = DllStructCreate($tagNMHDR, $lParam) $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom")) $iCode = DllStructGetData($tNMHDR, "Code") If $hWndFrom == GUICtrlGetHandle($h_ListView) And $iCode == $NM_CLICK Then _GUICtrlTemp_Create() Return $GUI_RUNDEFMSG EndFunc Func WM_COMMAND($hWnd, $iMsg, $iwParam, $ilParam) #forceref $hWnd, $iMsg ; Catch user input Local $hWndFrom, $iIDFrom, $iCode $hWndFrom = $ilParam $iIDFrom = BitAND($iwParam, 0xFFFF) $iCode = BitShift($iwParam, 16) If $TempCtrlStatus[0] Then If $hWndFrom == GUICtrlGetHandle($h_TempCtrl) Then Switch $iCode Case $CBN_SELENDOK _GUICtrlTemp_Apply("$CBN_SELENDOK") Case $CBN_SELENDCANCEL _GUICtrlTemp_Delete("$CBN_SELENDCANCEL") Case $EN_KILLFOCUS _GUICtrlTemp_Apply("$EN_KILLFOCUS") EndSwitch EndIf EndIf Return $GUI_RUNDEFMSG EndFunc Func _GUICtrlTemp_Create() ; Create a temporary control for user input Local $tempPos, $HitTest $HitTest = _GUICtrlListView_SubItemHitTest(GUICtrlGetHandle($h_ListView)) If $HitTest[0] <> -1 Then $TempCtrlStatus[0] = True $TempCtrlStatus[1] = $HitTest[0] $TempCtrlStatus[2] = $HitTest[1] Switch $HitTest[1] ; Global Const $_INCL = 1, $_REGEX = 2, $_FILTER = 3, $_FREQ = 4 Case $_INCL $tempPos = _GUICtrlListView_GetSubItemRect($h_ListView, $HitTest[0], $_INCL) $h_TempCtrl = GUICtrlCreateCombo("", $tempPos[0] + 24, $tempPos[1] + 24 + $_ListViewY, $tempPos[2] - $tempPos[0], $tempPos[3] - $tempPos[1], $CBS_DROPDOWNLIST) GUICtrlSetData($h_TempCtrl, "Include|Don't Include") GUICtrlSetState($h_TempCtrl, BitOR($GUI_FOCUS, $GUI_ONTOP)) _GUICtrlComboBox_ShowDropDown($h_TempCtrl, True) Case $_REGEX $tempPos = _GUICtrlListView_GetSubItemRect($h_ListView, $HitTest[0], $_REGEX) $h_TempCtrl = GUICtrlCreateCombo("", $tempPos[0] + 24, $tempPos[1] + 24 + $_ListViewY, $tempPos[2] - $tempPos[0], $tempPos[3] - $tempPos[1], $CBS_DROPDOWNLIST) GUICtrlSetData($h_TempCtrl, "String|StringRegExp") GUICtrlSetState($h_TempCtrl, BitOR($GUI_FOCUS, $GUI_ONTOP)) _GUICtrlComboBox_ShowDropDown($h_TempCtrl, True) Case $_FILTER $tempPos = _GUICtrlListView_GetSubItemRect($h_ListView, $HitTest[0], $_FILTER) Local $hRegion = _WinAPI_CreateRectRgn($tempPos[0] + 24, $tempPos[1] + 24 + $_ListViewY, $tempPos[2], $tempPos[3]) $h_TempCtrl = GUICtrlCreateInput(_GUICtrlListView_GetItemText($h_ListView, $HitTest[0], 3), $tempPos[0] + 24, $tempPos[1] + 24 + $_ListViewY, $tempPos[2] - $tempPos[0], $tempPos[3] - $tempPos[1]) GUICtrlSetState($h_TempCtrl, BitOR($GUI_FOCUS, $GUI_ONTOP, $GUI_SHOW)) _GUICtrlEdit_SetSel($h_TempCtrl, 0, -1) _WinAPI_RedrawWindow($h_GUI, 0, $hRegion, $RDW_UPDATENOW) ; It won't draw the control until mouse-out *** (WHY??) EndSwitch EndIf EndFunc Func _GUICtrlTemp_Apply( $caller ) ; Apply the temporary control's text to the ListView If $TempCtrlStatus[0] Then $TempCtrlStatus[0] = False _GUICtrlListView_SetItemText($h_ListView, $TempCtrlStatus[1], GUICtrlRead($h_TempCtrl), $TempCtrlStatus[2]) $TempCtrlStatus[1] = -1 $TempCtrlStatus[2] = -1 _GUICtrlTemp_Delete($caller & " -> Apply") EndIf EndFunc Func _GUICtrlTemp_Delete( $caller ) ConsoleWrite("Delete called by: " & $caller & @LF & "$h_TempCtrl: " & $h_TempCtrl & @LF & @SEC & ':' & @MSEC & @LF & @LF) ; Get rid of the temporary control GUICtrlDelete($h_TempCtrl) EndFunc1 point
-
Artisan, Thanks for that - I enjoyed the detective work! You need to set a placeholder value for $h_TempCtrl when you first declare it: Global $h_TempCtrl = 9999 ; Or any other unlikely number When a variable is undefined and used as a GUIGetMsg Case, it fires every time through the loop. So you always tested the Case $h_TempCtrl code as the value of $h_TempCtrl was undefined - AutoIt takes the undefined value as 0 which is the return of GUIGetMsg when the queue is empty. As a result this Case was being checked every few millisecs and as soon as you created the temporary control, the If $h_TempCtrl <> 0 condition was met and the _GUICtrlTemp_Apply function was run. It seems that the loop was so fast it actually used different values of the $h_TempCtrl within the same section of code - undefined to fire the Case and the correct ControlID for the If! I hope that explanation is clear - please ask again if not. M231 point