建立在TaskBar上没有Item的Form(转载)

TaskBar上针对每个程式都会有一个Item於其上,按该Item便会Activate该对应的程式
,其实TaskBar上的这些程式Item是用Tab Control做的,所以如果我们能得到TaskBar
上的Tab Control(SysTab)的hWnd,我们便可以随意删除其上的Item了。

1. 一个应用程式启动时, 除了送出 WM_ACTIVE 叫醒自己本身的主要视窗外, 它还会通知
   SysTab (Send ABM_ACTIVATE) 建立该程式在工作列(TaskBar)上的按钮及图示
2. 要让一个应用程式, 按 Alt-Tab 无法切换到, 则必须先改变此应用程式的视窗型态
   为 ToolWindow; 然而在 VB 里面用 Show vbModal 可以达到相同的效果

Option Explicit
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" ( _
    ByVal lpClassName As String, _
    ByVal lpWindowName As String) As Long
 
Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" ( _
    ByVal hWndParent As Long, _
    ByVal hWndChild As Long, _
    ByVal lpClassName As String, _
    ByVal lpWindowName As String) As Long
Const GWL_EXSTYLE = (-20)
Const WS_EX_TOOLWINDOW = &H80
Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long

Private Const TCM_FIRST = &H1300    ' Tab control messages
Private Const TCM_GETIMAGELIST = (TCM_FIRST + 2)
Private Const TCM_SETIMAGELIST = (TCM_FIRST + 3)
Private Const TCM_GETITEMCOUNT = (TCM_FIRST + 4)
Private Const TCM_GETITEMA = (TCM_FIRST + 5)
Private Const TCM_GETITEMW = (TCM_FIRST + 60)
Private Const TCM_SETITEMA = (TCM_FIRST + 6)
Private Const TCM_SETITEMW = (TCM_FIRST + 61)
Private Const TCM_INSERTITEMA = (TCM_FIRST + 7)
Private Const TCM_INSERTITEMW = (TCM_FIRST + 62)
Private Const TCM_DELETEITEM = (TCM_FIRST + 8)
Private Const TCM_DELETEALLITEMS = (TCM_FIRST + 9)
Private Const TCM_GETITEMRECT = (TCM_FIRST + 10)
Private Const TCM_GETCURSEL = (TCM_FIRST + 11)
Private Const TCM_SETCURSEL = (TCM_FIRST + 12)
Private Const TCM_HITTEST = (TCM_FIRST + 13)
Private Const TCM_SETITEMEXTRA = (TCM_FIRST + 14)
Private Const TCM_ADJUSTRECT = (TCM_FIRST + 40)
Private Const TCM_SETITEMSIZE = (TCM_FIRST + 41)
Private Const TCM_REMOVEIMAGE = (TCM_FIRST + 42)
Private Const TCM_SETPADDING = (TCM_FIRST + 43)
Private Const TCM_GETROWCOUNT = (TCM_FIRST + 44)
Private Const TCM_GETTOOLTIPS = (TCM_FIRST + 45)
Private Const TCM_SETTOOLTIPS = (TCM_FIRST + 46)
Private Const TCM_GETCURFOCUS = (TCM_FIRST + 47)
Private Const TCM_SETCURFOCUS = (TCM_FIRST + 48)
Private Const TCM_SETMINTABWIDTH = (TCM_FIRST + 49)
Private Const TCM_DESELECTALL = (TCM_FIRST + 50)
Private Const TCM_HIGHLIGHTITEM = (TCM_FIRST + 51)
Private Const TCM_SETEXTENDEDSTYLE = (TCM_FIRST + 52)
Private Const TCM_GETEXTENDEDSTYLE = (TCM_FIRST + 53)
Private Const TCM_SETUNICODEFORMAT = &H2005
Private Const TCM_GETUNICODEFORMAT = &H2006

Private Sub Form_Load()
 
    Dim lReturn As Long
    Dim lHwnd As Long

    lReturn = FindWindow("Shell_TrayWnd", vbNullString)    ' 先找 Shell Tray handle
    lReturn = FindWindowEx(lReturn, 0, "MSTaskSwWClass", vbNullString)    ' 再找它的 Child
    lHwnd = FindWindowEx(lReturn, 0, "SysTabControl32", vbNullString)    ' 原来就是这一个
    Me.Show
    'DoEvents
    Me.Visible = False
    '将 Window Extend Style 设成 ToolWindow, 按 Alt-Tab 无法切换到
    lReturn = SetWindowLong(Me.hwnd, GWL_EXSTYLE, WS_EX_TOOLWINDOW)
    '应该设定 Visible 的属性, 才能让改变Window Style的 API 致能
    Me.Visible = True
    ' 将 SysTab 上的最後一个 Item 删掉
    lReturn = SendMessage(lHwnd, TCM_GETITEMCOUNT, 0, ByVal 0)
    lReturn = SendMessage(lHwnd, TCM_DELETEITEM, lReturn - 1, ByVal 0)
 
End Sub
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值