Visualizzazione dei risultati da 1 a 7 su 7
  1. #1

    [vb.net]un’icona nella Taskbar di Windows

    grazie alle sottopresenti linee di codice riesco a creare un'icona del programma e ad inserirla nella taskbar ma se chiudo il programma l'icona sparisce mentre io vorrei ottenere un effetto tipo antivirus ovvero che il programma resti in esecuzione
    Dim myNotifyIcon As New NotifyIcon

    ' Oggetto icona
    myNotifyIcon.Icon = New Icon("Icon1.ico")

    ' indica la visibilità dell’icona
    myNotifyIcon.Visible = True

    ' Testo che compare al passaggio del Mouse
    myNotifyIcon.Text = "Notify Icon"

  2. #2

    Prova questo:

    INSERISCI IL CODICE SOTTOSTANTE IN UN MODULO:
    Public 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

    'constants required by Shell_NotifyIcon API call:
    Public Const NIM_ADD = &H0
    Public Const NIM_MODIFY = &H1
    Public Const NIM_DELETE = &H2
    Public Const NIF_MESSAGE = &H1
    Public Const NIF_ICON = &H2
    Public Const NIF_TIP = &H4
    Public Const WM_MOUSEMOVE = &H200
    Public Const WM_LBUTTONDOWN = &H201 'Button down
    Public Const WM_LBUTTONUP = &H202 'Button up
    Public Const WM_LBUTTONDBLCLK = &H203 'Double-click
    Public Const WM_RBUTTONDOWN = &H204 'Button down
    Public Const WM_RBUTTONUP = &H205 'Button up
    Public Const WM_RBUTTONDBLCLK = &H206 'Double-click

    Public Declare Function SetForegroundWindow Lib "user32" _
    (ByVal hwnd As Long) As Long
    Public Declare Function Shell_NotifyIcon Lib "shell32" _
    Alias "Shell_NotifyIconA" _
    (ByVal dwMessage As Long, pnid As NOTIFYICONDATA) As Boolean

    Public nid As NOTIFYICONDATA

    INSERISCI IL CODICE SOTTOSTANTE IN UN FORM:
    Private Sub Form_Load()
    'the form must be fully visible before calling Shell_NotifyIcon
    Me.Show
    Me.Refresh
    With nid
    .cbSize = Len(nid)
    .hwnd = Me.hwnd
    .uId = vbNull
    .uFlags = NIF_ICON Or NIF_TIP Or NIF_MESSAGE
    .uCallBackMessage = WM_MOUSEMOVE
    .hIcon = Me.Icon
    .szTip = "Your ToolTip" & vbNullChar
    End With
    Shell_NotifyIcon NIM_ADD, nid
    End Sub

    Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X AS Single, Y As Single)
    Dim Result As Long
    Dim msg As Long
    'the value of X will vary depending upon the scalemode setting
    If Me.ScaleMode = vbPixels Then
    msg = X
    Else
    msg = X / Screen.TwipsPerPixelX
    End If
    Select Case msg
    Case WM_LBUTTONUP '514 restore form window
    Me.WindowState = vbNormal
    Result = SetForegroundWindow(Me.hwnd)
    Me.Show
    Case WM_LBUTTONDBLCLK '515 restore form window
    Me.WindowState = vbNormal
    Result = SetForegroundWindow(Me.hwnd)
    Me.Show
    Case WM_RBUTTONUP '517 display popup menu
    Result = SetForegroundWindow(Me.hwnd)
    Me.PopupMenu Me.mPopupSys
    End Select
    End Sub

    Private Sub Form_Resize()
    If Me.WindowState = vbMinimized Then Me.Hide
    End Sub

    Private Sub Form_Unload(Cancel As Integer)
    Shell_NotifyIcon NIM_DELETE, nid
    End Sub

    Private Sub mPopExit_Click()
    Unload Me
    End Sub

    Private Sub mPopRestore_Click()
    Dim Result As Long
    Me.WindowState = vbNormal
    Result = SetForegroundWindow(Me.hwnd)
    Me.Show
    End Sub
    LE PROPRIETA' DA GESTIRE DEL FORM
    .icon = l'icona che vuoi visualizzare
    .min button = true
    .showintaskbar = false
    INSERISCI POI QUESTI MENU NEL FORM:
    Caption Name Enabled Visible Position
    ---------------------------------------------------------
    &SysTray mPopupSys True False Main Level
    &Restore mPopRestore True True Inset one
    &Exit mPopExit True True Inset one
    ==============
    Dovrebbe funzionare tutto...

  3. #3
    Quell'esempio è per VB6, mentre per VB.NET trovi un esempio nella guida MSDN (quella installata nel pc, non quella web) in questo percorso:

    + Visual Studio .NET
    + Visual Basic e Visual C#
    + Esempi
    + Applicazioni di esempio di Visual Basic
    + Riepiloghi degli esempi di Visual Basic
    + Riepiloghi degli esempi di Windows Form per Visual Basic
    + Windows Form: esempio System Tray

    Prova eventualmente questo link:
    ms-help://MS.MSDNQTR.2003FEB.1040/vbref/html/vbsamwindowsformssystemtraysample.htm
    (da usare dentro la guida msdn)
    Chi non cerca trova.

  4. #4
    Utente di HTML.it
    Registrato dal
    Jul 2001
    Messaggi
    798
    semplicemente il programma non lo devi far chiudere, tramite la X, ma devi prevedere una tua azione di chiusura.
    Ans.

  5. #5
    Potresti fare così,nella Form_closing del form principale metti:
    codice:
    e.cancel = True
    Me.ShowInTaskbar = False
    Me.WindowState = FormWindowState.Minimized

  6. #6

    SCUSATE LA MIA IGNORANZA

    Ma tutti quei codici scritti dove devo inserirli?

    Ciau

  7. #7

    Re: SCUSATE LA MIA IGNORANZA

    Originariamente inviato da prando91
    Ma tutti quei codici scritti dove devo inserirli?

    Ciau
    Benvenuto nel forum di HTML.it


    Ti invito a prendere visione del Regolamento, dal momento che in un colpo solo hai infranto tante regole:

    1. non si "resuscitano" vecchie discussioni per dare/chiedere risposte, ma si apre una nuova discussione
    2. quando si apre una discussione, mettere nel titolo linguaggio utilizzato e tema principale della discussione
    3. evitare di scrivere in maiuscolo, o meglio.."non gridare !"
    4. spiegazione dettagliata del problema: specificare se compare un errore ed eventualmente la descrizione dell'errore stesso.


    Ciao

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.