Results 1 to 12 of 12

Thread: prevent window movement in MDI

  1. #1

    Thread Starter
    Member
    Join Date
    Sep 2001
    Location
    Austin, TX
    Posts
    41

    Question prevent window movement in MDI

    I have a simple MDI application with a few children windows.

    That being said, how can I change the children windows in such a way that they are not moveable.

    I know I can do this at design time, but I want them initially to be moveable, and allow the user to "lock" and "unlock" the windows while the program is running...to keep windows from being moved accidentally.

    Any ideas?

  2. #2
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Set the Movable property of the child forms to False.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  3. #3

    Thread Starter
    Member
    Join Date
    Sep 2001
    Location
    Austin, TX
    Posts
    41
    HELLO!

    You can't set that property at run time.

  4. #4
    Frenzied Member MerrionComputin's Avatar
    Join Date
    Apr 2001
    Location
    Dublin, Ireland
    Posts
    1,616
    You have two options, both of which involve subclassing.
    Either:
    1 Intercept the WM_SIZING/WM_MOVING messages and set the parameters of the RECT structure pointed to by lParam to the location you want your form to be stuck at.

    2 Intercept the WM_NCHITTEST and always return HTCLIENT thus fooling Windows into thinking your form has no caption or borders that can be selected.

    The good news is that both of these are fairly straight forward if you use the EventVB.dll thus:

    Code:
     '\\ Form declarations 
    Dim WithEvents vbLink As EventVB.ApiFunctions
    Dim WithEvents vbWnd As EventVB.ApiWindow
    Dim bLocked As Boolean
    
     '\\ Start subclassing when form loads
    Private Sub Form_Load()
       
      Set vbLink = New EventVB.ApiFunctions
    
      Set vbWnd = New EventVB.ApiWindow
      vbWnd.hwnd = Me.hWnd
      vbLink.SubclassedWindows.Add vbWnd
    
    End Sub
    
     '\\ Stop subclassing when form unloads 
    Private Sub Form_Unload()
    
       vbLink.SubclassedWindows.Remove vbWnd
       Set vbWnd = Nothing
       Set vbLink = Nothing 
    
    End Sub
    
    '\\ Option 1 - prevent the WM_SIZING/WM_MOVING having any effect  
    Private Sub vbWnd_Sizing(ByVal SizeEdges As EventVB.WindowSizingEdges, DragRectangle As EventVB.APIRect)
    
    If blocked Then
        With DragRectangle
            .Left = vbWnd.RECT.Left
            .Right = vbWnd.RECT.Right
            .Top = vbWnd.RECT.Top
            .Bottom = vbWnd.RECT.Bottom
        End With
    End If
    
    End Sub
    
    Private Sub vbWnd_Moving(ByVal MoveEdges As EventVB.WindowSizingEdges, MoveRectangle As EventVB.APIRect)
    
    If blocked Then
        With MoveRectangle
            .Left = vbWnd.RECT.Left
            .Right = vbWnd.RECT.Right
            .Top = vbWnd.RECT.Top
            .Bottom = vbWnd.RECT.Bottom
        End With
    End If
    
    End Sub
    
    
     '\\ Option 2 - fool the hittest  
    Private Sub vbWnd_HitTest(ByVal x As Long, ByVal y As Long, ReturnValue As EventVB.enHitTestResult, Override As Boolean)
    
    If bLocked Then
        ReturnValue = HTCLIENT
        Override = True
    End If
    
    End Sub
    Hope this helps,
    Duncan
    ----8<---------------------------------------
    NEW - The .NET printer queue monitor component
    ----8<---------------------------------------
    Now with Examples of use

  5. #5
    Hyperactive Member
    Join Date
    Feb 2001
    Posts
    421
    First of all, don't get an attitude for no reason. Second, put this in a module..

    VB Code:
    1. Declare Function RemoveMenu Lib "user32" (ByVal hMenu As Long, ByVal nPosition As Long, ByVal wFlags As Long) As Long
    2. Declare Function GetSystemMenu Lib "user32" (ByVal hWnd As Long, ByVal bRevert As Long) As Long
    3. Declare Function DrawMenuBar Lib "user32" (ByVal hWnd As Long) As Long
    4.  
    5. Public Const MF_APPEND = &H100&
    6. Public Const MF_BYPOSITION = &H400&
    7.  
    8. Function bMenu(hWnd As Long, Position As Long, Enabled As Boolean)
    9.     Dim hSysMenu As Long
    10.    
    11.     If Enabled = True Then
    12.         hSysMenu = GetSystemMenu(hWnd&, MF_APPEND)
    13.         DrawMenuBar hSysMenu&
    14.     Else
    15.         hSysMenu = GetSystemMenu(hWnd&, 0&)
    16.         RemoveMenu hSysMenu&, Position, MF_BYPOSITION
    17.     End If
    18. End Function
    To stop your MDIForm from moving, use this code..

    VB Code:
    1. bMenu MDIForm1.hWnd, 1, False
    And to make it moveable again...

    VB Code:
    1. bMenu MDIForm1.hWnd, 1, True
    Last edited by Oafo; Jan 11th, 2002 at 04:53 PM.
    [vbcode]
    ' comment
    Rem remark
    [/vbcode]

  6. #6

    Thread Starter
    Member
    Join Date
    Sep 2001
    Location
    Austin, TX
    Posts
    41
    I was hoping to prevent movement of the CHILDREN within the MDI. I tried this code with the hWnd of a child window, and it was still able to be moved...

    any ideas?

  7. #7
    Hyperactive Member
    Join Date
    Feb 2001
    Posts
    421
    hmm, it worked for me. Lets say you wanted to make the Form called "frmChild" unmoveable, then your code would look like this in frmChild's code..

    VB Code:
    1. Private Sub Form_Load
    2.     bMenu Me.hWnd, 1, False
    3. End Sub

    Using the function I gave you earlier of course.
    [vbcode]
    ' comment
    Rem remark
    [/vbcode]

  8. #8
    Hyperactive Member
    Join Date
    Feb 2001
    Posts
    421
    Here's an example project if you couldn't get it to work still.
    Attached Files Attached Files
    [vbcode]
    ' comment
    Rem remark
    [/vbcode]

  9. #9

    Thread Starter
    Member
    Join Date
    Sep 2001
    Location
    Austin, TX
    Posts
    41
    I don't know whats goin on here.

    Your version works perfectly, but when I try the EXACT implementation on my MDI array, it doesn't prevent the window from moving! What could possibly be the problem?

  10. #10

    Thread Starter
    Member
    Join Date
    Sep 2001
    Location
    Austin, TX
    Posts
    41
    It will work for the PARENT form (The MDIForm), but none of the children. Could it be because they are Fixed Single (type 1) child windows?

  11. #11

    Thread Starter
    Member
    Join Date
    Sep 2001
    Location
    Austin, TX
    Posts
    41
    Sorry for all the posts in a row.

    I did some testing, and that code only works for "Sizeable Windows" and fails to prevent movement of "Fixed Single" windows!

    Any more ideas short of making them sizeable?

  12. #12
    Hyperactive Member
    Join Date
    Feb 2001
    Posts
    421
    Can you post up your project? I'll be able to tell what's wrong if you do that.
    [vbcode]
    ' comment
    Rem remark
    [/vbcode]

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