{$APPTYPE GUI} {$MODE DELPHI} program WinHello; uses Strings, Windows, ShellApi; const AppName = 'WinHello'; menu_Tray = 95; MainWindowStyle = WS_CAPTION or WS_BORDER or WS_SYSMENU; WM_TRAYICON = WM_USER + $0001; var TrayIcon: NotifyIconData; function IntToStr (l: LONGINT): STRING; begin Str (l, result); end; var r : TRect; br: HBrush; NID : TNotifyIconData; function WindowProc(Wnd: HWnd; msg, WParam, LParam: Longint): Longint; stdcall; export; var dc : hdc; ps : paintstruct; begin result := 0; case msg of WM_PAINT: begin DC := BeginPaint(wnd, ps); GetClientRect (wnd, @r); br := CreateSolidBrush($0000FF); FillRect (dc, r, br); DeleteObject(br); EndPaint(wnd, ps); Exit; end; WM_TRAYICON: begin Exit; end; WM_CLOSE: begin PostQuitMessage(0); Exit; end; end; result := DefWindowProc(Wnd, msg, WParam, LParam); end; { Register the Window Class } function WinRegister: Boolean; var WindowClass: WndClass; begin WindowClass.Style := cs_hRedraw or cs_vRedraw; WindowClass.lpfnWndProc := WndProc(@WindowProc); WindowClass.cbClsExtra := 0; WindowClass.cbWndExtra := 0; WindowClass.hInstance := system.MainInstance; WindowClass.hIcon := LoadIcon(0, idi_Exclamation); WindowClass.hCursor := LoadCursor(0, idc_Arrow); WindowClass.hbrBackground := GetStockObject(WHITE_BRUSH); WindowClass.lpszMenuName := nil; WindowClass.lpszClassName := AppName; Result := RegisterClass(WindowClass) <> 0; end; { Create the Window Class } function WinCreate: HWnd; var hWindow: HWnd; begin hWindow := CreateWindowEx(WS_EX_TOOLWINDOW, AppName, 'Hello Bokul', MainWindowStyle, r.Left, r.Top, r.Right, r.Bottom, 0, 0, system.MainInstance, nil); if longint(hWindow) = 0 then begin MessageBox(0, 'WinCreate failed', nil, mb_Ok); Exit; end; ZeroMemory (@TrayIcon, SizeOf (TrayIcon)); TrayIcon.cbSize := SizeOf (TrayIcon); TrayIcon.hWnd := hWindow; TrayIcon.uID := 1; TrayIcon.uFlags := NIF_TIP or NIF_ICON or NIF_MESSAGE; TrayIcon.uCallbackMessage := WM_TRAYICON; TrayIcon.hIcon := LoadIcon(0, idi_Exclamation); // LoadIcon (0, IDI_WINLOGO); TrayIcon.szTip := 'My tray Icon'; Shell_NotifyIcon (NIM_ADD, PNotifyIconData(@TrayIcon)); ShowWindow(hWindow, CmdShow); UpdateWindow(hWindow); Result := hWindow; end; var AMessage: Msg; hMainWindow: HWnd; begin br := CreateSolidBrush($000000); if not WinRegister then begin MessageBox (0, PChar('Can not register window class. Error code ' + IntToStr (GetLastError)), 'Error', MB_OK or MB_ICONERROR); DeleteObject (br); end; r.Right := 200; r.Bottom := 100; r.Left := GetSystemMetrics (SM_CXSCREEN) div 2 - r.Right div 2; r.Top := GetSystemMetrics (SM_CYSCREEN) div 2 - r.Bottom div 2; AdjustWindowRectEx(r, MainWindowStyle, FALSE, WS_EX_TOOLWINDOW); hMainWindow := WinCreate; while GetMessage(@AMessage, 0, 0, 0) do begin TranslateMessage(AMessage); DispatchMessage(AMessage); end; Shell_NotifyIcon (NIM_DELETE, PNotifyIconData(@TrayIcon)); Halt(AMessage.wParam); end.