VirtualBox

Changeset 23053 in vbox


Ignore:
Timestamp:
Sep 16, 2009 8:42:56 AM (15 years ago)
Author:
vboxsync
Message:

VBoxTray: Added balloon tooltip notification for VBox host version update.

Location:
trunk/src/VBox/Additions/WINNT/VBoxTray
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Additions/WINNT/VBoxTray/Makefile.kmk

    r15176 r23053  
    4141        helpers.cpp \
    4242        VBoxTray.rc
     43ifdef VBOX_WITH_GUEST_PROPS
     44 VBoxTray_DEFS     +=  _WIN32_IE=0x500 VBOX_WITH_GUEST_PROPS
     45 VBoxTray_SOURCES  += \
     46        VBoxHostVersion.cpp
     47endif
     48
    4349VBoxTray_LIBS     = \
    4450        $(VBOX_LIB_IPRT_GUEST_R3) \
  • trunk/src/VBox/Additions/WINNT/VBoxTray/VBoxTray.cpp

    r21905 r23053  
    2727#include "VBoxStatistics.h"
    2828#include "VBoxMemBalloon.h"
     29#include "VBoxHostVersion.h"
    2930#include <VBoxHook.h>
    3031#include "resource.h"
     
    299300    Log(("VBoxTray: Window Handle = %p, Status = %p\n", gToolWindow, status));
    300301
     302    OSVERSIONINFO           info;
     303    DWORD                   dwMajorVersion = 5; /* default XP */
     304    info.dwOSVersionInfoSize = sizeof(info);
     305    if (GetVersionEx(&info))
     306    {
     307        Log(("VBoxTray: Windows version major %d minor %d\n", info.dwMajorVersion, info.dwMinorVersion));
     308        dwMajorVersion = info.dwMajorVersion;
     309    }
     310
    301311    if (status == NO_ERROR)
    302312    {
     
    310320        /* We need to setup a security descriptor to allow other processes modify access to the seamless notification event semaphore */
    311321        SECURITY_ATTRIBUTES     SecAttr;
    312         OSVERSIONINFO           info;
    313322        char                    secDesc[SECURITY_DESCRIPTOR_MIN_LENGTH];
    314         DWORD                   dwMajorVersion = 5; /* default XP */
    315323        BOOL                    ret;
    316324
     
    323331            Log(("VBoxTray: SetSecurityDescriptorDacl failed with %d\n", GetLastError()));
    324332
    325         info.dwOSVersionInfoSize = sizeof(info);
    326         if (GetVersionEx(&info))
    327         {
    328             Log(("VBoxTray: Windows version major %d minor %d\n", info.dwMajorVersion, info.dwMinorVersion));
    329             dwMajorVersion = info.dwMajorVersion;
    330         }
    331 
    332333        /* For Vista and up we need to change the integrity of the security descriptor too */
    333334        if (dwMajorVersion >= 6)
     
    407408    ndata.cbSize           = NOTIFYICONDATA_V1_SIZE; // sizeof(NOTIFYICONDATA);
    408409    ndata.hWnd             = gToolWindow;
    409     ndata.uID              = 2000;
     410    ndata.uID              = ID_TRAYICON;
    410411    ndata.uFlags           = NIF_ICON | NIF_MESSAGE | NIF_TIP;
    411412    ndata.uCallbackMessage = WM_USER;
    412413    ndata.hIcon            = LoadIcon(gInstance, MAKEINTRESOURCE(IDI_VIRTUALBOX));
    413414    sprintf(ndata.szTip, "Sun VirtualBox Guest Additions %d.%d.%dr%d", VBOX_VERSION_MAJOR, VBOX_VERSION_MINOR, VBOX_VERSION_BUILD, VBOX_SVN_REV);
    414 
    415415    Log(("VBoxTray: ndata.hWnd %08X, ndata.hIcon = %p\n", ndata.hWnd, ndata.hIcon));
    416416
     
    472472                fTrayIconCreated = Shell_NotifyIcon(NIM_ADD, &ndata);
    473473                Log(("VBoxTray: fTrayIconCreated = %d, err %08X\n", fTrayIconCreated, GetLastError ()));
     474
     475                /* We're ready to create the tooltip balloon. */
     476                if (fTrayIconCreated && dwMajorVersion >= 5)
     477                {
     478                    /* Check in 10 seconds (@todo make seconds configurable) ... */
     479                    SetTimer(gToolWindow,
     480                             WM_VBOX_CHECK_HOSTVERSION,
     481                             10000, /* 10 seconds */
     482                             NULL   /* no timerproc */);
     483                }
    474484            }
    475485        }
     
    508518{
    509519    /* Do not use a global namespace ("Global\\") for mutex name here, will blow up NT4 compatibility! */
    510     HANDLE hMutexAppRunning = CreateMutex (NULL, FALSE, "VBoxTray");
     520    HANDLE hMutexAppRunning = CreateMutex(NULL, FALSE, "VBoxTray");
    511521    if (   (hMutexAppRunning != NULL)
    512522        && (GetLastError() == ERROR_ALREADY_EXISTS))
     
    535545    /* Release instance mutex. */
    536546    if (hMutexAppRunning != NULL) {
    537         CloseHandle (hMutexAppRunning);
     547        CloseHandle(hMutexAppRunning);
    538548        hMutexAppRunning = NULL;
    539549    }
     
    554564
    555565        case WM_DESTROY:
     566            KillTimer(gToolWindow, WM_VBOX_CHECK_HOSTVERSION);
     567            break;
     568
     569        case WM_TIMER:
     570
     571            switch (wParam)
     572            {
     573                case WM_VBOX_CHECK_HOSTVERSION:
     574                    if (RT_SUCCESS(VBoxCheckHostVersion()))
     575                    {
     576                        /* After successful run we don't need to check again. */
     577                        KillTimer(gToolWindow, WM_VBOX_CHECK_HOSTVERSION);
     578                    }
     579                    return 0;
     580
     581                default:
     582                    break;
     583            }
     584
    556585            break;
    557586
  • trunk/src/VBox/Additions/WINNT/VBoxTray/VBoxTray.h

    r21888 r23053  
    3737#include <VBox/VBoxGuestLib.h>
    3838
    39 #define WM_VBOX_RESTORED                     0x2005
    40 #define WM_VBOX_CHECK_VRDP                   0x2006
     39#define WM_VBOX_RESTORED                WM_APP + 1
     40#define WM_VBOX_CHECK_VRDP              WM_APP + 2
     41#define WM_VBOX_CHECK_HOSTVERSION       WM_APP + 3
     42
     43#define ID_TRAYICON                     2000
    4144
    4245
     
    6568
    6669
    67 extern HWND  gToolWindow;
     70extern HWND         gToolWindow;
     71extern HINSTANCE    gInstance;
    6872
    6973extern void VBoxServiceReloadCursor(void);
  • trunk/src/VBox/Additions/WINNT/VBoxTray/helpers.cpp

    r8155 r23053  
    2222#include <windows.h>
    2323
     24#include <iprt/string.h>
     25#include <VBox/VBoxGuestLib.h>
     26
     27#include <VBoxGuestInternal.h>
     28
    2429#include "helpers.h"
     30#include "resource.h"
    2531
    2632static unsigned nextAdjacentRectXP (RECTL *paRects, unsigned nRects, unsigned iRect)
     
    8288    paNewRects[iResized].right += NewWidth - (paNewRects[iResized].right - paNewRects[iResized].left);
    8389    paNewRects[iResized].bottom += NewHeight - (paNewRects[iResized].bottom - paNewRects[iResized].top);
    84    
    85     /* Verify all pairs of originally adjacent rectangles for all 4 directions. 
     90
     91    /* Verify all pairs of originally adjacent rectangles for all 4 directions.
    8692     * If the pair has a "good" delta (that is the first rectangle intersects the second)
    8793     * at a direction and the second rectangle is not primary one (which can not be moved),
    8894     * move the second rectangle to make it adjacent to the first one.
    8995     */
    90    
     96
    9197    /* X positive. */
    9298    unsigned iRect;
     
    96102        unsigned iNextRect = nextAdjacentRectXP (paRects, nRects, iRect);
    97103        DDCLOG(("next %d -> %d\n", iRect, iNextRect));
    98        
     104
    99105        if (iNextRect == ~0 || iNextRect == iPrimary)
    100106        {
    101107            continue;
    102108        }
    103        
     109
    104110        /* Check whether there is an X intesection between these adjacent rects in the new rectangles
    105111         * and fix the intersection if delta is "good".
    106112         */
    107113        int delta = paNewRects[iRect].right - paNewRects[iNextRect].left;
    108        
     114
    109115        if (delta > 0)
    110116        {
     
    112118                     paNewRects[iRect].right, paNewRects[iNextRect].left,
    113119                     delta));
    114            
     120
    115121            paNewRects[iNextRect].left += delta;
    116122            paNewRects[iNextRect].right += delta;
    117123        }
    118124    }
    119    
     125
    120126    /* X negative. */
    121127    for (iRect = 0; iRect < nRects; iRect++)
     
    124130        unsigned iNextRect = nextAdjacentRectXN (paRects, nRects, iRect);
    125131        DDCLOG(("next %d -> %d\n", iRect, iNextRect));
    126        
     132
    127133        if (iNextRect == ~0 || iNextRect == iPrimary)
    128134        {
    129135            continue;
    130136        }
    131        
     137
    132138        /* Check whether there is an X intesection between these adjacent rects in the new rectangles
    133139         * and fix the intersection if delta is "good".
    134140         */
    135141        int delta = paNewRects[iRect].left - paNewRects[iNextRect].right;
    136        
     142
    137143        if (delta < 0)
    138144        {
     
    140146                     paNewRects[iRect].left, paNewRects[iNextRect].right,
    141147                     delta));
    142            
     148
    143149            paNewRects[iNextRect].left += delta;
    144150            paNewRects[iNextRect].right += delta;
    145151        }
    146152    }
    147    
     153
    148154    /* Y positive (in the computer sence, top->down). */
    149155    for (iRect = 0; iRect < nRects; iRect++)
     
    152158        unsigned iNextRect = nextAdjacentRectYP (paRects, nRects, iRect);
    153159        DDCLOG(("next %d -> %d\n", iRect, iNextRect));
    154        
     160
    155161        if (iNextRect == ~0 || iNextRect == iPrimary)
    156162        {
    157163            continue;
    158164        }
    159        
     165
    160166        /* Check whether there is an Y intesection between these adjacent rects in the new rectangles
    161167         * and fix the intersection if delta is "good".
    162168         */
    163169        int delta = paNewRects[iRect].bottom - paNewRects[iNextRect].top;
    164        
     170
    165171        if (delta > 0)
    166172        {
     
    168174                     paNewRects[iRect].bottom, paNewRects[iNextRect].top,
    169175                     delta));
    170            
     176
    171177            paNewRects[iNextRect].top += delta;
    172178            paNewRects[iNextRect].bottom += delta;
    173179        }
    174180    }
    175    
     181
    176182    /* Y negative (in the computer sence, down->top). */
    177183    for (iRect = 0; iRect < nRects; iRect++)
     
    180186        unsigned iNextRect = nextAdjacentRectYN (paRects, nRects, iRect);
    181187        DDCLOG(("next %d -> %d\n", iRect, iNextRect));
    182        
     188
    183189        if (iNextRect == ~0 || iNextRect == iPrimary)
    184190        {
    185191            continue;
    186192        }
    187        
     193
    188194        /* Check whether there is an Y intesection between these adjacent rects in the new rectangles
    189195         * and fix the intersection if delta is "good".
    190196         */
    191197        int delta = paNewRects[iRect].top - paNewRects[iNextRect].bottom;
    192        
     198
    193199        if (delta < 0)
    194200        {
     
    196202                     paNewRects[iRect].top, paNewRects[iNextRect].bottom,
    197203                     delta));
    198            
     204
    199205            paNewRects[iNextRect].top += delta;
    200206            paNewRects[iNextRect].bottom += delta;
    201207        }
    202208    }
    203    
     209
    204210    memcpy (paRects, paNewRects, sizeof (RECTL) * nRects);
    205211    return;
    206212}
     213
     214int showBalloonTip (HINSTANCE hInst, HWND hWnd, UINT uID, const char *pszMsg, const char *pszTitle, UINT uTimeout, DWORD dwInfoFlags)
     215{
     216    NOTIFYICONDATA niData;
     217    niData.cbSize = sizeof(NOTIFYICONDATA);
     218    niData.uFlags = NIF_INFO;
     219    niData.hWnd = hWnd;
     220    niData.uID = uID;
     221    niData.uTimeout = uTimeout;
     222    if (dwInfoFlags == 0)
     223        dwInfoFlags = NIIF_INFO;
     224    niData.dwInfoFlags = dwInfoFlags;
     225
     226    OSVERSIONINFO   info;
     227    DWORD           dwMajorVersion = 5; /* default XP */
     228
     229    info.dwOSVersionInfoSize = sizeof(info);
     230    if (FALSE == GetVersionEx(&info))
     231        return FALSE;
     232
     233    if (info.dwMajorVersion >= 5)
     234    {
     235        niData.uFlags |= NIF_ICON;
     236        if (   info.dwMajorVersion == 5
     237            && info.dwMinorVersion == 1) /* WinXP */
     238        {
     239            //niData.dwInfoFlags = NIIF_USER; /* Use an own icon instead of the default one */
     240            niData.hIcon = LoadIcon(hInst, MAKEINTRESOURCE(IDI_VIRTUALBOX));
     241        }
     242#ifdef BALLOON_WITH_VISTA_TOOLTIP_ICON
     243        else if (info.dwMajorVersion == 6) /* Vista and up */
     244        {
     245            niData.dwInfoFlags = NIIF_USER | NIIF_LARGE_ICON; /* Use an own icon instead of the default one */
     246            niData.hBalloonIcon = LoadIcon(hInst, MAKEINTRESOURCE(IDI_VIRTUALBOX));
     247        }
     248#endif
     249    }
     250
     251    strcpy(niData.szInfo, pszMsg ? pszMsg : "");
     252    strcpy(niData.szInfoTitle, pszTitle ? pszTitle : "");
     253
     254    if (!Shell_NotifyIcon(NIM_MODIFY, &niData))
     255        return GetLastError();
     256    return 0;
     257}
     258
     259/** @todo move this in guest lib, also used in a similar way in VBoxService */
     260int getAdditionsVersion(char *pszVer, size_t cbSizeVer, char *pszRev, size_t cbSizeRev)
     261{
     262    HKEY hKey;
     263    int rc;
     264
     265    /* Check the new path first. */
     266    rc = RegOpenKeyEx(HKEY_LOCAL_MACHINE, "SOFTWARE\\Sun\\VirtualBox Guest Additions", 0, KEY_READ, &hKey);
     267#ifdef RT_ARCH_AMD64
     268    if (rc != ERROR_SUCCESS)
     269    {
     270        /* Check Wow6432Node (for new entries). */
     271        rc = RegOpenKeyEx(HKEY_LOCAL_MACHINE, "SOFTWARE\\Wow6432Node\\Sun\\VirtualBox Guest Additions", 0, KEY_READ, &hKey);
     272    }
     273#endif
     274
     275    /* Still no luck? Then try the old xVM paths ... */
     276    if (RT_FAILURE(rc))
     277    {
     278        rc = RegOpenKeyEx(HKEY_LOCAL_MACHINE, "SOFTWARE\\Sun\\xVM VirtualBox Guest Additions", 0, KEY_READ, &hKey);
     279#ifdef RT_ARCH_AMD64
     280        if (rc != ERROR_SUCCESS)
     281        {
     282            /* Check Wow6432Node (for new entries). */
     283            rc = RegOpenKeyEx(HKEY_LOCAL_MACHINE, "SOFTWARE\\Wow6432Node\\Sun\\xVM VirtualBox Guest Additions", 0, KEY_READ, &hKey);
     284        }
     285#endif
     286    }
     287
     288    /* Did we get something worth looking at? */
     289    if (RT_SUCCESS(rc))
     290    {
     291        DWORD dwSize;
     292        DWORD dwType;
     293
     294        /* Revision. */
     295        dwSize = cbSizeRev;
     296        rc = RegQueryValueEx(hKey, "Revision", NULL, &dwType, (BYTE*)(LPCTSTR)pszRev, &dwSize);
     297        /* Version. */
     298        dwSize = cbSizeVer;
     299        rc = RegQueryValueEx(hKey, "Version", NULL, &dwType, (BYTE*)(LPCTSTR)pszVer, &dwSize);
     300    }
     301
     302    if (NULL != hKey)
     303        RegCloseKey(hKey);
     304
     305    return rc;
     306}
  • trunk/src/VBox/Additions/WINNT/VBoxTray/helpers.h

    r10800 r23053  
    3232
    3333void resizeRect(RECTL *paRects, unsigned nRects, unsigned iPrimary, unsigned iResized, int NewWidth, int NewHeight);
     34int showBalloonTip (HINSTANCE hInst, HWND hWnd, UINT uID, const char *pszMsg, const char *pszTitle, UINT uTimeout, DWORD dwInfoFlags);
     35int getAdditionsVersion(char *pszVer, size_t cbSizeVer, char *pszRev, size_t cbSizeRev);
    3436
    3537#endif /* !___VBOXTRAY_HELPERS_H */
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette