Jump to content

Utility to look up constants


qwert
 Share

Recommended Posts

 

A utility to look up constants in the Include files

 

Countless times in writing or debugging I’ve interrupted my train of thought to go look up the numeric value of a named constant ... or worse, had to figure out which include file reference is needed.

 

I finally got around to looking for a solution. (Actually, I’ve never understood why there hasn’t been some standard feature—in SciTE?— to do this. But I digress.) What I found was a pair of ready-to-use functions (from “Mat”) in the example files from 2009.

 

They are everything I envisioned for the “lookup side” of the problem, but they lacked a GUI for convenient use. Encouraged by the possibilities, I began to work with richedit, drag/drop and WM_COMMAND (thanks, Melba23!), and I've now put all the pieces together into a desktop utility. (Caution to coding purists: I sought a solution, here—not programming art ... so you’ll see some “quick fix” code ... even (aghast!) some straight-line coding. I’m always interested in readable code and function trumps form, for me—certainly at this moment.)

 

That said, I did add some touches using simple GUI methods: frameless ... draggable ... on top ... with some basic uses of transparency and parent drag. I wanted to stay away from GDI+. It’s great, but I’ve done enough at that level to really develop an appreciation for SIMPLE. Simple is so much easier to troubleshoot! But these forums are great sources of information for both levels. I’m continually amazed at what knowledge is embodied in the posts. Sometimes it takes a while—and some directional assistance—to ferret it out. But it’s there.

post-29172-0-63781400-1410814576_thumb.p

[screen image]

How to use the utility:

 

Easiest use: just drag the text string for the constant into the lower box and let it go.

(caveat: when dragging from SciTE, you MUST hold down the CTRL key to keep it from removing the text from your script—but more on that, below.)

Or, you can type (or paste/edit) the name of the constant into the upper box and then click Find.

Either way, the utility finds the occurrence (or occurrences) in the include files and shows the file(s), plus the numeric value for the constant.

 

The other main feature (as afforded by Mat’s second function) is to type in (or paste) a numeric value into the top field and click Find. The utility will display an array of all the include files that have a constant with that value.

 

A third use (which I took the liberty of modifying Mat’s functions to implement) is to look up references to include files that occur in the standard UDFs (those on the Include directory). As you might expect, “#i” is the trigger string for the lookup. For simplicity’s sake, only the first seven occurrences are listed. This feature is more a proof of concept than anything else, as it demonstrates how this simple utility might be expanded or adapted for other uses.

 

Technical note on the drag/drop from SciTE:

 

Let me be clear:

dragging a constant from the SciTE window to the Lookup Utility

 WITHOUT USING THE CTRL KEY REMOVES IT from the script.

Ctrl+Z is required to restore it. (Curiously, you can drag the same constant to WorkPad and it stays in SciTE.)

 

I toyed with ways to automatically issue that restore, but SciTE apparently doesn’t accept sent keystrokes. Nine different attempts yielded nothing, so I dropped the idea. Later, I found these two entries on Google Groups:

 

“In the simplest case, the target of a drag and drop action receives a copy of the data being dragged, and the source decides whether to delete the original. “

 

“There is no (SciTE) option. The code that controls this is in

/scintilla/gtk/ScintillaGTK.cxx ScintillaGTK::DragMotionThis where

preferredAction = GDK_ACTION_MOVE can be changed to GDK_ACTION_COPY.”

 

Link: https://groups.google.com/forum/#!topicsearchin/scite-interest/drag/scite-interest/2AZzHfnfFIQ

 

Apparently there’s at least the possibility of a solution.

 

 

Programming notes:

• Yes, the fonts are large. I trust I’m not the only one annoyed by tiny fonts on large screens. Anyone running a desktop setting of 125% or 150% with have to tune accordingly.

• The progress bar exists only to give some indication of action.

• The utility assumes you’re entering a findable name or number. Some minimal pre-check of the requested text would be worthwhile to avoid false runs.

• Also, it would appear to be an easy extension to add “F” (for Func) as a 3rd trigger to locate functions in UDFs. The top entry field is a little wider to accommodate this eventuality, given that some names are long. Another obvious possibility is to bring the searched directory to the forefront and make it selectable so any group of au3 files can be searched. Right now, only the standard and user include directories are looked at.

 

All that said, let me restate the main purpose:

Provides a convenient desktop utility that locates a constant name (or value) in the include files. Anything more is icing ... but never forget the two-layer cake of simplicity and convenience!

 

Well, that’s it, for now. Suggestions and advice are welcome; criticism, not so much!

Lookup.zip

IMPORTANT NOTE:

 

Be sure to adjust the path (Line 12) to your installed AutoIt3.EXE file.

It currently serves as the anchor point to locate the Include directory.

 

Examples:

C:Program Files (x86)AutoIt3AutoIt3.exe

C:AutoIt3AutoIt3.exe

Footnote:

Mat’s functions did require one change for a compiled version to operate correctly:  @AutoItExe >> $AutoItExe

(“@AutoItExe is the full path and filename of the AutoIt executable currently running. For compiled scripts it is the path of the compiled script; for .a3x and .au3 files it is the path of the interpreter running the file.”) The functions must know where the actual AutoIt3.exe actually is ... and hence, where the Include files are.

Edited by qwert
Link to comment
Share on other sites

