Access MDI

M

Matthew Hood

Here's a interesting question for the guru's out there.

I've created a VB.NET class library with a couple of forms that I have
successfully got to work from within MS Access using COM interop and VBA.
(Working, meaning it hasn't crashed on me yet... ;-). I

Would anybody know how to take this VB.NET Winform (using it's handle,
subclassing, or other means) and set it's parent to be the Access MDI client
area so that it will behave as if it's a window withing the Access
container?

TIA,
-Matt
 
D

Douglas J. Steele

I don't believe it's possible. In fact, I don't believe you can do it with
any other type of form either.
 
M

Matthew Hood

Never say it's impossible!
Got it figured out.

Here's the VBA module code I used.
All you have to do is pass the MoveWindowToAccessMDIClient your VB.NET
winform's handle. (Setting up the VB.NET application to be COM compatible of
course and using a wrapper class for the form....)
It works, but I haven't tested it extensively so there may be some quirks to
deal with.


'API Declarations
Private Declare Function SetParentAPI Lib "user32" Alias "SetParent" (ByVal
hWndChild As Long, ByVal hWndNewParent As Long) As Long
Private Declare Function GetWindowAPI Lib "user32" Alias "GetWindow" (ByVal
hWnd As Long, ByVal wCmd As Long) As Long
Private Declare Function GetClassNameAPI Lib "user32" Alias "GetClassNameA"
(ByVal hWnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long)
As Long

'API Constants
Private Const GW_CHILD As Long = 5
Private Const GW_HWNDNEXT As Long = 2
Private Const ACCESSMDICLIENTCLASSNAME As String = "MDIClient"

'Private Methods
Private Function pGetClassName(ByVal hWnd As Long) As String
'Returns the window class name.
On Error Resume Next
Dim sClassName As String
Dim lRet As Long

'Get the class name.
sClassName = Space$(255)
lRet = GetClassNameAPI(hWnd, sClassName, 255)
sClassName = Left(sClassName, lRet)

'Return the value.
pGetClassName = sClassName

End Function

Private Function pGetAccessMDIClientHwnd() As Long
'Returns MS Access's MDI Client window handle.
On Error Resume Next
Dim hWnd As Long

'Get the Access Application Handle
hWnd = GetWindowAPI(Access.hWndAccessApp, GW_CHILD)

Do
'If the window class name is "MDIClient" or the handle is 0, then
exit.
If (hWnd = 0) Or (pGetClassName(hWnd) = ACCESSMDICLIENTCLASSNAME)
Then Exit Do

'Get the next window.
hWnd = GetWindowAPI(hWnd, GW_HWNDNEXT)
Loop

'Return the value.
pGetAccessMDIClientHwnd = hWnd

End Function

'Public Methods
Public Function MoveWindowToAccessMDIClient(ByVal hWndChild As Long) As Long
'Moves the specified window to MS Access's MDI Client area.
On Error Resume Next

MoveWindowToAccessMDIClient = SetParentAPI(hWndChild,
pGetAccessMDIClientHwnd)

End Function
 
A

Andi Mayer

Private Function pGetAccessMDIClientHwnd() As Long
'Returns MS Access's MDI Client window handle.
On Error Resume Next
Dim hWnd As Long

'Get the Access Application Handle
hWnd = GetWindowAPI(Access.hWndAccessApp, GW_CHILD)

Do
'If the window class name is "MDIClient" or the handle is 0, then
exit.
If (hWnd = 0) Or (pGetClassName(hWnd) = ACCESSMDICLIENTCLASSNAME)
Then Exit Do

'Get the next window.
hWnd = GetWindowAPI(hWnd, GW_HWNDNEXT)
Loop

'Return the value.
pGetAccessMDIClientHwnd = hWnd

End Function

try pGetAccessMDIClientHwnd =
findWindowEx( Access.hWndAccessApp,0&,"MDIClient",vbnullstring)
 
A

ALESSANDRO Baraldi

May be:

Private Declare Function apiGetWindowLong Lib "User32" _
Alias "GetWindowLongA" _
(ByVal hWnd As Long, _
ByVal nIndex As Long) As Long

Private Const GWL_HINSTANCE = (-6)

pGetAccessMDIClientHwnd = apiGetWindowLong(Application.hWndAccessApp,
GWL_HINSTANCE)

Bye
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top