Always on top

gthgb
gthgb used Ask the Experts™
on
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
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Use the following code
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

Const HWND_TOPMOST = -1
Const HWND_NOTTOPMOST = -2
Const SWP_NOSIZE = 1
Const SWP_NOMOVE = 2
Dim flags As Integer
Private Sub cmdSetTopMost_Click()
   flags = SWP_NOSIZE Or SWP_NOMOVE
   lResult = SetWindowPos(frmDLLDemo.hWnd, HWND_TOPMOST, 0, 0, 0, 0, flags)
End Sub
Sub cmdResetTomost_Click()
   flags = SWP_NOSIZE Or SWP_NOMOVE
   lResult = SetWindowPos(frmDLLDemo.hWnd, HWND_NOTTOPMOST, 0, 0, 0, 0, flags)
End Sub


Get a hold of Daniel Appleman's Book Visual Basic Programmers guide to the Win32 API.  That's th best resource I've found so far.

Ryan ChongSoftware Team Lead

Commented:
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
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
Ensure you’re charging the right price for your IT

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

Commented:
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

Author

Commented:
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!

http://www.experts-exchange.com/Programming/Programming_Languages/Visual_Basic/Q_20377750.html
http://www.experts-exchange.com/Programming/Q_20375979.html

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial