?
Solved

Planting (Docking) a form in a form....

Posted on 2004-04-04
5
Medium Priority
?
371 Views
Last Modified: 2010-05-02
I want to plant or dock a form in another form, i want it to stick, and i want the option to make it so it doesnt need to stick.  can someone help me?  Thanks...
0
Comment
Question by:GBLX-Bill
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 67

Expert Comment

by:sirbounty
ID: 10752773
Sounds like you're looking for Multiple-Document Interface (MDI) Applications.
Read more abou it here:http://msdn.microsoft.com/library/en-us/vbcon/html/vbconmdiapplications.asp
0
 
LVL 17

Accepted Solution

by:
zzzzzooc earned 1400 total points
ID: 10753023
You can use (as mentioned) MDI or the method I proposed for your other question (SetParent). By "stick" do you mean to keep users from moving it? If so, you can subclass the form and ignore window-messages when the user tries to move the form from the title-bar.


Form1:
============

Private Declare Function SetParent Lib "user32" (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As Long
Private Sub Command1_Click()
    'Allow Form2 to be moved
    bAllowMove = True
End Sub
Private Sub Form_Load()
    Call Load(Form2)
    With Form2
        .Width = 700
        .Height = 700
        .Visible = True
    End With
    bAllowMove = False
    Call WindowHook(True, Form2.hWnd)
    Call SetParent(Form2.hWnd, Form1.hWnd)
End Sub
Private Sub Form_Unload(Cancel As Integer)
    Call WindowHook(False, Form2.hWnd)
    Call Unload(Form2)
End Sub


Module1:
===========

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 CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hWnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long

Private Const GWL_WNDPROC = (-4)
Private Const WM_NCLBUTTONDOWN = &HA1

Public lPrevProc As Long
Public bAllowMove As Boolean
Public Sub WindowHook(ByVal bHook As Boolean, lHandle As Long)
    If bHook = True Then
        lPrevProc = SetWindowLong(lHandle, GWL_WNDPROC, AddressOf WindowProc)
    Else
        Call SetWindowLong(lHandle, GWL_WNDPROC, lPrevProc)
    End If
End Sub
Public Function WindowProc(ByVal hWnd As Long, ByVal uMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    If uMsg = WM_NCLBUTTONDOWN Then
        'Ignore left-button down messages (when form is moved from titlebar)
        If bAllowMove = False Then Exit Function
    End If
    WindowProc = CallWindowProc(lPrevProc, hWnd, uMsg, wParam, lParam)
End Function
0
 

Author Comment

by:GBLX-Bill
ID: 10753041
No, actually mean to fix it on a form so people can't move it with out mvoing my form.
0
 
LVL 17

Expert Comment

by:zzzzzooc
ID: 10753107
Yes. Similar to the other question, it'll reside inside the form itself (you mentioned IN so I'm taking it you don't mean to dock it NEXT to the main form). The above example should prevent the "docked" form from moving (by titlebar) until you click on the button that changes bAllowMove  to true.
0
 

Author Comment

by:GBLX-Bill
ID: 10753274
THANK YOU
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month13 days, 11 hours left to enroll

800 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question