We help IT Professionals succeed at work.

Command Button Hwnd

eeyore7250
eeyore7250 asked
on
Can I, retrieve the hwnd reference for a command button on a form? If so, how?
Comment
Watch Question

Ryan ChongSoftware Tead Lead / Business Analyst / System Analyst / Data Engineer
CERTIFIED EXPERT

Commented:
<listening..>
as far as I knew you could only retrieve the hWnd property for forms and reports.  I'll check it out though...
as far as I knew you could only retrieve the hWnd property for forms and reports.  I'll check it out though...
ok, you can get the hwnd properties for the following objects in Access:
  Form
  Report

And the following objects from The Microsoft Common Controls Library (MSCOMCTL.OCX)
  ImageCombo
  ListView
  ProgressBar
  Slider
  StatusBar
  TabStrip
  ToolBar
  TreeView


any particular reason you need the hWnd for a command button?  Are you trying to subclass?
Jim Dettman (EE MVE)President / Owner
CERTIFIED EXPERT
Fellow
Most Valuable Expert 2017

Commented:
No you cannot. Controls in Access don't have a hWnd.  The standard controls in Access are unlike their VB counterparts.

Jim.

Author

Commented:
Fair enough.

So what you could do if you needed a seperate hWnd for a button is crate a subform the size of a button and embedd the button in this subform, and it would have a unique hWnd from it's parent?
Hello,

If you put this in a code module, then call the function like this:

Call fhWnd(me.ControlName)

This will return the Hwnd of the command button. This was taken from Dev Ashish's web site www.mvps.org/access. It is a great site to get advanced information on Access.

Thanks!

Joe

'----------------------------------------------------------
'Taken from Dev Ashish web site www.mvps.org/access
'
'When an Access control on a form receives the focus,
'it becomes a true window and it's possible to retrieve
'it's handle by using the GetFocus API.   Note that
'because Access controls do not behave like VB controls,
'there's not a whole lot that we can do with the hWnd.
'
'Joe Kendall 8/13/2001
'----------------------------------------------------------

Private Declare Function GetFocus Lib "user32" () As Long
         
Public Function fhWnd(ctl As Control) As Long
    On Error Resume Next
    ctl.SetFocus
    If Err Then
        fhWnd = 0
    Else
        fhWnd = GetFocus
    End If
    On Error GoTo 0
End Function
very cool....that's going in my code library.
Jim Dettman (EE MVE)President / Owner
CERTIFIED EXPERT
Fellow
Most Valuable Expert 2017

Commented:
That's news to me to.  Have always been told it can't be done.

Note the last comment though:

"Note that
'because Access controls do not behave like VB controls,
'there's not a whole lot that we can do with the hWnd.
"

  Which is probably no one has ever bothered to get it. So eeyore, what is it that your trying to do with this control?

Jim.