Results 1 to 10 of 14

Thread: Rough Notes, and posts to be referenced from elsewhere, on VBA Windows API

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    9,455
    Rep Power
    10

    Rough Notes, and posts to be referenced from elsewhere, on VBA Windows API

    Rough Notes on VBA Windows API Introduction Part 1


    If, for now we restrict ourselves, to the subject area of Excel VBA Windows API, we can consider us to be talking most often about another, and/or similar to other ways, ( such as the so called External shared libraries ), to control or communicate with things outside of Excel, or even sometimes in Excel.
    More broadly speaking we are controlling or communicating with windows. (An existing window is often seen as based on a Class, and we are messing with the window/ manipulating the window, so what we are doing may sometimes be regarded as Sub Classing)

    Manipulating "Windows”.
    It would appear initially that the word “Windows” is a name for a programming idea which might result in something we “see” as what we conceive as Windows. But, a window is a vague concept. It includes what we see as windows and other things.
    Manipulating of the actual “Windows” seems the key to pseudo “making my own” Class or of a API Function or a Window thing from it
    Doing this in any language is a task for a computer genius, and in Visual Basic, (In particular Visual Basic for Applications), the documentation is very sparse. But “ API User 32 dll Programs” would appear to make this possible.
    It would appear that direct linked libraries (dll) are available to run as and when required, hence the wording of direct link: They are used as an efficient means to organise Microsoft’s software generally allowing different Applications to share smaller programs which are shipped as standard with the Microsoft Windows Operating system. They are however also available to programmers, programming the applications. Hence Application Programming Interface
    There are some similarities between a .dll file and a .exe file. The main difference is that we usually need to organise how and when it is used in Windows, hence I say Manipulating "Windows"

    API , “API Calls
    Such things get bundled up in an imprecise intimidating term API, for Application Programming Interface. They are usually contained in a Folder with a name similar to User 32.
    Another seemingly intimidating phrase is “API call”. You may hear the term “I am using API calls”. It just means usually that you are using those things and related “Windows” concept
    I have been told by some professionals that in actual fact these Library programs are organised in a similar way to the Libraries that one can pseudo Import by “checking a reference” in the list of available to VBA code libraries. However by some subtlety that they are not sure about they cannot be used in a code in the way of through declaring ( Dim ing ) them and then after assigning a variable using that variable to “get at” the various Methods / Functions inside them. Perhaps they are slightly more run time things, even though I have heard that the other Libraries are as well. Perhaps it can depend on the exact thing.
    When we are involved with VBA, it is difficult sometimes perhaps to distinguish between an end user and a professional programmer. The so called External shared libraries may be regarded as for the end user, whereas the API things could be regarded as intended for a programmer.
    In place of the normal declaring ( Dim ing ) that would be within a routine, in the case of the Library programs being used here, you must do a sort of initial globial type Declaration.

    Declareing Declare Type Functions
    You don’t always need the AliAs bit in these things. ( It just means _ this Lib "user32" _ Ali As ¬_ that _ (that is the Microsoft name , this is any name that I choose to use) ). Occasionally something can only be done to the AliAs where numbers and variable used to refer to things are concerned. It is subtle general point in computing that you might get problems when a number is used to refer to something that might take or give a number at some point. But you might need to do that, so having an intermediate word is a workaround for that so that the number is set to a word which is then related to a word that might be being referred to or returning a number.
    Function = Word
    Word = 873248
    So the Function can be referred to by a number indirectly, --- occasionally this may not be possible directly, --- Function =837547 might error for subtle computer reasons.

    It seems to do no harm to use an AliAs when you don’t need it and it helps to make a code prettier.

    Once Declared you can think of them to a first approximation as a function written in a code module in the Folder on your computer with the name something like “User32” or “User32dll” or similar. You then use them to a very crude approximation as you would any conventional function that you may have made and which is typically in a VBA code module, like pseudo
    _ x = SetWindowsHookExample( 3 , y , _..__… etc )
    x would need to be a variable declared at the top of the module I think, as would possibly be some of the signature line arguments in the Function, but note those arguments could also be a pseudo function, - pseudo as the address/ location of the function is given. (That function may, for example, be set off by something going on in a window at some point). The possibilities and construction of the signature line in a API Declare Function line are not as simply defined as in a standard VBA Function


    For use in a normal code you can use Private or Pubic. As in convectional VBA Functions Pubic will not confine the use of the function to the macro module in which it is in.
    For a class code module, such as a worksheet code module ( To get there, right click the worksheet's tab and select View Code ), these Declare type functions must be Private

    Owned “Windows”, and/ or z order.
    It is well above my knowledge to explain all concepts here, and as noted some things will have to be read as “on the tin” or in other words its faecile value.
    A Pop up is apparently always the one on top of to be seen ( “above on the screen “z axis” “ , - as a approximation the z axis is in the direction looking at it ) of the Window to which they belong and they always “belong”” to a parent window… well maybe something is not quite clear there…
    It is not always clear what “z option” does what, and even professionals sometimes seem to choose it from trial and error .
    But anyway these are two things that will need to be taken into the equation… or rather the “API calls” that we do..

    Hooking a “Window” to Handle it ..Computer Bollox terminology.
    I have needed to get some terms undefined correctly. Words like Handle and Hook are computer terms similar to the word Bollox in normal language and can be used alone or in conjunction with other words to have some meaning possibly in the context in which they are used but cannot have any precise meaning. Defining them as some computer bollox to do with handling and identifying Windows is a useful way to understand these terms.
    Some handle bollox will need to be taken into the equation… or rather the “API calls” that I do..
    Some published literature even supports my somewhat naive and critical resume, saying the words can mean a number of things. In our case the handle can be thought a number identifying a Window. A Hook can be thought of as hook or trip trap placed in some run or chain of events cause shuddering or jerking off of a procedure.


    Handleing
    When doing VBA Windows API coding, a "handle" seems to play a major role. It is an identification number / address/ pointer , or similar, which is required in much coding, as one might reasonably expect, in order that a coding knows which window or windows that we want to manipulate. One problem/s is that, although a window may have some known fixed name, this number is more often what is required in coding, and those numbers are not fixed, but rather are somehow generated and given each time to a software when it us running so that that software can access the windows, without us knowing any specific memory location/ address of things. Possibly that is done to make it more difficult to hack things . We are not privy to exactly how the numbers are generated, so we can consider them as random. ( Not all possible numbers are used, so it is possible that the same number is re used, but it is random chance if it is).
    To make things worse,
    _ getting the number seems to be not always reliable, and not all things that should do work.
    _ to get at most windows would require some sort of navigating of an explorer tree like structure.
    There are several API functions, that is to say Declareation Functions available to get the handle, and one or more may need to be used for a particular coding situation.
    So getting the handle/ using handle related Declareation Functions can be a good start point when learning VBA Windows
    Last edited by DocAElstein; 11-11-2024 at 01:05 PM.

Similar Threads

  1. Version Info using VBA and registry quirks
    By DocAElstein in forum Test Area
    Replies: 6
    Last Post: 10-23-2024, 01:50 PM
  2. ADS info via VBA 64bit
    By TML59 in forum Excel Help
    Replies: 9
    Last Post: 07-13-2024, 03:43 PM
  3. Replies: 26
    Last Post: 07-17-2013, 11:42 AM
  4. Info: different Value !
    By PcMax in forum Excel Help
    Replies: 2
    Last Post: 04-22-2012, 04:13 PM
  5. Version 2003 to 2007
    By PcMax in forum Excel Help
    Replies: 5
    Last Post: 11-23-2011, 07:52 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •