This is a new post 27, appearing after a copy of full page 2 gave me a full page 3. It is #post24900
It came from It was Taken from the Second copy from New post #16, 31 Oct 2024, all done on 31 Oct 2024
#post24891
API stuff tidily away in separate module
So far we have had all the 4 main coding sections in one code module. This helped to keep things fairly compact for the explanations, especially the code walk through which went neatly from the main sub down to the other two needed routines, then back to finish at the main sub.
It would also be Ok in a practical usage with a much larger main sub to do this, although then the main sub might be brought down to be the last, just for the sake of tidiness to keep most of the extra APIU stuff together at the top.
Another possibility would be to keep most of the API stuff in a separate module.
Doing this requires only 2 minor modifications.
_ The main sub will of course be removed to another code module
_ The only other modification is that the Called routine ,
Private Sub HangAHookToCatchAPIssinUserDLL_MsgBoxThenBringThat MsgBoxUp(ByRef RcelsToYou)
, will need to be made Public or else it cannot be Called from outside the module in which it is in
Public Sub HangAHookToCatchAPIssinUserDLL_MsgBoxThenBringThat MsgBoxUp(ByRef RcelsToYou)
The other things are only referenced from within the module, so they can be left Private, which is good practice to do so as to give better flexibility to naming other things outside the module
Since we have many comments and detailed explanations already, I will also remove the comments for clarity for this iteration of the coding development. As mentioned, the detailed commented codings are netter suited for the all in one code module, such as the module AlansInputBoxComnutsByRef
I will make a new code module, for the API stuff, called InpBxAPIddllWindowsSubClassing, and these will be the three coding sections in it
Code:
Option Explicit
Private Declare Function APIssinUserDLL_MsgBox Lib "user32" Alias "MessageBoxA" (Optional ByVal hWnd As Long, Optional ByVal Prompt As String, Optional ByVal Title As String, Optional ByVal Buts As Long) As Long
Private Declare Function SetWindowsHooksExample Lib "user32" Alias "SetWindowsHookExA" (ByVal Hooktype As Long, ByVal lokprocedureAddress As Long, Optional ByVal hmod As Long, Optional ByVal DaFredId As Long) As Long
Private hHookTrapCrapNumber As Long
Private Declare Function GetDaFredId Lib "kernel32" Alias "GetCurrentThreadId" () As Long
Private Declare Function UnHookWindowsHookCodEx Lib "user32" Alias "UnhookWindowsHookEx" (ByVal hHookTrapCrapNumber As Long) As Long
Private Declare Function SetWindowPosition Lib "user32" Alias "SetWindowPos" (ByVal hWnd As Long, ByVal zNumber As Long, ByVal CoedX As Long, ByVal CoedY As Long, ByVal xPiXel As Long, ByVal yPiYel As Long, ByVal wFlags As Long) As Long
Dim Booloks As Boolean
Dim GlobinalCntChopsLog As Long
'____________________________________________________________________________________
Public Sub HangAHookToCatchAPIssinUserDLL_MsgBoxThenBringThatMsgBoxUp(ByRef RcelsToYou)
Set RcelsToYou = Selection
Noughty:
Dim BookMarkClassTeachMeWind As Long: Let BookMarkClassTeachMeWind = 5
Let hHookTrapCrapNumber = SetWindowsHooksExample(BookMarkClassTeachMeWind, AddressOf WinSubWinCls_JerkBackOffHooKerd, 0, GetDaFredId)
Dim Valyou As Variant: Let Valyou = RcelsToYou.Value: If IsArray(Valyou) Then Valyou = Valyou(1, 1)
Dim Rpnce As Long
Let Rpnce = APIssinUserDLL_MsgBox(hWnd:=&H0, Prompt:="Yes, or No to ReCheck, Cancel for help ", Title:="Selection Check: Address is " & RcelsToYou.Address & " Value is """ & Valyou & """", Buts:=vbYesNoCancel)
Set RcelsToYou = Selection: Let Valyou = RcelsToYou.Value: If IsArray(Valyou) Then Valyou = Valyou(1, 1)
If Rpnce = 2 Then Application.Help HelpFile:=ThisWorkbook.Path & "\AnyFileName.chm", HelpContextID:=2
If Rpnce = 7 Then GoTo Noughty
End Sub
'___________________________________________________________________________________
Private Function WinSubWinCls_JerkBackOffHooKerd(ByVal lMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Let GlobinalCntChopsLog = GlobinalCntChopsLog + 1
If GlobinalCntChopsLog = 2 Then Let GlobinalCntChopsLog = GlobinalCntChopsLog - 1: UnHookWindowsHookCodEx hHookTrapCrapNumber: Exit Function
If lMsg = 5 Then Let Booloks = SetWindowPosition(wParam, 0, 10, 50, 400, 150, 40)
Let GlobinalCntChopsLog = GlobinalCntChopsLog - 1
End Function
In any code module requiring the pop up, these would be the required code lines
Code:
Dim RSel As Range ' This is a variable to hold the Pointer to the users range object.. So this variable in VBA is like the Link to the part of a URL string reducing size site where a few things about the actual Final site is informed about. This area in that site, like a pigeon Hole to which the variable refers, ( the "pigeon hole" location address, and all its contents would be defined as the "Pointer". Amongst other things it has a link, a "Pointing part", pointing to actually where all the stuff is
Call HangAHookToCatchAPIssinUserDLL_MsgBoxThenBringThatMsgBoxUp(RSel) ' In a normal application of the main Theme of all this, this would be the main code line you use to cause a the "Pop Up User pseudo InputBox with range selection alternative with API User 32 dll Programs"
Bookmarks