Looks cool will come in handy I was thinking the other night about something to phase the include files and extract information, I had the idea of maybe something like the api viewer made in VB6, anyway nise little app

On Error Resume Pulling Hair Out.

Link to comment
Share on other sites

"No results were found for this name or value"

.

That's the correct response when you don't enter the leading "$" character.  It's trying to find it as a value and not as a named constant.

See the screen in Post #4 for the proper entry and result.

Link to comment
Share on other sites

Take a look at the path to your installed AutoIt3.exe and confirm that Includes is located there.  You'll have to adjust $AutoItEXE if it's not.

;===========================================================
;   Utility to look up constants ... with drag and drop feature!
;   by qwert ... 9/14/2014
;
#include <GUIConstantsEx.au3>
#include <GuiRichEdit.au3>
#include <GuiListView.au3>
#include <WindowsConstants.au3>
#include<array.au3>                         ;            IMPORTANT NOTE
#include <ButtonConstants.au3>              ;              |   |   |   |   |
$tColor = 0xDDE9E5                          ;              V   V   V   V   V
$AutoitEXE = "C:\AutoIt3\AutoIt3.exe"       ; <<< modify this if your copy is elsewhere <<<

.

That's what comes to mind because it happened to me in testing the compiled version ... which is why I added "Important Note".

 

Link to comment
Share on other sites

lulz, that's the issue.  C:Program Files (x86)AutoIt3Include

My two cents would be to add the $ if the user doesn't, and to check that path for existence and notify otherwise.

Edited by jaberwacky
Link to comment
Share on other sites

Both good points and I had one on my suggested improvements list:

• The utility assumes you’re entering a findable name or number. Some minimal pre-check of the requested text would be worthwhile to avoid false runs.

.

Glad to hear it's resolved for you.

Link to comment
Share on other sites

  • Moderators

qwert,

Could I suggest that rather than asking the user to set the AutoIt path:

$AutoitEXE = "C:\AutoIt3\AutoIt3.exe"           ; <<< modify this if your copy is elsewhere <<<
you check the location of the include folder automatically? :huh:

And of course there could well be other folders in which the user has placed include files - see the Adding UDFs to AutoIt and SciTE tutorial in the Wiki to see how it is done. ;)

In the UserCallTip utility I collect all the include paths like this (They are delimited with "|" because the result goes into a combo):

; Create Include folder list
Local $sInclude_Folders
; This returns a ";" delimited list of user created include folders
Local $sUser_Folder = RegRead("HKEY_CURRENT_USER\Software\AutoIt v3\AutoIt", "Include")
Local $aUser_Folder = StringSplit($sUser_Folder, ";")
For $i = 1 To $aUser_Folder[0]
    If $aUser_Folder[$i] <> "" Then
        $sInclude_Folders &= $aUser_Folder[$i] & "\|"
    EndIf
Next
; Now add the standard include folder
Local $sAutoIt_Path = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\AutoIt3.exe", "")
Local $sAutoIt_Folder = StringRegExpReplace($sAutoIt_Path, "(^.*\\)(.*)", "$1")
$sInclude_Folders &= $sAutoIt_Folder & "Include\"
Then you will always be sure to search on the correct paths. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Link to comment
Share on other sites

If you don't install it and use the the zip file, there are no registry settings to read, so searching just the registry will fail as well. You can also add in the SCITE_Home environment variable as a stop-gap check to find where SciTE is installed, and that might help get the correct folder for includes.

Edited by BrewManNH

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

  • Moderators

BrewManNH,

If you don't install it and use the the zip file...

If the user has chosen to do that then the user is presumably capable of choosing the correct paths for themselves - I am more interested in helping the inexperienced user who has no idea of what to add at that point. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Link to comment
Share on other sites

@Melba23, good suggestions.  I'll add to my TBD's. 

Mat's functions do take the time to look up any designated user include directory, so both paths are searched:

Local $aFolders = StringSplit (RegRead ("HKEY_CURRENT_USER\Software\AutoIt v3\AutoIt", "include"), ";"), $aRet[1][2]
      $aRet[0][0] = 0
      $aRet[0][1] = $sFind

I keep my "installed" AutoIt out in the open on C: so I can get to it easily.  But I suppose most people use Programs, so I'll add a reminder to the first post.

Thanks for the suggestions.

 

 

Link to comment
Share on other sites

The whole point is, not everyone installs AutoIt, and only showing one way limits this programs use, I was just adding to the discussion. :)

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

  • Moderators

BrewManNH,

Fair point. :)

qwert,

if you look at the UserCallTip utility code (it is in the SciTESciTEConfig folder) you will see I also added a "Browse" button so that people could set their own path if they wished - that way the utility caters for all situations. Feel free to use any of that code in your app. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Link to comment
Share on other sites

I follow what you're suggesting, but simply adding a browse for exe button will require the user to set the path each time they start the utility ... unless, of course, I add an INI file to support it.  I'll have to mull it over.

post-29172-0-63063800-1410884423_thumb.p

I guess I assumed that anyone interested in having this level of convenience would just compile it once and have an icon for it on their desktop.  I can confirm that it works pretty well that way.

However, a browse button would make perfect sense when more functions are added and you'd want to change where it looks for matches.

Thanks for the suggestions.

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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...