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
Printable View
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
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.
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.
Here's a sample. It keeps the form completely on the screen at all times...
VB Code:
'** In your form Option Explicit Private Sub Form_Load() Call Hook(Me.hwnd) End Sub Private Sub Form_Unload(Cancel As Integer) Call Unhook(Me.hwnd) End Sub '** In a standard module Option Explicit 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 Declare Function DefWindowProc Lib "user32" Alias "DefWindowProcA" (ByVal hwnd As Long, _ ByVal wMsg As Long, _ ByVal wParam As Long, _ ByVal lParam As Long) _ As Long Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, _ Source As Any, _ ByVal Length As Long) Private Const GWL_WNDPROC = (-4) Private Const WM_MOVING = &H216 Private Const WMSZ_LEFT = 1 Private Const WMSZ_RIGHT = 2 Private Const WMSZ_TOP = 3 Private Const WMSZ_TOPLEFT = 4 Private Const WMSZ_TOPRIGHT = 5 Private Const WMSZ_BOTTOM = 6 Private Const WMSZ_BOTTOMLEFT = 7 Private Const WMSZ_BOTTOMRIGHT = 8 Private Type RECT Left As Long Top As Long Right As Long Bottom As Long End Type Private mPrevProc As Long Public Sub Hook(ByVal hwnd As Long) mPrevProc = SetWindowLong(hwnd, GWL_WNDPROC, AddressOf WndProc) End Sub Public Sub Unhook(ByVal hwnd As Long) Call SetWindowLong(hwnd, GWL_WNDPROC, mPrevProc) mPrevProc = 0& End Sub Private Function PScreenWidth() As Long PScreenWidth = (Screen.Width \ 15) End Function Private Function PScreenHeight() As Long PScreenHeight = (Screen.Height \ 15) End Function Public Function WndProc(ByVal hwnd As Long, ByVal uMsg As Long, _ ByVal wParam As Long, ByVal lParam As Long) _ As Long On Error Resume Next Dim r As RECT Dim lTemp As Long If uMsg = WM_MOVING Then Call CopyMemory(r, ByVal lParam, Len(r)) If r.Left < 0 Then lTemp = r.Right - r.Left r.Left = 0 r.Right = lTemp End If If r.Right > PScreenWidth Then lTemp = r.Right - r.Left r.Right = PScreenWidth r.Left = r.Right - lTemp End If If r.Top < 0 Then lTemp = r.Bottom - r.Top r.Top = 0 r.Bottom = lTemp End If If r.Bottom > PScreenHeight Then lTemp = r.Bottom - r.Top r.Bottom = PScreenHeight r.Top = r.Bottom - lTemp End If Call CopyMemory(ByVal lParam, r, Len(r)) End If If mPrevProc& Then WndProc = CallWindowProc(mPrevProc, hwnd, uMsg, wParam, lParam) Else WndProc = DefWindowProc(hwnd, uMsg, wParam, lParam) End If End Function
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?
ica what do you mean by seeing all of it in development stage?
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.Quote:
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
thx