By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,146 Members | 1,738 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,146 IT Pros & Developers. It's quick & easy.

Access MDI

P: n/a
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
Nov 21 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
I don't believe it's possible. In fact, I don't believe you can do it with
any other type of form either.

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)

"Matthew Hood" <Dr***********@Yahoo.com> wrote in message
news:O0**************@TK2MSFTNGP09.phx.gbl...
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

Nov 21 '05 #2

P: n/a
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


"Douglas J. Steele" <NOSPAM_djsteele@NOSPAM_canada.com> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
I don't believe it's possible. In fact, I don't believe you can do it with
any other type of form either.

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)

"Matthew Hood" <Dr***********@Yahoo.com> wrote in message
news:O0**************@TK2MSFTNGP09.phx.gbl...
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


Nov 21 '05 #3

P: n/a
Very nicely executed. That's an interesting tidbit

<stored locally>

"Matthew Hood" <Dr***********@Yahoo.com> wrote in message
news:un*************@TK2MSFTNGP11.phx.gbl...
Never say it's impossible!
Got it figured out.

Nov 21 '05 #4

P: n/a
On Thu, 6 Jan 2005 13:38:31 -0800, "Matthew Hood"
<Dr***********@Yahoo.com> wrote:

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)
---
If you expect an answer to a personal mail, add the word "manfred" to the first 10 lines in the message
MW
Nov 21 '05 #5

P: n/a
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

--
@Alex (Alessandro Baraldi)
---------------------------------------------------------------------------
http://www.sitocomune.com/
http://www.mantuanet.it/alessandro.baraldi/
---------------------------------------------------------------------------
"Matthew Hood" <Dr***********@Yahoo.com> ha scritto nel messaggio
news:un*************@TK2MSFTNGP11.phx.gbl...
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


"Douglas J. Steele" <NOSPAM_djsteele@NOSPAM_canada.com> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
I don't believe it's possible. In fact, I don't believe you can do it withany other type of form either.

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)

"Matthew Hood" <Dr***********@Yahoo.com> wrote in message
news:O0**************@TK2MSFTNGP09.phx.gbl...
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



Nov 21 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.