Results 1 to 14 of 14

Thread: Stick/Dock 2 forms together

  1. #1

    Thread Starter
    New Member
    Join Date
    Jan 2000
    Location
    spore
    Posts
    3

    Post

    Hi, any1 know how to stick 2 forms together?
    kinda like how winamp & the equaliser stick together

  2. #2
    Lively Member
    Join Date
    Oct 2001
    Posts
    73

    well

    Did you ever figure this out? I've seen many links that do not link to the code they should.

    Try doing a search for WINAMP and forms.

    good luck

    j

  3. #3
    Lively Member
    Join Date
    Oct 2001
    Posts
    67

    Maybe help??

    I can move the forms together, this might help...

    Put this in the declarations section of the main form

    Function Mve(SIDE As String)
    Form2.Show

    If SIDE = "right" Then 'check what side
    Form2.Move Form1.Left + Form1.Width, Form1.Top 'move it

    ElseIf SIDE = "left" Then
    Form2.Move Form1.Left - Form2.Width, Form1.Top

    ElseIf SIDE = "top" Then
    Form2.Move Form1.Left, Form1.Top - Form2.Height

    ElseIf SIDE = "bottom" Then
    Form2.Move Form1.Left, Form1.Top + Form1.Height

    End If
    End Function


    Then just all that function Eg.

    command1_click()
    Mve("right")
    end sub

    Hope this helps
    AGB

  4. #4
    Registered User Nucleus's Avatar
    Join Date
    Apr 2001
    Location
    So that's what you are up to ;)
    Posts
    2,530
    I have done for work, so can't give away the code, but in essence you have to use subclassing, here is the windows proc to get you started, then combine it with the approach AGB provided. Can get tricky.

    Code in module:
    VB Code:
    1. Option Explicit
    2.  
    3. Private lHWndProc As Long
    4. Private lHWnd As Long
    5.  
    6. Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" _
    7. (ByVal hwnd As Long, ByVal nIndex As Long) As Long
    8.  
    9. Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" _
    10. (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
    11.  
    12. Private Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" _
    13. (ByVal lpPrevWndFunc As Long, ByVal hwnd As Long, _
    14. ByVal Msg As Long, _
    15. ByVal wParam As Long, ByVal lParam As Long) As Long
    16.  
    17. Private Declare Function CopyFromLParamToRect Lib "user32" Alias "CopyRect" (lpDestRect As RECT, ByVal lpSourceRect As Long) As Long
    18.  
    19. Type RECT
    20.   Left   As Long
    21.   Top    As Long
    22.   Right  As Long
    23.   Bottom As Long
    24. End Type
    25.  
    26. Dim r As RECT
    27.  
    28. Const GWL_WNDPROC = (-4)
    29. Const WM_MOVING = 534
    30. Const WM_ENTERSIZEMOVE = 561
    31. Const WM_EXITSIZEMOVE = 562
    32.  
    33. Public Sub HookForm(frmHandle As Long)
    34.     lHWnd = frmHandle
    35.     If lHWndProc = 0 Then
    36.         lHWndProc = GetWindowLong(lHWnd, GWL_WNDPROC) 'get handle of old window proc
    37.         SetWindowLong lHWnd, GWL_WNDPROC, AddressOf WndProc 'set to replacement wndproc
    38.     End If
    39. End Sub
    40.  
    41. Public Sub UnhookForm()
    42.     If lHWndProc Then
    43.         SetWindowLong lHWnd, GWL_WNDPROC, lHWndProc 'reset wnd proc to original
    44.         lHWndProc = 0
    45.     End If
    46. End Sub
    47.  
    48. Public Function WndProc(ByVal hwnd As Long, ByVal uMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    49.     Select Case uMsg
    50.         Case WM_ENTERSIZEMOVE
    51.             Debug.Print "form started to move"
    52.             'Put any code you want when form starts to move here
    53.             'Debug.Print "Position: "; Form1.Left / Screen.TwipsPerPixelX, Form1.Top / Screen.TwipsPerPixelY
    54.            
    55.         Case WM_MOVING
    56.             Debug.Print "Form moving..."
    57.             'Put any code you want while form is moving here
    58.             Call CopyFromLParamToRect(r, lParam)
    59.             'Debug.Print "Position: "; r.Left, r.Top
    60.            
    61.         Case WM_EXITSIZEMOVE
    62.             Debug.Print "Form stopped moving"
    63.             'Debug.Print "Position: "; Form1.Left / Screen.TwipsPerPixelX, Form1.Top / Screen.TwipsPerPixelY
    64.             'Put any code you want when form finishes moving here
    65.            
    66.     End Select
    67.     WndProc = CallWindowProc(lHWndProc, hwnd, uMsg, wParam, lParam)
    68. End Function
    Code in form:
    VB Code:
    1. Private Sub Form_Load()
    2. HookForm (Me.hwnd)
    3. End Sub
    Last edited by Nucleus; Nov 16th, 2001 at 10:03 PM.

  5. #5
    Member
    Join Date
    Dec 2001
    Posts
    38
    my way is easier than Nucleus way but works pretty cheap, but works =P

    i have a timer with interval of 10~20, and on each timer event, it checks to see if the form.top = form2.top and form.left+formwidth = form2.left, if not, then move it there.

    then i have 2 buttons which one will enable timer, and one to disable it, which will make it "dock and undock"

    you will notice a slight gap in between them if you move the form relatively fast, since the timer of 10, even 1 is not fast enough? though there is not much difference between 1 and 20, so i use 10~20.

  6. #6
    Addicted Member
    Join Date
    Sep 2001
    Posts
    152

    Exclamation For when it loads

    heres a beginner sort of code for when it loads up:

    dim form1L as integer
    dim form1H as integer
    dim form2H as integer
    dim i as integer

    form1.show
    form2.show

    form1H = form1.height
    form1L = form1.left

    form2H = form2.height


    i = form1H - form2H
    form2.left = form1L

    form2.Height = i

  7. #7
    Fanatic Member dongaman's Avatar
    Join Date
    Aug 2001
    Location
    xi'an
    Posts
    616
    Nucleus:
    Your code have a compile error in
    Code:
    SetWindowLong lHWnd, GWL_WNDPROC, AddressOf WndProc 'set to replacement wndproc
    It said "Invilad use of AddressOf operator".
    And i also met such problem when i use AddressOf operator.
    Can U explain this???
    I am just aman.

  8. #8
    Registered User Nucleus's Avatar
    Join Date
    Apr 2001
    Location
    So that's what you are up to ;)
    Posts
    2,530
    What version of VB are you using?

  9. #9
    Serge's Avatar
    Join Date
    Feb 1999
    Location
    Scottsdale, Arizona, USA
    Posts
    2,744
    In order for you to use SetWindowLong and the call back function API to subclass, it has to be (declared as Public) in a module.

  10. #10
    DaoK
    Guest
    AGB your code is great but the form2 have all the time the focus so it's not very usefull

  11. #11
    Registered User Nucleus's Avatar
    Join Date
    Apr 2001
    Location
    So that's what you are up to ;)
    Posts
    2,530
    Serge, are you sure, that code wortks fine on my box?

  12. #12
    Serge's Avatar
    Join Date
    Feb 1999
    Location
    Scottsdale, Arizona, USA
    Posts
    2,744
    Yes, I am sure.

    This is straight from MSDN

    Error: Invalid use of AddressOf operator

    The AddressOf operator modifies an argument to pass the address of a function rather than passing the result of the function call. This error has the following cause and solution:

    · You tried to use AddressOf with the name of a class method.

    Only the names of Visual Basic procedures in a .bas module can be modified with AddressOf. You can't specify a class method.

    · The procedure name modified by AddressOf is defined in a module in a different project.
    · You tried to modify the name a DLL function or a function defined in a type library with AddressOf.
    · DLL and type library functions can't be modified with AddressOf.

    The procedure definition must be in a module in the current project. Move the definition to a module in this project or include its current module in the project.

  13. #13
    Registered User Nucleus's Avatar
    Join Date
    Apr 2001
    Location
    So that's what you are up to ;)
    Posts
    2,530
    What I was getting at was that I don't think it has to be declared as public.

  14. #14
    Serge's Avatar
    Join Date
    Feb 1999
    Location
    Scottsdale, Arizona, USA
    Posts
    2,744
    No, it doesn't, if you create your own public function in the module that calls SetWindowLong.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width