タスクバーにアイコンを追加・削除          <TOP>


タスクバーの右部に指定のアイコンを追加、または削除してみます。

Shell_NotifyIcon タスクトレイにアイコンを追加、変更、削除のメッセージをシステムに通知

LoadImage 画像ファイルの読み込み

 

 

'================================================================
'= タスクバーにアイコンを追加・削除
'=    (Shell_NotifyIcon.bas)
'================================================================
#include "Windows.bi"

Type NOTIFYICONDATA
    cbSize           As Long
    hwnd             As Long
    uID              As Long
    uFlags           As Long
    uCallbackMessage As Long
    hIcon            As Long
    szTip            As String * 64
End Type

' タスクトレーにアイコンを追加・変更・削除のメッセージをシステムに通知
Declare Function Api_Shell_NotifyIcon& Lib "shell32" Alias "Shell_NotifyIconA" (ByVal dwMessage&, lpData As NOTIFYICONDATA)

' 画像ファイルの読み込み
Declare Function Api_LoadImage& Lib "user32" Alias "LoadImageA" (ByVal hInst&, ByVal lpszName$, ByVal uType&, ByVal cxDesired&, ByVal cyDesired&, ByVal fuLoad&)

#define NIF_ICON &H2                    'hIconが有効
#define NIF_MESSAGE &H1                 'uCallbackMessageが有効
#define NIF_TIP &H4                     'szTipが有効
#define NIM_ADD &H0                     'アイコンを追加
#define NIM_DELETE &H2                  'アイコンを削除
#define NIM_MODIFY &H1                  'アイコンを変更
#define WM_MOUSEMOVE &H200              'マウスが移動した
#define IMAGE_BITMAP 0                  'ビットマップ
#define IMAGE_CURSOR 2                  'カーソル
#define IMAGE_ENHMETAFILE 3             '拡張メタファイル
#define IMAGE_ICON 1                    'アイコン
#define LR_LOADFROMFILE &H10            '外部ファイルからロードする

Var Shared nid As NOTIFYICONDATA

Var Shared Button1 As Object
Var Shared Button2 As Object

Button1.Attach GetDlgItem("Button1") : Button1.SetFontSize 14
Button2.Attach GetDlgItem("Button2") : Button2.SetFontSize 14

'================================================================
'= 追加
'================================================================
Declare Sub Button1_on edecl ()
Sub Button1_on()
    Var Ret As Long

    nid.cbSize = Len(nid)
    nid.hwnd = GethWnd
    nid.uID = 1
    nid.uFlags = NIF_MESSAGE Or NIF_ICON Or NIF_TIP
    nid.uCallbackMessage = WM_MOUSEMOVE
    nid.hIcon = Api_LoadImage(GethInst, "Test5.ico", IMAGE_ICON, 0, 0, LR_LOADFROMFILE)
    nid.szTip = "これは Tooltip :-)" & Chr$(0)

    Ret = Api_Shell_NotifyIcon(NIM_ADD, nid)
End Sub

'================================================================
'= 削除
'================================================================
Declare Sub Button2_on edecl ()
Sub Button2_on()
    Var Ret As Long

    Ret = Api_Shell_NotifyIcon(NIM_DELETE, nid)
End Sub

'================================================================
'=
'================================================================
Declare Sub MainForm_QueryClose edecl ()
Sub MainForm_QueryClose()
    Button2_on
    End
End Sub

'================================================================
'=
'================================================================
While 1
    WaitEvent
Wend
Stop
End