Results 1 to 5 of 5

Thread: Me on top?

  1. #1

    Thread Starter
    Hyperactive Member Petergotchi's Avatar
    Join Date
    Jan 2002
    Location
    Dendermonde - Belgium
    Posts
    267

    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.

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333
    I don't believe you need to be concerned with mouse clicks. Try this.
    VB Code:
    1. 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
    2.  
    3. Private Const SWP_NOMOVE = 2
    4. Private Const SWP_NOSIZE = 1
    5. Private Const FLAGS = SWP_NOMOVE Or SWP_NOSIZE
    6. Private Const HWND_TOPMOST = -1
    7. Private Const HWND_NOTOPMOST = -2
    8.  
    9. Private Function SetTopMostWindow(hwnd As Long, Topmost As Boolean) As Long
    10.   On Error Goto ErrRtn
    11.    If (Topmost) Then
    12.       SetTopMostWindow = SetWindowPos(hwnd, HWND_TOPMOST, 0, 0, 0, 0, FLAGS)
    13.    Else
    14.       SetTopMostWindow = SetWindowPos(hwnd, HWND_NOTOPMOST, 0, 0, 0, 0, FLAGS)
    15.       SetTopMostWindow = False
    16.    End If
    17.    Exit Function
    18. ErrRtn:
    19. MsgBox "Error in SetTopMostWindow " & Err & " " & Error, vbExclamation + vbOKCancel
    20. End Function
    21.  
    22. Private Sub Form_Load()
    23. SetTopMostWindow Me.hwnd, TRUE
    24. '(SetTopMostWindow Me.hwnd, FALSE would prevent window from being TopMost)
    25. End Sub

  3. #3

    Thread Starter
    Hyperactive Member Petergotchi's Avatar
    Join Date
    Jan 2002
    Location
    Dendermonde - Belgium
    Posts
    267

    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.

  4. #4

    Thread Starter
    Hyperactive Member Petergotchi's Avatar
    Join Date
    Jan 2002
    Location
    Dendermonde - Belgium
    Posts
    267

    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.

  5. #5
    Addicted Member Virtual24's Avatar
    Join Date
    May 2001
    Posts
    228
    OK! Try This:

    Use these functions:
    VB Code:
    1. Declare Function BringWindowToTop Lib "user32.dll" (ByVal hwnd As Long) As Long
    2.  
    3. 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:
    1. Sub ProgramLoop()
    2.     Do
    3.         If GetForegroundWindow() <> Form1.hWnd Then
    4.             BringWindowToTop(Form1.hWnd)
    5.         End If
    6.         DoEvents
    7.     Loop
    8. 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:
    1. Type POINT_API
    2.     x as long
    3.     y as long
    4. End Type
    5. Dim point as POINT_API
    6. Dim retval as long
    7.  
    8. retval = GetCursorPos(point)
    9. If point.x < form1.left Then
    10.     point.x = Form1.Left
    11. End If
    12. If point.x > (form1.left + form1.width) Then
    13.     point.x = (form1.left + form1.widht)
    14. End If
    15.  
    16. 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
  •  



Click Here to Expand Forum to Full Width