VB Code:
Private Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long Private Declare Function ClipCursor Lib "user32" (lpRect As Any) As Long Private Declare Function GetWindowRect Lib "user32.dll" (ByVal hwnd As Long, lpRect As RECT) As Long Private Declare Function GetDesktopWindow Lib "user32.dll" () As Long Type RECT left As Long top As Long right As Long bottom As Long End Type Private Const SWP_NOMOVE = 2 Private Const SWP_NOSIZE = 1 Private Const FLAGS = SWP_NOMOVE Or SWP_NOSIZE Private Const HWND_TOPMOST = -1 Private Const HWND_NOTOPMOST = -2 Private Function SetTopMostWindow(hwnd As Long, Topmost As Boolean) As Long On Error Goto ErrRtn If (Topmost) Then SetTopMostWindow = SetWindowPos(hwnd, HWND_TOPMOST, 0, 0, 0, 0, FLAGS) Else SetTopMostWindow = SetWindowPos(hwnd, HWND_NOTOPMOST, 0, 0, 0, 0, FLAGS) SetTopMostWindow = False End If Exit Function ErrRtn: MsgBox "Error in SetTopMostWindow " & Err & " " & Error, vbExclamation + vbOKCancel End Function Private Sub Form_Load() Dim r As RECT Dim retval As Long 'To make a form always on top SetTopMostWindow Me.hwnd, TRUE '(SetTopMostWindow Me.hwnd, FALSE would prevent window from being TopMost) 'To prevent any action on any other window, confine the mouse to the topmost form, using this retval = GetWindowRect(Form1.hwnd, r) retval = ClipCursor(r) End Sub




Reply With Quote