Solved

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

Posted on 2004-04-04
5
365 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
  • 2
  • 2
5 Comments
 
LVL 67

Expert Comment

by:sirbounty
Comment Utility
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 350 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
THANK YOU
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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…

771 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now