Solved

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

Posted on 2004-04-04
5
370 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 350 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

688 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