Results 1 to 9 of 9

Thread: not allow program to move off screen?

  1. #1

    Thread Starter
    Hyperactive Member FUBAR's Avatar
    Join Date
    Jan 2000
    Posts
    307

    not allow program to move off screen?

    in what event would i put code to check if the form is being moved off the desktop screen? i know how to code it once i figure out where to put it

    thanks

  2. #2
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649
    VB doesn't raise an event when a form is moved (unfortunatly). You'll need to subclass the Form and check for the WM_MOVE or WM_MOVING message.

  3. #3
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091
    I would go with WM_MOVING, personally. That way you can bound (or clip, or whatever the right word is) the window rect instead of moving it back and forth, which causes a lot of flickering.
    Laugh, and the world laughs with you. Cry, and you just water down your vodka.


    Take credit, not responsibility

  4. #4
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091
    Here's a sample. It keeps the form completely on the screen at all times...
    VB Code:
    1. '** In your form
    2. Option Explicit
    3.  
    4. Private Sub Form_Load()
    5.     Call Hook(Me.hwnd)
    6. End Sub
    7.  
    8. Private Sub Form_Unload(Cancel As Integer)
    9.     Call Unhook(Me.hwnd)
    10. End Sub
    11.  
    12.  
    13. '** In a standard module
    14. Option Explicit
    15.  
    16. Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, _
    17.                                                                             ByVal nIndex As Long, _
    18.                                                                             ByVal dwNewLong As Long) _
    19.                                                                             As Long
    20. Private Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, _
    21.                                                                               ByVal hwnd As Long, _
    22.                                                                               ByVal Msg As Long, _
    23.                                                                               ByVal wParam As Long, _
    24.                                                                               ByVal lParam As Long) _
    25.                                                                               As Long
    26. Private Declare Function DefWindowProc Lib "user32" Alias "DefWindowProcA" (ByVal hwnd As Long, _
    27.                                                                             ByVal wMsg As Long, _
    28.                                                                             ByVal wParam As Long, _
    29.                                                                             ByVal lParam As Long) _
    30.                                                                             As Long
    31. Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, _
    32.                                                                      Source As Any, _
    33.                                                                      ByVal Length As Long)
    34.  
    35. Private Const GWL_WNDPROC = (-4)
    36. Private Const WM_MOVING = &H216
    37.  
    38. Private Const WMSZ_LEFT = 1
    39. Private Const WMSZ_RIGHT = 2
    40. Private Const WMSZ_TOP = 3
    41. Private Const WMSZ_TOPLEFT = 4
    42. Private Const WMSZ_TOPRIGHT = 5
    43. Private Const WMSZ_BOTTOM = 6
    44. Private Const WMSZ_BOTTOMLEFT = 7
    45. Private Const WMSZ_BOTTOMRIGHT = 8
    46.  
    47. Private Type RECT
    48.     Left As Long
    49.     Top As Long
    50.     Right As Long
    51.     Bottom As Long
    52. End Type
    53.  
    54. Private mPrevProc As Long
    55.  
    56. Public Sub Hook(ByVal hwnd As Long)
    57.     mPrevProc = SetWindowLong(hwnd, GWL_WNDPROC, AddressOf WndProc)
    58. End Sub
    59.  
    60. Public Sub Unhook(ByVal hwnd As Long)
    61.    
    62.     Call SetWindowLong(hwnd, GWL_WNDPROC, mPrevProc)
    63.     mPrevProc = 0&
    64.    
    65. End Sub
    66.  
    67. Private Function PScreenWidth() As Long
    68.     PScreenWidth = (Screen.Width \ 15)
    69. End Function
    70.  
    71. Private Function PScreenHeight() As Long
    72.     PScreenHeight = (Screen.Height \ 15)
    73. End Function
    74.  
    75.  
    76. Public Function WndProc(ByVal hwnd As Long, ByVal uMsg As Long, _
    77.                         ByVal wParam As Long, ByVal lParam As Long) _
    78.                         As Long
    79. On Error Resume Next
    80.  
    81. Dim r As RECT
    82. Dim lTemp As Long
    83.  
    84.     If uMsg = WM_MOVING Then
    85.         Call CopyMemory(r, ByVal lParam, Len(r))
    86.        
    87.         If r.Left < 0 Then
    88.             lTemp = r.Right - r.Left
    89.             r.Left = 0
    90.             r.Right = lTemp
    91.         End If
    92.         If r.Right > PScreenWidth Then
    93.             lTemp = r.Right - r.Left
    94.             r.Right = PScreenWidth
    95.             r.Left = r.Right - lTemp
    96.         End If
    97.         If r.Top < 0 Then
    98.             lTemp = r.Bottom - r.Top
    99.             r.Top = 0
    100.             r.Bottom = lTemp
    101.         End If
    102.         If r.Bottom > PScreenHeight Then
    103.             lTemp = r.Bottom - r.Top
    104.             r.Bottom = PScreenHeight
    105.             r.Top = r.Bottom - lTemp
    106.         End If
    107.        
    108.         Call CopyMemory(ByVal lParam, r, Len(r))
    109.     End If
    110.  
    111.     If mPrevProc& Then
    112.         WndProc = CallWindowProc(mPrevProc, hwnd, uMsg, wParam, lParam)
    113.     Else
    114.         WndProc = DefWindowProc(hwnd, uMsg, wParam, lParam)
    115.     End If
    116.  
    117. End Function
    Laugh, and the world laughs with you. Cry, and you just water down your vodka.


    Take credit, not responsibility

  5. #5
    Member
    Join Date
    Apr 2003
    Location
    Australia
    Posts
    34

    Question similar

    I have a similar question...
    how do you manage to create a fullscreen form AND have your computer seeing all of it in the development stage?
    ------------------------------------------
    Private Sub Problem()
    If resolved.Value = True Then
    MsgBox "Resolved Query", vbInformation, "Resolved"
    End If
    End Sub
    ------------------------------------------
    Public Sub aspnow()
    Me.DoingASPNow = true
    End Sub
    ------------------------------------------

  6. #6

    Thread Starter
    Hyperactive Member FUBAR's Avatar
    Join Date
    Jan 2000
    Posts
    307
    ica what do you mean by seeing all of it in development stage?

  7. #7
    Frenzied Member <ABX's Avatar
    Join Date
    Jul 2002
    Location
    Canada eh...
    Posts
    1,622
    I think he means not having to use the sliders to see the form in the IDE. I think the only way to do this is to change ur computers resolution to a higher setting. MAKE SURE UR MONITOR CAN HANDLE IT
    Tips:
    • Google is your friend! Search before posting!
    • Name your thread appropriately... "I Need Help" doesn't cut it!
    • Always post your code!!!! We can't read your mind!!! (well, at least most of us!)
    • Allways Include the Name and Line of the Exception (if one is occuring!)
    • If it is relevant state the version of Visual Studio/.Net Framwork you are using (2002/2003/2005)


    If you think I was helpful, rate my post
    IRC Contact: Rizon/xous ChakraNET/xous Freenode/xous

  8. #8
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649
    Originally posted by <ABX
    I think he means not having to use the sliders to see the form in the IDE. I think the only way to do this is to change ur computers resolution to a higher setting. MAKE SURE UR MONITOR CAN HANDLE IT
    If this is what you mean you can set the "SDI Development Environment" option on the Advanced tab of the Tools > Options dialog box. You have to restart VB for this to take effect though.

  9. #9
    Member
    Join Date
    Apr 2003
    Location
    Australia
    Posts
    34

    thx

    thx
    ------------------------------------------
    Private Sub Problem()
    If resolved.Value = True Then
    MsgBox "Resolved Query", vbInformation, "Resolved"
    End If
    End Sub
    ------------------------------------------
    Public Sub aspnow()
    Me.DoingASPNow = true
    End Sub
    ------------------------------------------

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