Click here to Skip to main content
15,867,308 members
Home / Discussions / Visual Basic
   

Visual Basic

 
QuestionSetup Project not found in template Pin
Benniit17-Dec-22 18:23
Benniit17-Dec-22 18:23 
AnswerRe: Setup Project not found in template Pin
Richard Deeming18-Dec-22 21:23
mveRichard Deeming18-Dec-22 21:23 
GeneralRe: Setup Project not found in template Pin
Benniit18-Dec-22 21:48
Benniit18-Dec-22 21:48 
QuestionImports Excel = Microsoft.Office.Interop.Excel Pin
LAMBERT Georges5-Dec-22 2:52
LAMBERT Georges5-Dec-22 2:52 
AnswerRe: Imports Excel = Microsoft.Office.Interop.Excel Pin
Ralf Meier5-Dec-22 2:57
professionalRalf Meier5-Dec-22 2:57 
AnswerRe: Imports Excel = Microsoft.Office.Interop.Excel Pin
Richard MacCutchan5-Dec-22 3:19
mveRichard MacCutchan5-Dec-22 3:19 
AnswerRe: Imports Excel = Microsoft.Office.Interop.Excel Pin
jsc425-Dec-22 22:46
professionaljsc425-Dec-22 22:46 
QuestionRemove pesky "zombie" icons from the Windows System Tray Pin
Dan Desjardins28-Nov-22 4:40
Dan Desjardins28-Nov-22 4:40 
There is no (apparent) API for managing icons in the system tray in Windows. Applications that live in the system tray that are aborted through Task Manager, or end without a proper shutdown (error out) will leave their icons in the system tray. Restarting the application then puts another icon in the tray. The zombie icons persist and the only official way to remove them is to float your mouse over them and POOF - they disappear. There simply is no Win32 API for clearing these out. In my research I have found that a lot of folks are looking for the ability to clear these out. I even found one commercial product from a company called APPSVOID But it's bundled in an expensive subscription package.
I suspect the commercial product uses hacks that can be found in various places in languages other than VB. One such can be found at Refresh Notification Area This works, but is written entirely in C++. I'm not a C++ Programmer so I spent some time clumsily refactoring the C++ to vb.net (Framework 4.8 in a Winforms application) and came up with the following and would love it if someone smarter than me could look over my shoulder, laugh a little, and help out:
VB
<pre>Imports System.Runtime.InteropServices

Public Class ClearSystemTray

    Private Const WM_MOUSEMOVE As UInteger = &H200

    <DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)>
    Private Shared Function PostMessage(ByVal hWnd As IntPtr, ByVal Msg As UInteger, ByVal wParam As IntPtr, ByVal lParam As IntPtr) As Boolean
    End Function

    '<DllImport("user32.dll", EntryPoint:="SendMessageW")>
    'Private Shared Function SendMessageW(ByVal hWnd As IntPtr, ByVal Msg As UInteger, ByVal wParam As Integer, ByVal lParam As Integer) As Integer
    'End Function

    <DllImport("user32.dll", EntryPoint:="FindWindowW")>
    Public Shared Function FindWindowW(<MarshalAs(UnmanagedType.LPTStr)> ByVal lpClassName As String, <MarshalAs(UnmanagedType.LPTStr)> ByVal lpWindowName As String) As IntPtr
    End Function

    <DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)>
    Private Shared Function FindWindowEx(ByVal parentHandle As IntPtr, ByVal childAfter As IntPtr, ByVal lclassName As String, ByVal windowTitle As String) As IntPtr
    End Function

    <DllImport("user32.dll", CharSet:=CharSet.Auto)>
    Private Shared Function GetClientRect(ByVal hWnd As System.IntPtr, ByRef lpRECT As Rectangle) As Integer
    End Function

    Public Shared Async Function ClearTray() As Task(Of Task)
        Dim SystemTrayContainerHandle As IntPtr = FindWindowW("Shell_TrayWnd", Nothing)
        Dim systemTrayHandle As IntPtr = FindWindowEx(SystemTrayContainerHandle, IntPtr.Zero, "TrayNotifyWnd", Nothing)
        Dim sysPagerHandle As IntPtr = FindWindowEx(systemTrayHandle, IntPtr.Zero, "SysPager", Nothing)
        Dim NotificationAreaHandle = FindWindowEx(sysPagerHandle, IntPtr.Zero, "ToolbarWindow32", "Notification Area")

        If NotificationAreaHandle = IntPtr.Zero Then
            NotificationAreaHandle = FindWindowEx(sysPagerHandle, IntPtr.Zero, "ToolbarWindow32", "User Promoted Notification Area")
            Dim notifyIconOverflowWindowHandle As IntPtr = FindWindowW("NotifyIconOverflowWindow", Nothing)
            Dim overflowNotificationAreaHandle As IntPtr = FindWindowEx(notifyIconOverflowWindowHandle, IntPtr.Zero, "ToolbarWindow32", "Overflow Notification Area")
            Await RefreshTrayArea(NotificationAreaHandle)
            Await RefreshTrayArea(notifyIconOverflowWindowHandle)
            Await RefreshTrayArea(overflowNotificationAreaHandle)
        Else
            Await RefreshTrayArea(NotificationAreaHandle)
        End If

        Application.DoEvents()

        Return Task.CompletedTask

    End Function

    Private Shared Async Function RefreshTrayArea(windowHandle As IntPtr) As Task(Of Task)
        Dim rect As Rectangle
        GetClientRect(windowHandle, rect)
        Dim iPos As Integer
        Await Task.Run(Sub()
                           For x As Integer = 0 To rect.Right - 1 Step 5
                               For y As Integer = 0 To rect.Bottom - 1 Step 5
                                   iPos = (y << 16) + x
                                   'SendMessageW(windowHandle, WM_MOUSEMOVE, 0, iPos)
                                   PostMessage(windowHandle, WM_MOUSEMOVE, 0, iPos)
                               Next
                               Application.DoEvents()
                           Next
                       End Sub)

                           Return Task.CompletedTask

    End Function

