Simulation MDI

Hi does any body have some code that simulates mdi that works under NT4. I can set the parent of a form to a picture box of another form to simulate mdi but when I move the form within the picturebox there is an offset in the move message. The offset is the distance the simulated mdi form is from 0,0 so when i move the mdi form to the top left of the screen all's fine but as i move the mdi form to the bottom right corner things get worse & worse. I have got around the problem  by subclassing the form and hooking WM_MOVE, WM_MOVING, WM_EXITSIZEMOVE but I would like a better solution.

   
LVL 3
julianpointerAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
amebaConnect With a Mentor Commented:
Sample with only one child form (Form2).

' Form1: add button and picturebox, paste this code
Option Explicit
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 Const GWL_STYLE = (-16)
Private Const WS_POPUP = &H80000000

Private Sub Command1_Click()
    Dim m_oldstyle As Long
    Load Form2 ' load child form
    SetParent Form2.hwnd, Me.Picture1.hwnd
   
    m_oldstyle = GetWindowLong(Form2.hwnd, GWL_STYLE)
    Call SetWindowLong(Form2.hwnd, GWL_STYLE, (m_oldstyle Or WS_POPUP))
   
    Form2.Move 0, 0
    Form2.Show
End Sub

Private Sub Form_Unload(Cancel As Integer)
    Unload Form2  ' unload child form
End Sub
0
 
mcriderCommented:
What's wrong with just creating your program as a MDI??

Cheers!
0
 
VBGuruCommented:
what actually you are looking for. May be there is an alternative way to do the task.
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
VBGuruCommented:
I think what he expects is the scroll bars which comes in the mdi form when you move the form to the buttom of the mdi form
check out
http://vbaccelerator.com/codelib/ssubtmr/sbrclass.htm

it may be of use.
0
 
caraf_gCommented:
Ameba said it. It's the WS_POPUP that'll fix your problem for you.
0
 
amebaCommented:
or it was WS_CARAF_G_POSITION
SetParent Blues, 10 pts
http://oldlook.experts-exchange.com/bin/Q.10165031

' Here is code for child form - when focus goes to child form, main form title bar will change color to 'inactive' without this
' credits: vbpj
' Form2 code
Option Explicit
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Const WM_NCACTIVATE = &H86

Private Sub Form_Activate()
    Call SendMessage(Form1.hWnd, WM_NCACTIVATE, 1, ByVal 0&)
End Sub
0
 
caraf_gCommented:
:-)
0
 
julianpointerAuthor Commented:
Hi ameba,
    Everything works great.....
Can you post an answer so i can give you the points.
0
 
caraf_gCommented:
If you look at the "title bar" over ameba's comment you'll see that there's a hotlink for accepting the comment as an answer.
0
 
julianpointerAuthor Commented:
Thanks
0
 
amebaCommented:
Thanks.
Credits also to caraf_g for his contribution when making code this short (2 lines to modify one style bit).
0
 
julianpointerAuthor Commented:
How ca I add scrollbars to the picturebox ??
0
 
amebaCommented:
I think you can modify it's style bit, I'll try it later.
0
 
amebaCommented:
I tried and added scrollbars, but there is more - getting events, set/getscrollinfo ...

so it's easier to use 2 scrollbar controls and 2 pictureboxes, e.g.:
http://www.vb-helper.com/HowToInt.htm
Make a scrolled window (24K)

You'll need to add some calculation - whenever child form is moved/resized, scroll range must be set.
0
 
julianpointerAuthor Commented:
Whats the best place to find out when a child is moved.. There are many 100+ child forms ????
0
 
amebaCommented:
I hate subclassing, so I would try to avoid code to subclass and catch WM_MOVE/WM_SIZE messages.
Maybe using timer, 2 seconds interval, is not bad idea...
0
All Courses

From novice to tech pro — start learning today.