JMongi
Active member
- Local time
- Today, 16:21
- Joined
- Jan 6, 2021
- Messages
- 802
I've reimplemented some code written by a variety of people smarter than me including some VBA that ties into Windows API calls. I'm not going to pretend to understand every nuance, but I do know that the structure of these API code blocks are different than defining functions and subs. Here's an example:
Then there are some functions defined afterward to help interface with this API code. My question is can I have more than one API call in a module? Something like this:
Code:
Option Compare Database
Option Explicit
#If VBA7 Then
Dim handleW1 As LongPtr
#Else
Dim handleW1 As Long
#End If
'###############################################
#If VBA7 Then 'PtrSafe
Private Declare PtrSafe Function FindWindowA Lib "user32" (ByVal lpClassName As String, ByVal lpWindowName As String) As LongPtr
Private Declare PtrSafe Function SetWindowPos Lib "user32" (ByVal handleW1 As LongPtr, ByVal handleW1InsertWhere As LongPtr, ByVal w As Long, _
ByVal X As Long, ByVal Y As Long, ByVal Z As Long, ByVal wFlags As Long) As Long
#Else '32-bit Office
Private Declare Function FindWindowA Lib "user32" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function SetWindowPos Lib "user32" (ByVal handleW1 As Long, ByVal handleW1InsertWhere As Long, ByVal w As Long, _
ByVal X As Long, ByVal Y As Long, ByVal z As Long, ByVal wFlags As Long) As Long
#End If
'###############################################
Const TOGGLE_HIDEWINDOW = &H80
Const TOGGLE_UNHIDEWINDOW = &H40
Public strProc As String 'used in error code
Public blnShowTaskbar As Boolean
Public blnShowNavPane As Boolean
Then there are some functions defined afterward to help interface with this API code. My question is can I have more than one API call in a module? Something like this:
Code:
Option Compare Database
Option Explicit
'-------------------ACCESS WINDOW VISIBILITY API START-------------------
'************ Code Start **********
' This code was originally written by Dev Ashish.
' It is not to be altered or distributed,
' except as part of an application.
' You are free to use it in any application,
' provided the copyright notice is left unchanged.
'
' Code Courtesy of Dev Ashish
'Additional API code by Daolix
'/* ShowWindow() Commands */
Global Const SW_HIDE = 0
Global Const SW_SHOWNORMAL = 1
Global Const SW_SHOWMINIMIZED = 2
Global Const SW_SHOWMAXIMIZED = 3
Global Const SW_SHOW = 5
Public blnShowWindow As Boolean
'###############################################
#If VBA7 Then
Declare PtrSafe Function ShowWindow Lib "user32" _
(ByVal hWnd As LongPtr, ByVal nCmdShow As Long) As Long
Declare PtrSafe Function GetWindowLong Lib "user32" Alias "GetWindowLongA" _
(ByVal hWnd As LongPtr, ByVal nIndex As Long) As Long
Declare PtrSafe Function SetWindowLong Lib "user32" Alias "SetWindowLongA" _
(ByVal hWnd As LongPtr, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Declare PtrSafe Function GetParent Lib "user32" _
(ByVal hWnd As LongPtr) As LongPtr
#Else '32-bit Office
Declare Function ShowWindow Lib "user32" _
(ByVal hWnd As Long, ByVal nCmdShow As Long) As Long
Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" _
(ByVal hWnd As Long, ByVal nIndex As Long) As Long
Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" _
(ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Declare Function GetParent Lib "user32" _
(ByVal hWnd As Long) As Long
#End If
'###############################################
'/* Window field offsets for Set/GetWindowLong() */
Public Const GWL_EXSTYLE As Long = -20
'/* Extended Window Styles */
Public Const WS_EX_APPWINDOW As Long = &H40000
'-------------------ACCESS WINDOW VISIBILITY API END------------------
'------------------ACCESS FORM MOVE WITH MOUSE DOWN API START------------------
Public Const WM_NCLBUTTONDOWN = &HA1
Public Const HT_CAPTION = &H2
'===========================================================
'Usage with form mouse down event e.g.
'Private Sub FormHeader_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
' X = ReleaseCapture()
' X = SendMessage(Me.HWnd, WM_NCLBUTTONDOWN, HT_CAPTION, 0)
'End Sub
'===========================================================
#If VBA7 Then
Public Declare PtrSafe Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As LongPtr, _
ByVal wMsg As Long, ByVal wParam As LongPtr, lParam As Any) As LongPtr
Public Declare PtrSafe Function ReleaseCapture Lib "user32.dll" () As Long
#Else
Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, _
ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Public Declare Function ReleaseCapture Lib "user32.dll" () As Long
#End If
'---------------------ACCESS FORM MOVE WITH MOUSE DOWN API END--------------------