PDA

Click to See Complete Forum and Search --> : MDI-Child Forms


Aug 27th, 2000, 08:09 PM
Hi!

I'm having trouble to create a child form in an MDI form from a DLL. I've created an ACTIVE-X DLL in VB (6.0, SP4) with a form in it. When I set it's properties to MDI child I can't load it in the main project. I've then tried the Setparent function from the API, wich worked... BUT... When I maximize the "child" form it's "Title bar" won't go away. I'd like the "normal" Child behaviour, but I want the child forms to be included in DLL's in my project.

So far I've tried these 2 methods:

' --------------------------------------
' Method 1
' --------------------------------------

Private Declare Function SetParent Lib "user32" _
(ByVal hWndChild As Long, ByVal hWndNewParent As Long) As Long

Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" _
(ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long

Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" _
(ByVal hwnd As Long, ByVal nIndex As Long) As Long

Private Declare Sub SetWindowPos Lib "user32" _
(ByVal hwnd As Long, ByVal hWndInsertAfter As Long, _
ByVal X As Long, ByVal Y As Long, ByVal cx As Long, _
ByVal cy As Long, ByVal wFlags As Long)

Const WS_CHILD = &H40000000
Const GWL_STYLE = (-16)
Const GWL_HWNDPARENT = (-8)
Const SWP_NOZORDER = &H4
Const SWP_NOACTIVATE = &H10
Const SWP_SHOWWINDOW = &H40
Const HWND_TOP = 0&

Public Sub ShowWin(Wid As Long)

Dim OrigStyle As Long
Dim style As Long

Load frmDLLTest

OrigStyle = GetWindowLong(frmDLLTest.hwnd, GWL_STYLE) 'Get current window style
style = OrigStyle Or WS_CHILD 'Append "WS_CHILD" style to the hWnd window style
SetWindowLong frmDLLTest.hwnd, GWL_STYLE, style 'Add new style to window
SetParent frmDLLTest.hwnd, Wid 'Set form into parent window
SetWindowLong frmDLLTest.hwnd, GWL_HWNDPARENT, Wid 'have the hWnd Parent in hWnd's window struct.
SetWindowPos frmDLLTest.hwnd, HWND_TOP, 0&, 0&, 400, 400, SWP_NOZORDER Or SWP_NOACTIVATE Or SWP_SHOWWINDOW ' Show the Window

End Sub

' --------------------------------------
' Method 2
' --------------------------------------
Load frmDLLTest
frmDLLTest.Show
SetParent frmDLLTest.hwnd, Wid 'Set form into parent window

What do I do wrong? Please help!!!
__________________
Regards,

Rob

CGTS
Aug 28th, 2000, 12:00 AM
Basically the theory sounds fine........ but It cannot be done! I have tried many times before and it is frought with problems. I refer you to a magazine article in Visual Basic Programmers Journal Issue March 1999 Vol 9 No 3. It has a very lengthy article on this issue with a sound solution. (To detailed to print here) Try their WEB at http://www.vbpj.com The Locator ID for the articles code is VBPJ0399 unfortunately this is only the code and not the article text. I think if you are a Premier Member then you can access old magazine articles (I am not!).

Hope this NONE answer at least helps in some way.

damonous
Sep 17th, 2000, 10:18 AM
I know this is an older post, but I too had the same desire to create an MDI application with dynamic activex dll child forms. Microsoft has included a copy of the article in MSDN that CGTS talks about.

http://msdn.microsoft.com/library/periodic/period99/da0399.htm