VBA, MS Access MS Access в примерах

hWnd контрола в форме MS Access (API)

' -------------------------------------------------------------------------------------------------/
' Module    : modGetControlHwnd_API
' Purpose   : Получение hWnd контрола в форме
' -------------------------------------------------------------------------------------------------/
#If VBA7 Then
    Private Declare PtrSafe Function GetFocusAPI Lib "user32" Alias "GetFocus" () As LongPtr
#Else
    Private Declare Function GetFocusAPI Lib "user32" Alias "GetFocus" () As Long
#End If

Public Function GetControlWnd(ctrl As Control) As Long
'Возвращает дескриптор контрола (HWND) - Window Hundle
' -------------------------------------------------------------------------------------------------/
On Error GoTo GetControlWnd_Err
   
    ctrl.SetFocus
    GetControlWnd = GetFocusAPI

GetControlWnd_Bye:
    Exit Function

GetControlWnd_Err:
    GetControlWnd = 0
    MsgBox "Ошибка " & Err.Number & vbCrLf & Err.Description & vbCrLf & _
        "в процедуре: GetControlWnd", vbCritical, "Error in module modGetControlWnd_API"
    Resume GetControlWnd_Bye
End Function

Назад ToTop
L.E. 24.10.2023
Рейтинг@Mail.ru