|
-
Mar 23rd, 2002, 08:53 PM
#1
Thread Starter
Hyperactive Member
Me on top?
Is it true that you can't keep your own form on top with vbmodal?
I have just one form that I want to keep on top in Windows. Not in another Form. If it's true, what can I do to get around that?
I've been thinking about capturing mouseclicks in AND out the form than resetting your focus and doing the beep function. Does anyone have the code for this??? Or another idea to solve it?
Kind Regards,
Pieter
PS: If you found someone's answer helpful, please be so kind to rate that person.
Thanks.
-
Mar 24th, 2002, 06:36 AM
#2
I don't believe you need to be concerned with mouse clicks. Try this.
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 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()
SetTopMostWindow Me.hwnd, TRUE
'(SetTopMostWindow Me.hwnd, FALSE would prevent window from being TopMost)
End Sub
-
Mar 24th, 2002, 04:31 PM
#3
Thread Starter
Hyperactive Member
This doesn't seem to work...
Is it possible that this doesn't work?
I tried it but it didn't work!
Can somebody try it out for me pls?
Kind Regards,
Pieter
PS: If you found someone's answer helpful, please be so kind to rate that person.
Thanks.
-
Mar 24th, 2002, 04:48 PM
#4
Thread Starter
Hyperactive Member
Nope sorry
It works but the user still is able to browse and use the computer! Is there a way to lock every keypress and mousebutton press?
Kind Regards,
Pieter
PS: If you found someone's answer helpful, please be so kind to rate that person.
Thanks.
-
Mar 24th, 2002, 11:40 PM
#5
Addicted Member
OK! Try This:
Use these functions:
VB Code:
Declare Function BringWindowToTop Lib "user32.dll" (ByVal hwnd As Long) As Long
Declare Function GetForegroundWindow Lib "user32.dll" () As Long
BringWindowToTop will set your window as the topmost window.
GetForeGroundWindow returns the handle to the window that is on top.
Use these like this:
VB Code:
Sub ProgramLoop()
Do
If GetForegroundWindow() <> Form1.hWnd Then
BringWindowToTop(Form1.hWnd)
End If
DoEvents
Loop
End Sub
This will run a loop that will constantly check the top window, and if its not your window, it sets your wind as the top one.
As far as the mouse, you can use the GetCursorPos, and SetCursorPos API calls. Just say:
VB Code:
Type POINT_API
x as long
y as long
End Type
Dim point as POINT_API
Dim retval as long
retval = GetCursorPos(point)
If point.x < form1.left Then
point.x = Form1.Left
End If
If point.x > (form1.left + form1.width) Then
point.x = (form1.left + form1.widht)
End If
SetCursorPos(point.x, point.y)
This checks to see if the mouse is beyond your window and if it is, moves it back... you would have to do a similar check for point.y too.
This is one way you can do it. Info on the GetCursorPos and SetCursorPos can be found at www.vbapi.com ,
under reference.
Hope this helps.
To protect time is to protect everything...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|