fb:porticula NoPaste
Trayicon laden u. anzeigen mit Mausabfrage
Uploader: | Michael |
Datum/Zeit: | 05.05.2006 23:24:36 |
''' Autor: Michael
''' Viele Teile aus Lutz-Ifers WinAPI-Tutorial(Kapitel 3.2) entnommen
''' ---> LutzIfer.FreeBasic.de
option explicit
#define WIN_INCLUDEALL
#include "windows.bi"
#define WM_TRAYICON WM_APP+1
const ProgrammName = "TrayIcon test"
Declare function Fenster(byval hWnd as HWND, byval message as UINTEGER,_
byval wParam as WPARAM, byval lParam as LPARAM) as LRESULT
dim as WNDCLASS wcMeinFenster
with wcMeinFenster
.style = CS_HREDRAW or CS_VREDRAW
.lpfnWndProc = ProcPtr(Fenster)
.cbClsExtra = 0
.cbWndExtra = 0
.hInstance = GetModuleHandle(NULL)
.hCursor = LoadCursor(NULL, IDC_ARROW)
.hIcon = LoadIcon(NULL, IDI_APPLICATION)
.hbrBackground = GetStockObject(WHITE_BRUSH)
.lpszClassName = StrPtr(ProgrammName)
.lpszMenuName = NULL
end with
RegisterClass @wcMeinFenster
dim as HWND hMeinFenster = CreateWindow(_
ProgrammName, "Titelzeile", WS_OVERLAPPEDWINDOW,_
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,_
NULL, NULL, GetModuleHandle(NULL), NULL)
ShowWindow hMeinFenster, SW_HIDE 'sw_show wenn man das "große" fenster auch sehen möchte
UpdateWindow hMeinFenster
'für das Trayicon
Dim SystrayIcon As NOTIFYICONDATA
Dim hIcon As hicon
hIcon = ExtractIcon(getmodulehandle(0),"C:\Windows\system32\SHELL32.dll",165)
With SystrayIcon
.cbSize = Len(SystrayIcon)
.hWnd = hmeinfenster
.uId = 1&
.uFlags = NIF_ICON Or NIF_TIP Or NIF_MESSAGE
.ucallbackMessage = WM_TRAYICON
.hIcon = hicon
.szTip = "Ich bin ein Text den man sieht, wenn man mit der maus über dem icon ist." +Chr(0)
End With
Shell_NotifyIcon NIM_ADD, @SystrayIcon
dim as MSG msg
do while getmessage(@msg, NULL, 0, 0) <> 0
DispatchMessage @msg
loop
end msg.wParam
function Fenster(byval hWnd as HWND, byval message as UINTEGER,_
byval wParam as WPARAM, byval lParam as LPARAM) as LRESULT
static as POINT ptStart, ptEnde
dim as HDC hDC
select case message
case WM_DESTROY
PostQuitMessage 0
return 0
Case WM_TRAYICON
Select Case lparam
Case WM_LBUTTONDOWN
Print "linke maustaste gedrückt."
Case WM_LBUTTONUP
Print "linke maustaste losgelassen."
Case WM_RBUTTONDOWN
Print "rechte maustaste gedrückt."
Case WM_RBUTTONUP
Print "rechte maustaste losgelassen."
End Select
end select
return DefWindowProc( hWnd, message, wParam, lParam )
end function