Since I can barely read the C++ code I have no idea if I did this correctly or not - but... it appears to work.
Here is the original C++ code from the above mentioned site:
C++
<pre>#include "stdafx.h"

#define FW(x,y) FindWindowEx(x, NULL, y, L"")

int _tmain(int argc, _TCHAR* argv[])
{
	HWND hNotificationArea;
    RECT r;

	//WinXP
    GetClientRect(
        hNotificationArea = FindWindowEx(
            FW(FW(FW(NULL, L"Shell_TrayWnd"), L"TrayNotifyWnd"), L"SysPager"),
            NULL,
            L"ToolbarWindow32",
            L"Notification Area"),
        &r);
    
    for (LONG x = 0; x < r.right; x += 5)
        for (LONG y = 0; y < r.bottom; y += 5)
            SendMessage(
                hNotificationArea,
                WM_MOUSEMOVE,
                0,
                (y << 16) + x);
	

	//Visible icons
    GetClientRect(
        hNotificationArea = FindWindowEx(
            FW(FW(FW(NULL, L"Shell_TrayWnd"), L"TrayNotifyWnd"), L"SysPager"),
            NULL,
            L"ToolbarWindow32",
            L"User Promoted Notification Area"),
        &r);
    
    for (LONG x = 0; x < r.right; x += 5)
        for (LONG y = 0; y < r.bottom; y += 5)
            SendMessage(
                hNotificationArea,
                WM_MOUSEMOVE,
                0,
                (y << 16) + x);


	//Hidden icons
	GetClientRect(
        hNotificationArea = FindWindowEx(
            FW(NULL, L"NotifyIconOverflowWindow"),
            NULL,
            L"ToolbarWindow32",
            L"Overflow Notification Area"),
        &r);
    
    for (LONG x = 0; x < r.right; x += 5)
        for (LONG y = 0; y < r.bottom; y += 5)
            SendMessage(
                hNotificationArea,
                WM_MOUSEMOVE,
                0,
                (y << 16) + x);


	return 0;
}

If someone here is literate in C++ it would be great if you could look this over and see what dumb things I may have done. I am not offended by legitimate criticism (saying you shouldn't be using VB is not legitimate criticism). Also - if someone thinks it's valuable to have this in C# I'm game for that.

modified 29-Nov-22 8:21am.

SuggestionRe: Remove pesky "zombie" icons from the Windows System Tray Pin
Richard Deeming28-Nov-22 21:22
mveRichard Deeming28-Nov-22 21:22 
GeneralRe: Remove pesky "zombie" icons from the Windows System Tray Pin
Dan Desjardins29-Nov-22 2:19
Dan Desjardins29-Nov-22 2:19 
GeneralRe: Remove pesky "zombie" icons from the Windows System Tray Pin
Richard Deeming29-Nov-22 2:44
mveRichard Deeming29-Nov-22 2:44 
GeneralRe: Remove pesky "zombie" icons from the Windows System Tray Pin
Dan Desjardins29-Nov-22 4:19
Dan Desjardins29-Nov-22 4:19 
QuestionAttendance Machine IP Connected / Disconnected Pin
Member 132153538-Nov-22 18:23
Member 132153538-Nov-22 18:23 
AnswerRe: Attendance Machine IP Connected / Disconnected Pin
Richard Deeming8-Nov-22 21:39
mveRichard Deeming8-Nov-22 21:39 
GeneralRe: Attendance Machine IP Connected / Disconnected Pin
Member 1321535310-Nov-22 23:38
Member 1321535310-Nov-22 23:38 
GeneralRe: Attendance Machine IP Connected / Disconnected Pin
Richard MacCutchan11-Nov-22 1:35
mveRichard MacCutchan11-Nov-22 1:35 
QuestionRe: Attendance Machine IP Connected / Disconnected Pin
Eddy Vluggen11-Nov-22 6:46
professionalEddy Vluggen11-Nov-22 6:46 
AnswerRe: Attendance Machine IP Connected / Disconnected Pin
Gerry Schmitz11-Nov-22 6:50
mveGerry Schmitz11-Nov-22 6:50 
GeneralRe: Attendance Machine IP Connected / Disconnected Pin
Eddy Vluggen11-Nov-22 13:25
professionalEddy Vluggen11-Nov-22 13:25 
QuestionMaking VC++ 6 DLL to work on VB6 App with no UNICODE issue Pin
whiteboat27-Oct-22 19:28
whiteboat27-Oct-22 19:28 
AnswerRe: Making VC++ 6 DLL to work on VB6 App with no UNICODE issue Pin
Victor Nijegorodov27-Oct-22 20:43
Victor Nijegorodov27-Oct-22 20:43 
GeneralRe: Making VC++ 6 DLL to work on VB6 App with no UNICODE issue Pin
whiteboat27-Oct-22 21:24
whiteboat27-Oct-22 21:24 
QuestionVBApp with a Crystal Report in it. Where do I find it when published. Pin
KreativeKai27-Oct-22 6:21
professionalKreativeKai27-Oct-22 6:21 
AnswerRe: VBApp with a Crystal Report in it. Where do I find it when published. Pin
Richard Deeming27-Oct-22 21:09
mveRichard Deeming27-Oct-22 21:09 
QuestionUpdate Parent and Child Table Pin
EngrImad27-Oct-22 0:37
EngrImad27-Oct-22 0:37 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.