Link to home
Start Free TrialLog in
Avatar of zubairi
zubairi

asked on

How to uncheck the "Always on top" at taskbar using VB 6.0

I would like to know on how to uncheck and check the "Always on top"  at taskbar using VB 6.0?

Thank you
Avatar of Ryan Chong
Ryan Chong
Flag of Singapore image

Hi zubairi,

Try this:

'! Stay On Top
Public Const HWND_TOPMOST = -1
Public Const HWND_NOTOPMOST = -2
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
'! Stay On Top

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, 0)
End Sub

Cheers
Avatar of zubairi
zubairi

ASKER

Hi ryancys ,

I am appreciated with your answer but unfortunately that was not answer my question.

i would like to know on how to uncheck/Check "Always on top" at window TASKBAR?

Hope this will clear to everybody

Thank you
Found a code to check the TaskBar status:

Const ABS_AUTOHIDE = &H1
Const ABS_ONTOP = &H2
Const ABM_GETSTATE = &H4
Const ABM_GETTASKBARPOS = &H5
Private Type RECT
    Left As Long
    Top As Long
    Right As Long
    Bottom As Long
End Type
Private Type APPBARDATA
    cbSize As Long
    hwnd As Long
    uCallbackMessage As Long
    uEdge As Long
    rc As RECT
    lParam As Long '  message specific
End Type
Private Declare Function SHAppBarMessage Lib "shell32.dll" (ByVal dwMessage As Long, pData As APPBARDATA) As Long
Private Sub Form_Paint()
    'KPD-Team 1999
    'URL: http://www.allapi.net/
    'E-Mail: KPDTeam@Allapi.net
    Dim ABD As APPBARDATA, Ret As Long
    'Get the taskbar's position
    SHAppBarMessage ABM_GETTASKBARPOS, ABD
    'Get the taskbar's state
    Ret = SHAppBarMessage(ABM_GETSTATE, ABD)
    If (Ret And ABS_AUTOHIDE) Then Me.Print "Autohide option is on"
    If (Ret And ABS_ONTOP) Then Me.Print "Always on top option is on"
    Me.Print "Taskbar coordinates: (" + Trim(Str(ABD.rc.Left)) + "," + Trim(Str(ABD.rc.Top)) + ")-(" + Trim(Str(ABD.rc.Right)) + "," + Trim(Str(ABD.rc.Bottom)) + ")"
End Sub

<Still looking for solution, listening..>
Here is the code for you

http://www.a1vbcode.com/app.asp?ID=1193

Narayanan
ryancys, I think you may be a long while looking. I remember looking at this problem a while back and found that it is actually immensely complicated. Setting either the autohide or ontop properties requires a complete redraw of the window for which you will probably find that you do not have enough information available to do properly.
In the end we decided to go with the simple hide/unhide of the taskbar which is quite easy to achieve. If you do find a solution I would be interested in seeing it though.
Thanks for the comments, Tim. So how do you do that > simply hide/unhide the taskbar?

Currently not find a solution here.. and Curious to ask how M$ Software Engineers achieve this function (Set the 'Always on top' property in Taskbar)? It must be a way to go..

And i think the links provided by n_narayanan, as well as first comments posted by me is not useful for this question.

regards
ASKER CERTIFIED SOLUTION
Avatar of TimCottee
TimCottee
Flag of United Kingdom of Great Britain and Northern Ireland image

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 zubairi

ASKER

Hello there,

I am agree with TimCottee , I have been searching for this code unfortunately i could not find those api to uncheck/check "always on top" at windows taskbar.
but i just found hide/show taskbar and get the taskbar "auto-hide" status.  as given by TimCottee and ryancys.

Now i just thinking about registry key?
Can i know the taskbar information from registry key?

Anybody please help
Avatar of zubairi

ASKER

i do not know what to say. Your answer is not what i want but I still can accept it.
thank you
zubairi,

C is a bad grading!
Avatar of zubairi

ASKER

anybody know which registry key involved when we uncheck and check the "Always on top"  at taskbar?