I'm sure this is dead easy IF youv've been there before. Anyway my
question.
Is there an API that would allow me to retrieve an object pointer based on a
windows handle. Basically, I'm trying to use the SetWindowLong with the
WM_USERDATA parameter in order to use the CopyMemory API to 'find' an
object. Using the built in vb ObjPtr function, I can do it all hunky-dory
(because I of course know what the object is in this scenario). However, in
my app, I use the SetCapture and WindowFromPoint API's and need to get
object pointers based on window handles (of where the mouse happens to be
hovering). I hope I've been clear.
So, who out there has done this type of frig??
TIA
Jimi
Windows do not contain "objects" or "object handles" as we commonly understand
those terms... What exactly are you trying to retrieve from the window handle?
--
~~~~~~~~~~~~~~~~~~~~~~~~~~~
Please post/reply to the newsgroup(s) so
that everyone can benefit from the discussion.
Klaus H. Probst, MCP
kpr...@altavista.net
ICQ: 22454937
The VB Box: http://members.xoom.com/kprobst/
~~~~~~~~~~~~~~~~~~~~~~~~~~~
James Tollan <jimibt_SPA...@dircon.co.uk> wrote in message
news:3768...@newsread3.dircon.co.uk...
I'm trying to retrieve the pointer in memory to the 'vb object' (not the
object itself, as I can get this using the RtlMoveMemory API after using
SetWindowLong with GWL_USERDATA). Basically, I'd like to be able to do the
following:
Public Const GWL_USERDATA = (-21)
' this is what I can do now:
Private Sub CanDoThisNow()
Dim lngPointer as Long
Dim lngHwnd as Long
Dim objVbobject as Object
Dim objCopy as Object
set objVbobject = objCustom ' this could be a control or a form etc...
lngPointer = ObjPtr(objVbobject)
' e.g lngPointer gives a value of 123456
lngHwnd = objVbobject.hWnd
' e.g lngHwnd gives a value of 987654
' set the hWnd up for userdata
Call SetWindowLong(lngHwnd, GWL_USERDATA, lngPointer)
set ObjCopy=GetMemoryObject(lngHwnd)
' bingo, no problem
End Sub
Public Function GetMemoryObject(ByVal plngOwnerHwnd As Long) As Object
Dim objTemp As Object
Dim lngPointer As Long
lngPointer = GetWindowLong(plngOwnerHwnd, GWL_USERDATA)
If lngPointer > 0 Then
CopyMemory objTemp, lngPointer, 4
Set GetMemoryObject = objTemp
CopyMemory objTemp, 0&, 4
Else
Set GetMemoryObject = Nothing
End If
End Function
' this is what I'd like to do:
Private Sub ThisIsPossible_I_WontBeBeaten()
Dim lngPointer as Long
Dim lngHwnd as Long
Dim objVbobject as Object
set objVbobject = objCustom
lngHwnd = objVbobject.hWnd
' e.g lngHwnd gives a value of 987654
' this is the 'Function' that I need to figure out
lngPointer = MemoryHandleOfObject_FromWindowHandle(lngHwnd)
' e.g lngPointer gives a value of 123456
' set the hWnd up for userdata
Call SetWindowLong(lngHwnd, GWL_USERDATA, lngPointer)
set ObjCopy=GetMemoryObject(lngHwnd)
' bingo, no problem
End Sub
Sorry if I wasn't very clear with my original post!! Do you know How I go
about getting this memory handle to an object based on it's hWnd???
Hoots mon the noo..
Jimi
Klaus H. Probst wrote in message <#pnjFJIu#GA.52@cppssbbsa03>...
Jim Deutch
MS Dev MVP
james.toll...@gmg.co.uk wrote in message
<3768c0fa$0$3...@news-reader.satin.net>...
I have looked for a way to do this for a long time. I have never found one.
Even if all you wanted was the IDispatch pointer to a window, you'd be hard
pressed to get it. However, there are some features in the new Active
Accessibility SDK that will be coming out in Windows 2000 as well as updates
for NT4 and 9x. Three in particular will interest you;
AccessibleObjectFromWindow, AccessibleObjectFromPoint and
AccessibleObjectFromEvent. Each of these can return several interfaces from
a given hWnd or event including IDispatch and IUnknown. The base Windows
GDI, USER and KERNEL services will be updated to support Active
Accessibility so most system windows and dialogs will support it. All other
applications will have to use the SDK and incorporate the new features. I
know this doesn't help much now, but it does give some hope for the future.
-Sebastian Odin Smith
How'about if the objects were all in the same process space (tho' compiled
in seperate dll's). This is really what my scenario is all about. My form
objects are in various dll's/ocx's. I'm trying to emulate a psuedo
drag'n'drop routine (my control has a dragbag!!, and a 'textcursor'
describing the contents of the dragged object which in turn has pointers to
various business objects which are common to all the dll's).
If I can get the object pointer (i.e the object which will recieve the drop)
based on the hWnd, then I'll be able to make it all happen as I need to.
As I mentioned in an earlier post, I can make it work by running a routine
that makes windows aware of any objects that are USERDATA 'ised, but this
takes away the totally generic nature of what I'm trying to achieve i.e
getting an object (via mem API's) based on it's hWnd.
Phew, enough of all of this, time to make some music..
Jimi
Jim Deutch <10313...@compuserve.com> wrote in message
news:eGmbeFOu#GA....@cppssbbsa02.microsoft.com...
> How'about if the objects were all in the same process space (tho' compiled
> in seperate dll's). This is really what my scenario is all about. My form
> objects are in various dll's/ocx's. I'm trying to emulate a psuedo
> drag'n'drop routine (my control has a dragbag!!, and a 'textcursor'
> describing the contents of the dragged object which in turn has pointers to
> various business objects which are common to all the dll's).
Jim's assertion is correct: Even if running in the same process space, the DLL
and your EXE are still separate processes.
I'll find an alternative way round it. Thanks for your responses.
Jimi
BTW As an aside, is there any way to temporarily 'block' events in an
application. Here's what I mean. If I have used SetCapture (and am
examining various hWnd's), can I prevent Microsoft Exchange notifications
interuptting my action?? This is just an aside an requires no comment
really, just curious!!
Klaus H. Probst wrote in message ...
>James,
[snip]
You know how frustrating this road has been!!! I think the sound of the new
functions does indeed hold a lot of promise. I'll keep my nose to the grind
stone (did I really say that!!)...
Cheers
Jimi
Sebastian Odin Smith <ssm...@itiweb.com> wrote in message
news:uKw5NHQu#GA....@cppssbbsa02.microsoft.com...