Results 1 to 10 of 30

Thread: VBA Input Pop up Boxes: Application.InputBox Method versus VBA.InputBox Function

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #7
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    10,457
    Rep Power
    10
    Sub Classing Windows aka in English: One way to mess about and modify the underlying Windows processes within a VBA code to get extra and novel solutions

    “Second Part PROCmy hook procedure

    My Function HoldYaBackCalledYaBackClapTrap

    ( CBTProc callback secret god knows where function ( https://msdn.microsoft.com/en-us/lib...(v=vs.85).aspx ) )


    Summary how did we get here:
    It is difficult to separate the discussions into the main code and the Function which is the main Theme of this Post. Probably with hindsight an intermediate post is needed to talk about some hidden secret coding which links the two.. ( CBTProc callback secret god knows where claptrap ) but anyway….
    Lets say that at this point in time that the code discussed in the last post has been run to the point that the reasonably normal VBA code line _..
    APIssinUserDLL_MsgBox &H0, "Select Range", "MutsNuts AkaApi working ApplicationPromptToRangeInputBox", vbOKOnly
    _.. has just been passed / is in the process of being carried out.
    ( I admit that this code line is actually also an API thingy, but for the purposes of this discussion it can be taken as working very similarly to the normal conventional VBA MsgBox Function – most of its arguments are doing the same )
    But before that, a line has previously been done as was discussed in detail in the last post:
    hHookTrapCrapNumber = SetWindowsHooksExample(5, AddressOf HoldYaBackCalledYaBackClapTrap, 0, GetCurrentThreadId)

    The effect of that is / was a follows:
    In some predetermined set of instructions or planned chain of events, a “hook” or “marker” or “clap trap” or “page marker” or “trip trap” was made. This was given an identifying number which was returned by that “API Function” and it was chosen to be placed in the main code in a globial variable hHookTrapCrapNumber. I do not think that this number identifies the “page in the book” where the bookmarker is. I think it just is listed somewhere in a list of any active / set up book marks. I guess there might be / could be a few, so you need to distinguish them. It was also disgust that possibly the number refers to set instances of a Bookmark class: there may be a few , but they are all effectively connected / activated by the number hHookTrapCrapNumber existing in some register.
    The bookmarker has a particular type, ( 5 ). The type will be responsible for catching the Message box code line from the last post, ( APIssinUserDLL_MsgBox &H0, "Select Range", "MutsNuts AkaApi working ApplicationPromptToRangeInputBox", vbOKOnly ). That fires my hook procedure Function. Other things may also fire my hook procedure Function. They may or may not be themselves also related to the Popping up of my message Box.

    What can easily confuse is that we do not need that number in hHookTrapCrapNumber initially. The number refers to the book mark.
    When we have finished this Function code we will need it to take the Bookhook marker out.
    There is an API Function too do this:
    __UnHookWindowsHookCodEx hHookTrapCrapNumber
    That code line will be used in my function, so we need to have had to put it at the start of the code module in a global variable:
    Private hHookTrapCrapNumber As Long
    The effect of using the option 5 has been to effectively to have another program which we never see “made available “ ( it might be another dll User 32 one or some other one hidden god knows where on the computer). I think a good guess and explanation might be to say that this hidden code “sits” on the bookmark waiting to be run when the chain of events or book that the bookmark is in waggles/ shakes it into life. The hidden coding when it runs is somehow giving the information such that my written hook procedure Function must be written in such a way to recognise. part of what the hidden code does is to pseudo to write on the bookhook mark a number…. which…can be thought of as a number of a Window in this case… possibly… but I am not really convinced… maybe that is the number of a Window being opened.. There probably is another couple of numbers written on the bookmark:
    _The Address Of this “rat-trap-back-W_nd-rap-hold-back-call-back-holdhook roll back to my bollox” function HoldYaBackCalledYaBackClapTrap
    ( Address Of my hook procedure Function HoldYaBackCalledYaBackClapTrap )
    and
    _ the “address” of the CBTProc callback secret god knows where function
    No wonder no one knows what’s going on. I doubt I would if I was not a bit autistic. We never get to see the those number or numbers . There might be a API function code to get those, - but that will probably have to wait 10 years to find when I answer the API List thread. The fact that the function does get called is the proof I guess that the correct one was got by the
    SetWindowsHooksExample(5, AddressOf HoldYaBackCalledYaBackClapTrap, 0, GetCurrentThreadId)….
    In the last post it was suggested that the Microsoft CBTProc callback Function might be some sort of skeleton signature line place holding thing for the argumentstosend to my hook procedure Function HoldYaBackCalledYaBackClapTrap. Effectively it defines how my signature line must be written such that the data made available ( 3 Long numbers ) are in the predefined order so that I know which is which.

    One could say, as a chap Don I know did, “ The function you set up as the hook callback has to match the CBTProc specification (parameter names are not important, but order, type and number are)
    I think in the meantime I understand.
    _... The secretly held info of Long number Address Of HoldYaBackCalledYaBackClapTrap was already known. It served its purpose to “get us to” the signature line of the function
    Code:
    Private Function HoldYaBackCalledYaBackClapTrap(ByVal lMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long   '                                   ByVal CopyNumberFroNxtLvl As Long) As Long This bit wont work… The function you set up as the hook callback has to match the CBTProc specification (parameter names are not important, but order, type and number are)……
    “So Here” we are. We are Here:
    Function HoldYaBackCalledYaBackClapTrap

    I suspect now, at this moment in time, at the trigger / trip / stumble over the bookhookmark , we are “sent” to the function with information pertaining to the _...
    ___( _trip type detected ,
    _________ a number…. which…can be thought of as a number of a Window in this case ,
    ________________ a number god knows what but it ain’t important anyway. )
    _.. or maybe the “thing” cursor progression robot walking through the transverse multi plane simultaneous dimensioned computer memory is stumbling never ending as long as the bookhook mark is there, which it is as we have not taken it out yet, … but we will catch this one with our_........
    __If lMsg = 5 Then _...........
    ___( _ The system is about to activate a window. ,
    _________ a number…. which… in this case .. my MessageBoxA window ,
    ________________ maybe some info about a cat and /or mouse )

    The cursor progression robot had stumbled about 5 times or so before he tripped up on the one I wanted. My logs showed that. ( https://www.excelforum.com/developme...ml#post4829796 https://www.excelforum.com/developme...ml#post4831335 https://www.excelforum.com/developme...ml#post4831382 )
    I couldn’t get any satisfaction in understanding the logic of Functions of this nature which I found on searches. ( And those posts got deleted in some Witch hunt to ban me from that Forum anyway…. )

    I decided to start again on the Function from scratch.
    If the syntaxly correct arguments are passed, then the Function “starts” as any other.
    If I have any normal syntax errors then that does not seem to be picked up when I write the code.
    But if there are any then running the main code will cause Excel to crash once the function “starts”
    I played around a bit.
    The idea of the Function in this application is to position and size the window of a Message box.
    But starting from scratch. I just do this-..
    Code:
    Private Function HoldRapeAHookPro(ByVal lMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long    
    End Function ' HoldRapeAHookPro
    _.. and I get no error. The main code completes normally with a Message box. Further investigation suggests that the Function is done many times, but it proved difficult to measure how many- an attempt with variations of_...
    Let GlobinalCntChopsLog = GlobinalCntChopsLog + 1 : Debug.Print GlobinalCntChopsLog
    _... a very high number was suggested but the Immediate window seemed to go on printing more and more lines after completion of the code when anything was clicked on. Simply removing the Debug.Print and looking at the final value of GlobinalCntChopsLog yields a much smaller number. Possibly some strange mismatch in execution times and states. The Immediate window appears to effect the code.


    Various Published codes doing something similar API things, _...

    http://www.vbforums.com/showthread.p...3-but-not-2007
    https://www.techrepublic.com/blog/10...-applications/
    http://www.eileenslounge.com/viewtop...=28885#p223629
    https://stackoverflow.com/questions/...excel-vba-why/
    http://www.mrexcel.com/forum/excel-q...ox-method.html
    http://www.excely.com/excel-vba/defi...ssagebox.shtml
    https://www.excelforum.com/excel-pro...dll-stuff.html

    _... seemed to go into a strange recursion which seemed to have a stack limit of 30. Once again the details and Logs of those at the previous links have been deleted.

    I started to start from scratch having gained a small level of understanding in the process of preparing this and the referenced deleted Threads.

    So I start again in the next Post.
    Last edited by DocAElstein; 11-01-2024 at 06:07 PM.

Similar Threads

  1. How To React To The Cancel Button in a VB (not Application) InputBox
    By Rick Rothstein in forum Rick Rothstein's Corner
    Replies: 2
    Last Post: 02-04-2018, 01:48 AM
  2. Replies: 2
    Last Post: 02-12-2016, 04:32 PM
  3. InputBox OK and Cancel Button Problem
    By mackypogi in forum Excel Help
    Replies: 5
    Last Post: 05-30-2014, 12:20 AM
  4. VBA To Display Pop Up Alert When Duplicate Entry Is Made
    By peter renton in forum Excel Help
    Replies: 20
    Last Post: 07-26-2013, 07:56 PM
  5. Number validation in Text Boxes VBA
    By Admin in forum Excel and VBA Tips and Tricks
    Replies: 2
    Last Post: 05-17-2012, 02:48 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
  •