Results 1 to 5 of 5

Thread: Always on top...

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Oct 2001
    Location
    Philippines
    Posts
    136

    Unhappy Always on top...

    Hi,

    Does anyone knows how i can make my form always on top.
    pls show me some codes.


    Thanks in advance.
    elbimbo

  2. #2
    Frenzied Member macai's Avatar
    Join Date
    Jul 2001
    Location
    Napanoch NY
    Posts
    1,228

    Talking Your welcome. :D

    All you need to do is plop this code into a module.

    Code:
    Option Explicit
    
    #If Win16 Then
        Declare Sub SetWindowPos Lib "User" (ByVal hWnd As Integer, ByVal hWndInsertAfter As Integer, ByVal X As Integer, ByVal Y As Integer, ByVal cx As Integer, ByVal cy As Integer, ByVal wFlags As Integer)
    #Else
        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
    #End If
    
    
    Sub KeepOnTop(F As Form, Enabled As Boolean)
    Const SWP_NOMOVE = 2
    Const SWP_NOSIZE = 1
    
    Const HWND_TOPMOST = -1
    Const HWND_NOTOPMOST = -2
    If Enabled Then
     SetWindowPos F.hWnd, -1, 0, 0, 0, 0, SWP_NOMOVE Or SWP_NOSIZE
    Else
     SetWindowPos F.hWnd, -2, 0, 0, 0, 0, SWP_NOMOVE Or SWP_NOSIZE
    End If
    End Sub
    If you want to make a form "always on top", you just do this
    Code:
    Private Sub Command1_Click()
     Call KeepOnTop(Me, True)
    End Sub
    And if you want to disable a form's always on top setting, just,
    Code:
    Private Sub Command1_Click()
     Call KeepOnTop(Me, False)
    End Sub

    Your welcome, and you need help with anything else, my email adress is [email protected]. Have a good one, dude, later.

    OH! One more thing, you can join a cool club i started. You just need to submit some code. CHeck it out here.
    Luke

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Oct 2001
    Location
    Philippines
    Posts
    136

    Unhappy Always on Top MDI problem

    Hi,

    i tried your code but it wont work if the form is a child of an MDI form. how can i resolve this.

    pls reply. thanks.
    elbimbo

  4. #4
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333
    If you don't specify, the folks in this forum will assume that you are using VB, NOT VBA, and that you are dealing with standard forms, NOT MDI forms. 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. Call SetWindowPos(hwnd, -1, 0, 0, 0, 0, 3) - Makes the window topmost
    4. Call SetWindowPos(hwnd, 1, 0, 0, 0, 0, 3)  - Makes the window normal
    I do not know if this will work with MDI as I never, ever use that, but give it shot.

  5. #5
    Frenzied Member macai's Avatar
    Join Date
    Jul 2001
    Location
    Napanoch NY
    Posts
    1,228
    OK, i am really sorry about this, but i dont know what i can tell you. MDI is a bit weird. The SetWindowPos API dosent seem to have ANY affect at ALL.

    So you have a series of options.
    [list=1]
    Stop using MDI
    Find an API call specifically for SetWindowPos MDI style
    Or find a way to use the plain old setwindowpos API call.[/list=1]

    But, you might as well, store my code somewhere. Have a good one dude, i'm shoving off to go tinker with random chunks of code.

    Have a good one!
    Luke

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