Link to home
Start Free TrialLog in
Avatar of gthgb
gthgb

asked on

Always on top

just looking for a bit of code to toggle always on top on and off

also
im using vb 6 and i have the api viewer.. how can i find out to USE the api.. the api veiwer alowes me to declare the api but not tell me what it does or how to use it
is there an online list or data base that shows the entire api or is it hiding inside the msdn cd's
ASKER CERTIFIED SOLUTION
Avatar of twalgrave
twalgrave

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Ryan Chong
Points to twalgrave. Here is a better approach:

Public Const HWND_TOPMOST = -1
Public Const HWND_NOTOPMOST = -2
Public Const SWP_NOSIZE = &H1
Public Const SWP_NOMOVE = &H2
Public Const SWP_NOREDRAW = &H8
Public Const SWP_NOACTIVATE = &H10
Public Const SWP_SHOWWINDOW = &H40
Public Declare Function RemoveMenu Lib "user32" (ByVal hMenu As Long, ByVal nPosition As Long, ByVal wFlags As Long) As Long
Public 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

Public Sub StayOnTop(frmForm As Form, fOnTop As Boolean)
    Dim lState As Long
    Dim iLeft As Integer, iTop As Integer, iWidth As Integer, iHeight As Integer
    With frmForm
        iLeft = .Left / Screen.TwipsPerPixelX
        iTop = .Top / Screen.TwipsPerPixelY
        iWidth = .Width / Screen.TwipsPerPixelX
        iHeight = .Height / Screen.TwipsPerPixelY
    End With
    If fOnTop Then
        lState = HWND_TOPMOST
    Else
        lState = HWND_NOTOPMOST
    End If
    'Call SetWindowPos(frmForm.hwnd, lState, iLeft, iTop, iWidth, iHeight, SWP_NOACTIVATE Or SWP_SHOWWINDOW Or SWP_NOREDRAW Or SWP_NOSIZE Or SWP_NOMOVE)
    Call SetWindowPos(frmForm.hwnd, lState, iLeft, iTop, iWidth, iHeight, 0)
End Sub
Avatar of Crazy_king_in
Crazy_king_in

Try this code

Put this in a Module


Private Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, y, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
Private Const HWND_TOPMOST = -1
Private Const HWND_NOTOPMOST = -2
Private Const SWP_NOMOVE = &H2
Private Const SWP_NOSIZE = &H1
Private Const TOPMOST_FLAGS = SWP_NOMOVE Or SWP_NOSIZE

Public Sub MakeNormal(hwnd As Long)
    SetWindowPos hwnd, HWND_NOTOPMOST, 0, 0, 0, 0, TOPMOST_FLAGS
End Sub
Public Sub MakeTopMost(hwnd As Long)
    SetWindowPos hwnd, HWND_TOPMOST, 0, 0, 0, 0, TOPMOST_FLAGS
End Sub


In the form load even call
module1.MakeTopMost(me.hwnd)

To make it normal call
module1.makenormal(me.hwnd)

Good Luck
For more info about API's try http:\\www.allapi.net .
They have a tool called API-Guide which you can download for free. It shows you declaration, parameters and examples of API-Calls.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in Community Support that this question is:
- Award the points to twalgrave

Please leave any comments here within the
next seven days.
Per recommendation, force-accepted.

Netminder
EE Admin
Avatar of gthgb

ASKER

sorry guys... sorta got disconnected from the net for a while... oce again sorry twalgrave..
Not a problem at all.  Can you look at your other two old open questions and finalize them please.  I would appreciate it.  Have a great day and welcome back!

https://www.experts-exchange.com/questions/20377750/Recursive-Delete-no-FileSystemObject-or-Dos-commands.html
https://www.experts-exchange.com/questions/20375979/Recersive-Delete.html