dcsimg
Results 1 to 6 of 6

Thread: VB6 system Tray issue in Windows 10 toast tray Icon.

  1. #1

    Thread Starter
    New Member
    Join Date
    Aug 2019
    Posts
    2

    Post VB6 system Tray issue in Windows 10 toast tray Icon.

    HI Members,
    I have an issue with shell 32 system tray Icon in windows 10.
    We have an application created in VB6, In which one of the module uses Shell32 dll to create , modify and delete system tray Icon.
    Once System Tray Icon is created using Shell NM_ADD, We use shell NM_Modify call , during which a balloon notification with the message provided will displayed in the system tray.
    When use the application in Windows 10 instead of balloon notification icon of windows 7 a new toast tray notification will come in windows 10.

    My problem arises when I call shell Modify call in a loop:

    I am calling Shell NM_modify in a loop of 100 count to show progress messages of 100 percent.
    The same is working fine in windows 7 as classic balloon tray message. When I use the application in windows 10 the explorer restart is happening.
    When I reduce the count Less than 20 the toast tray Icon in Windows 10 is working fine.
    If I want to use same loop count 100 in windows 10, If we put sleep of 100 before shell modify of each call its working .

    So there is some delay issue in Windows 10 toast tray due to which the explorer restart is happening.

    Could anyone suggest any solution for This.
    Currently I am going forward with two work around;
    1. with sleep before NM modify call.
    2. By reg edit setting in windows 10 to enable classic balloon system tray view.

    Other than this any other solution can be provided.

    My sample code is as below:

    Option Explicit

    Private Const NOTIFYICON_VERSION = 3

    Private Const NOTIFYICONDATAA_V1_SIZE_A = 88
    Private Const NOTIFYICONDATAA_V1_SIZE_U = 152
    Private Const NOTIFYICONDATAA_V2_SIZE_A = 488
    Private Const NOTIFYICONDATAA_V2_SIZE_U = 936

    Private Enum NIM_CONSTANTS
    NIM_ADD = &H0
    NIM_MODIFY = &H1
    NIM_DELETE = &H2
    NIM_SETFOCUS = &H3
    NIM_SETVERSION = &H4
    End Enum

    Private Enum NIF_CONSTANTS
    NIF_MESSAGE = &H1
    NIF_ICON = &H2
    NIF_TIP = &H4
    NIF_STATE = &H8
    NIF_INFO = &H10
    End Enum

    Private Enum WM_CONSTANTS
    WM_MOUSEMOVE = &H200
    WM_LBUTTONDBLCLK = &H203
    WM_LBUTTONDOWN = &H201
    WM_LBUTTONUP = &H202
    WM_RBUTTONDBLCLK = &H206
    WM_RBUTTONDOWN = &H204
    WM_RBUTTONUP = &H205
    End Enum

    Private Type NOTIFYICONDATA
    cbSize As Long ' 4
    hwnd As Long ' 8
    uID As Long ' 12
    uFlags As Long ' 16
    uCallbackMessage As Long ' 20
    hIcon As Long ' 24
    szTip As String * 128 ' 152
    dwState As Long ' 156
    dwStateMask As Long ' 160
    szInfo As String * 256 ' 416
    uTimeOutOrVersion As Long ' 420
    szInfoTitle As String * 64 ' 484
    dwInfoFlags As Long ' 488
    guidItem As Long ' 492
    End Type

    Private Const WM_USER = &H400
    Private Const NIN_SELECT = WM_USER
    Private Const NINF_KEY = &H1
    Private Const NIN_KEYSELECT = (NIN_SELECT Or NINF_KEY)
    Private Const NIN_BALLOONSHOW = (WM_USER + 2)
    Private Const NIN_BALLOONHIDE = (WM_USER + 3)
    Private Const NIN_BALLOONTIMEOUT = (WM_USER + 4)
    Private Const NIN_BALLOONUSERCLICK = (WM_USER + 5)

    Private Type POINTAPI
    X As Long
    Y As Long
    End Type

    Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
    Private Declare Function Shell_NotifyIcon Lib "shell32" Alias "Shell_NotifyIconA" (ByVal dwMessage As NIM_CONSTANTS, pnid As NOTIFYICONDATA) As Boolean
    Private Declare Function GetSystemMenu Lib "user32" (ByVal hwnd As Long, ByVal bRevert As Long) As Long
    Private Declare Function TrackPopupMenu Lib "user32" (ByVal hMenu As Long, ByVal wFlags As Long, ByVal X As Long, ByVal Y As Long, ByVal nReserved As Long, ByVal hwnd As Long, ByVal lprc As Long) As Long

    Dim IconData As NOTIFYICONDATA

    Dim m_ToolTipText As String
    Dim m_Visible As Boolean
    Dim m_Show As Boolean
    Dim m_SysMenu As Boolean

    Event MouseMove()
    Event MouseDown(Button As Integer)
    Event MouseUp(Button As Integer)
    Event DblClick(Button As Integer)
    Event Click(Button As Integer)
    Event SingleClick(Button As Integer)
    Public Event BalloonShow()
    Public Event BalloonHide()
    Public Event BalloonTimeOut()
    Public Event BalloonClicked()

    Public Enum EBalloonIconTypes
    NIIF_NONE = 0
    NIIF_INFO = 1
    NIIF_WARNING = 2
    NIIF_ERROR = 3
    NIIF_NOSOUND = &H10
    End Enum

    Private Sub Form_Load()
    Dim i As Integer
    Initialise
    For i = 0 To 20 --> Here if loop exceeds more than 20 explorer restart in Windows 10.
    Show_Balloon (i)
    Next
    End Sub

    Public Sub Initialise()
    IconData.hwnd = hwnd
    IconData.uID = App.ThreadID
    IconData.uFlags = NIF_ICON Or NIF_TIP Or NIF_MESSAGE
    IconData.uCallbackMessage = WM_MOUSEMOVE
    IconData.uTimeOutOrVersion = NOTIFYICON_VERSION
    IconData.hIcon = Image1.Picture
    IconData.cbSize = NOTIFYICONDATAA_V2_SIZE_A
    Shell_NotifyIcon NIM_ADD, IconData
    End Sub


    Public Sub Show_Balloon(i As String)
    Dim lR As Long
    IconData.szInfo = "TEST" & i & vbNullChar
    IconData.szInfoTitle = "TEST" & vbNullChar
    IconData.uTimeOutOrVersion = 2000
    IconData.dwInfoFlags = NIIF_INFO + NIIF_NOSOUND
    IconData.uFlags = NIF_INFO
    lR = Shell_NotifyIcon(NIM_MODIFY, IconData)
    End Sub

  2. #2
    Fanatic Member
    Join Date
    Feb 2003
    Posts
    722

    Re: VB6 system Tray issue in Windows 10 toast tray Icon.

    Quote Originally Posted by ponvenky View Post
    HI Members,
    I have an issue with shell 32 system tray Icon in windows 10.
    We have an application created in VB6, In which one of the module uses Shell32 dll to create , modify and delete system tray Icon.
    Once System Tray Icon is created using Shell NM_ADD, We use shell NM_Modify call , during which a balloon notification with the message provided will displayed in the system tray.
    When use the application in Windows 10 instead of balloon notification icon of windows 7 a new toast tray notification will come in windows 10.

    My problem arises when I call shell Modify call in a loop:

    I am calling Shell NM_modify in a loop of 100 count to show progress messages of 100 percent.
    The same is working fine in windows 7 as classic balloon tray message. When I use the application in windows 10 the explorer restart is happening.
    When I reduce the count Less than 20 the toast tray Icon in Windows 10 is working fine.
    If I want to use same loop count 100 in windows 10, If we put sleep of 100 before shell modify of each call its working .

    So there is some delay issue in Windows 10 toast tray due to which the explorer restart is happening.

    Could anyone suggest any solution for This.
    Currently I am going forward with two work around;
    1. with sleep before NM modify call.
    2. By reg edit setting in windows 10 to enable classic balloon system tray view.

    Other than this any other solution can be provided.

    My sample code is as below:

    Option Explicit

    Private Const NOTIFYICON_VERSION = 3

    Private Const NOTIFYICONDATAA_V1_SIZE_A = 88
    Private Const NOTIFYICONDATAA_V1_SIZE_U = 152
    Private Const NOTIFYICONDATAA_V2_SIZE_A = 488
    Private Const NOTIFYICONDATAA_V2_SIZE_U = 936

    Private Enum NIM_CONSTANTS
    NIM_ADD = &H0
    NIM_MODIFY = &H1
    NIM_DELETE = &H2
    NIM_SETFOCUS = &H3
    NIM_SETVERSION = &H4
    End Enum

    Private Enum NIF_CONSTANTS
    NIF_MESSAGE = &H1
    NIF_ICON = &H2
    NIF_TIP = &H4
    NIF_STATE = &H8
    NIF_INFO = &H10
    End Enum

    Private Enum WM_CONSTANTS
    WM_MOUSEMOVE = &H200
    WM_LBUTTONDBLCLK = &H203
    WM_LBUTTONDOWN = &H201
    WM_LBUTTONUP = &H202
    WM_RBUTTONDBLCLK = &H206
    WM_RBUTTONDOWN = &H204
    WM_RBUTTONUP = &H205
    End Enum

    Private Type NOTIFYICONDATA
    cbSize As Long ' 4
    hwnd As Long ' 8
    uID As Long ' 12
    uFlags As Long ' 16
    uCallbackMessage As Long ' 20
    hIcon As Long ' 24
    szTip As String * 128 ' 152
    dwState As Long ' 156
    dwStateMask As Long ' 160
    szInfo As String * 256 ' 416
    uTimeOutOrVersion As Long ' 420
    szInfoTitle As String * 64 ' 484
    dwInfoFlags As Long ' 488
    guidItem As Long ' 492
    End Type

    Private Const WM_USER = &H400
    Private Const NIN_SELECT = WM_USER
    Private Const NINF_KEY = &H1
    Private Const NIN_KEYSELECT = (NIN_SELECT Or NINF_KEY)
    Private Const NIN_BALLOONSHOW = (WM_USER + 2)
    Private Const NIN_BALLOONHIDE = (WM_USER + 3)
    Private Const NIN_BALLOONTIMEOUT = (WM_USER + 4)
    Private Const NIN_BALLOONUSERCLICK = (WM_USER + 5)

    Private Type POINTAPI
    X As Long
    Y As Long
    End Type

    Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
    Private Declare Function Shell_NotifyIcon Lib "shell32" Alias "Shell_NotifyIconA" (ByVal dwMessage As NIM_CONSTANTS, pnid As NOTIFYICONDATA) As Boolean
    Private Declare Function GetSystemMenu Lib "user32" (ByVal hwnd As Long, ByVal bRevert As Long) As Long
    Private Declare Function TrackPopupMenu Lib "user32" (ByVal hMenu As Long, ByVal wFlags As Long, ByVal X As Long, ByVal Y As Long, ByVal nReserved As Long, ByVal hwnd As Long, ByVal lprc As Long) As Long

    Dim IconData As NOTIFYICONDATA

    Dim m_ToolTipText As String
    Dim m_Visible As Boolean
    Dim m_Show As Boolean
    Dim m_SysMenu As Boolean

    Event MouseMove()
    Event MouseDown(Button As Integer)
    Event MouseUp(Button As Integer)
    Event DblClick(Button As Integer)
    Event Click(Button As Integer)
    Event SingleClick(Button As Integer)
    Public Event BalloonShow()
    Public Event BalloonHide()
    Public Event BalloonTimeOut()
    Public Event BalloonClicked()

    Public Enum EBalloonIconTypes
    NIIF_NONE = 0
    NIIF_INFO = 1
    NIIF_WARNING = 2
    NIIF_ERROR = 3
    NIIF_NOSOUND = &H10
    End Enum

    Private Sub Form_Load()
    Dim i As Integer
    Initialise
    For i = 0 To 20 --> Here if loop exceeds more than 20 explorer restart in Windows 10.
    Show_Balloon (i)
    Next
    End Sub

    Public Sub Initialise()
    IconData.hwnd = hwnd
    IconData.uID = App.ThreadID
    IconData.uFlags = NIF_ICON Or NIF_TIP Or NIF_MESSAGE
    IconData.uCallbackMessage = WM_MOUSEMOVE
    IconData.uTimeOutOrVersion = NOTIFYICON_VERSION
    IconData.hIcon = Image1.Picture
    IconData.cbSize = NOTIFYICONDATAA_V2_SIZE_A
    Shell_NotifyIcon NIM_ADD, IconData
    End Sub


    Public Sub Show_Balloon(i As String)
    Dim lR As Long
    IconData.szInfo = "TEST" & i & vbNullChar
    IconData.szInfoTitle = "TEST" & vbNullChar
    IconData.uTimeOutOrVersion = 2000
    IconData.dwInfoFlags = NIIF_INFO + NIIF_NOSOUND
    IconData.uFlags = NIF_INFO
    lR = Shell_NotifyIcon(NIM_MODIFY, IconData)
    End Sub
    Please use code tags.

  3. #3
    Fanatic Member
    Join Date
    Dec 2012
    Posts
    760

    Re: VB6 system Tray issue in Windows 10 toast tray Icon.

    I gave up on using balloons with Win 10, as too many people just ignore the barrage of notifications. I now use a simple popup similar to the one dilletante used in:
    http://www.vbforums.com/showthread.p...eplacement-VB6

    J.A. Coutts

  4. #4

    Thread Starter
    New Member
    Join Date
    Aug 2019
    Posts
    2

    Re: VB6 system Tray issue in Windows 10 toast tray Icon.

    Hi Peter,
    I have added some basic comments to the code. Please let me know if anything more specific in the comments.


    My sample code is as below:

    Option Explicit

    ************** Assingning const variables****************
    Private Const NOTIFYICON_VERSION = 3
    Private Const NOTIFYICONDATAA_V1_SIZE_A = 88
    Private Const NOTIFYICONDATAA_V1_SIZE_U = 152
    Private Const NOTIFYICONDATAA_V2_SIZE_A = 488
    Private Const NOTIFYICONDATAA_V2_SIZE_U = 936


    ************** Assingning const variables of Shell Icon Flags****************
    Private Enum NIM_CONSTANTS
    NIM_ADD = &H0
    NIM_MODIFY = &H1
    NIM_DELETE = &H2
    NIM_SETFOCUS = &H3
    NIM_SETVERSION = &H4
    End Enum

    Private Enum NIF_CONSTANTS
    NIF_MESSAGE = &H1
    NIF_ICON = &H2
    NIF_TIP = &H4
    NIF_STATE = &H8
    NIF_INFO = &H10
    End Enum

    Private Enum WM_CONSTANTS
    WM_MOUSEMOVE = &H200
    WM_LBUTTONDBLCLK = &H203
    WM_LBUTTONDOWN = &H201
    WM_LBUTTONUP = &H202
    WM_RBUTTONDBLCLK = &H206
    WM_RBUTTONDOWN = &H204
    WM_RBUTTONUP = &H205
    End Enum


    ************** Assingning const variables of Shell32 variables ****************
    Private Type NOTIFYICONDATA
    cbSize As Long ' 4
    hwnd As Long ' 8
    uID As Long ' 12
    uFlags As Long ' 16
    uCallbackMessage As Long ' 20
    hIcon As Long ' 24
    szTip As String * 128 ' 152
    dwState As Long ' 156
    dwStateMask As Long ' 160
    szInfo As String * 256 ' 416
    uTimeOutOrVersion As Long ' 420
    szInfoTitle As String * 64 ' 484
    dwInfoFlags As Long ' 488
    guidItem As Long ' 492
    End Type

    Private Const WM_USER = &H400
    Private Const NIN_SELECT = WM_USER
    Private Const NINF_KEY = &H1
    Private Const NIN_KEYSELECT = (NIN_SELECT Or NINF_KEY)
    Private Const NIN_BALLOONSHOW = (WM_USER + 2)
    Private Const NIN_BALLOONHIDE = (WM_USER + 3)
    Private Const NIN_BALLOONTIMEOUT = (WM_USER + 4)
    Private Const NIN_BALLOONUSERCLICK = (WM_USER + 5)

    Private Type POINTAPI
    X As Long
    Y As Long
    End Type


    **************** decalaring Shell 32 dll as a library call *********************************
    Private Declare Function Shell_NotifyIcon Lib "shell32" Alias "Shell_NotifyIconA" (ByVal dwMessage As NIM_CONSTANTS, pnid As NOTIFYICONDATA) As Boolean


    Dim IconData As NOTIFYICONDATA

    Dim m_ToolTipText As String
    Dim m_Visible As Boolean
    Dim m_Show As Boolean
    Dim m_SysMenu As Boolean

    **********************************Events handles****************************
    Event MouseMove()
    Event MouseDown(Button As Integer)
    Event MouseUp(Button As Integer)
    Event DblClick(Button As Integer)
    Event Click(Button As Integer)
    Event SingleClick(Button As Integer)
    Public Event BalloonShow()
    Public Event BalloonHide()
    Public Event BalloonTimeOut()
    Public Event BalloonClicked()

    Public Enum EBalloonIconTypes
    NIIF_NONE = 0
    NIIF_INFO = 1
    NIIF_WARNING = 2
    NIIF_ERROR = 3
    NIIF_NOSOUND = &H10
    End Enum


    ***********************Form Load Start From Here******************************
    Private Sub Form_Load()
    Dim i As Integer
    Initialise --> Calling Initialise Initialise to add system tray ICON
    For i = 0 To 20 --> Here if loop exceeds more than 20 explorer restart in Windows 10.
    Show_Balloon (i) ---> Show_balloon call will modify shell tray message so that system popup will get generated
    Next
    End Sub

    Public Sub Initialise() --> **** Start **** Definition of Initialise Initialise
    IconData.hwnd = hwnd
    IconData.uID = App.ThreadID
    IconData.uFlags = NIF_ICON Or NIF_TIP Or NIF_MESSAGE
    IconData.uCallbackMessage = WM_MOUSEMOVE
    IconData.uTimeOutOrVersion = NOTIFYICON_VERSION
    IconData.hIcon = Image1.Picture
    IconData.cbSize = NOTIFYICONDATAA_V2_SIZE_A
    Shell_NotifyIcon NIM_ADD, IconData --> This call NIM_ADD will add system tray Icon
    End Sub --> **** END **** Definition of Initialise Initialise


    Public Sub Show_Balloon(i As String) -> **** Start **** Definition of Show_Balloon Initialise
    Dim lR As Long
    IconData.szInfo = "TEST" & i & vbNullChar
    IconData.szInfoTitle = "TEST" & vbNullChar
    IconData.uTimeOutOrVersion = 2000
    IconData.dwInfoFlags = NIIF_INFO + NIIF_NOSOUND
    IconData.uFlags = NIF_INFO
    lR = Shell_NotifyIcon(NIM_MODIFY, IconData) --> This call NIM_MODIFY will pop a balloon tray message
    End Sub -> **** END **** Definition of Show_Balloon Initialise

  5. #5
    Frenzied Member
    Join Date
    Feb 2017
    Posts
    1,788

    Re: VB6 system Tray issue in Windows 10 toast tray Icon.

    Quote Originally Posted by Peter Swinkels View Post
    Please use code tags.
    Name:  code-tags.jpg
Views: 66
Size:  19.0 KB

  6. #6
    Frenzied Member wqweto's Avatar
    Join Date
    May 2011
    Posts
    1,491

    Re: VB6 system Tray issue in Windows 10 toast tray Icon.

    Quote Originally Posted by ponvenky View Post
    I am calling Shell NM_modify in a loop of 100 count to show progress messages of 100 percent.
    The same is working fine in windows 7 as classic balloon tray message. When I use the application in windows 10 the explorer restart is happening.
    Works here with no crashes. I just copy/pasted your code in a form and added Image1 with an icon assigned (not a bitmap).

    The 100 notifications were spooled by the OS not to overwhelm the UI, each one showing once the previous is dismissed.

    cheers,
    </wqw>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width