VirtualBox

Changeset 34025 in vbox


Ignore:
Timestamp:
Nov 12, 2010 10:03:41 AM (14 years ago)
Author:
vboxsync
Message:

VBoxTray: Implemented global message registration/handling mechanism, added a global message for sending external messages to the systray balloon, refactoring, some bugfixes.

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

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Additions/WINNT/VBoxTray/VBoxDisplay.cpp

    r33966 r34025  
    688688            }
    689689            if (waitEvent.u32EventFlagsOut & VMMDEV_EVENT_MOUSE_CAPABILITIES_CHANGED)
    690                 VBoxServiceReloadCursor();
     690                hlpReloadCursor();
    691691        } else
    692692        {
  • trunk/src/VBox/Additions/WINNT/VBoxTray/VBoxHelpers.cpp

    r33966 r34025  
    2626#include "resource.h"
    2727
     28
     29
     30/**
     31 * Attempt to force Windows to reload the cursor image by attaching to the
     32 * thread of the window currently under the mouse, hiding the cursor and
     33 * showing it again.  This could fail to work in any number of ways (no
     34 * window under the cursor, the cursor has moved to a different window while
     35 * we are processing), but we just accept this, as the cursor will be reloaded
     36 * at some point anyway.
     37 */
     38void hlpReloadCursor(void)
     39{
     40    POINT mousePos;
     41    HWND hWin;
     42    DWORD hThread, hCurrentThread;
     43
     44    GetCursorPos(&mousePos);
     45    hWin = WindowFromPoint(mousePos);
     46    if (hWin)
     47    {
     48        hThread = GetWindowThreadProcessId(hWin, NULL);
     49        hCurrentThread = GetCurrentThreadId();
     50        if (hCurrentThread != hThread)
     51            AttachThreadInput(hCurrentThread, hThread, TRUE);
     52    }
     53    ShowCursor(false);
     54    ShowCursor(true);
     55    if (hWin && (hCurrentThread != hThread))
     56        AttachThreadInput(hCurrentThread, hThread, FALSE);
     57}
     58
    2859static unsigned hlpNextAdjacentRectXP(RECTL *paRects, unsigned nRects, unsigned uRect)
    2960{
     
    208239{
    209240    NOTIFYICONDATA niData;
     241    ZeroMemory(&niData, sizeof(NOTIFYICONDATA));
    210242    niData.cbSize = sizeof(NOTIFYICONDATA);
    211     niData.uFlags = NIF_INFO;
     243    niData.uFlags = NIF_INFO; /* Display a balloon notification. */
    212244    niData.hWnd = hWnd;
    213245    niData.uID = uID;
     246    /* If not timeout set, set it to 5sec. */
     247    if (uTimeout == 0)
     248        uTimeout = 5000;
    214249    niData.uTimeout = uTimeout;
     250    /* If no info flag (info, warning, error) set,
     251     * set it to info by default. */
    215252    if (dwInfoFlags == 0)
    216253        dwInfoFlags = NIIF_INFO;
    217254    niData.dwInfoFlags = dwInfoFlags;
    218255
    219     OSVERSIONINFO   info;
    220     DWORD           dwMajorVersion = 5; /* default XP */
    221 
    222     info.dwOSVersionInfoSize = sizeof(info);
    223     if (FALSE == GetVersionEx(&info))
    224         return FALSE;
    225 
    226     if (info.dwMajorVersion >= 5)
    227     {
    228         niData.uFlags |= NIF_ICON;
    229         if (   info.dwMajorVersion == 5
    230             && info.dwMinorVersion == 1) /* WinXP */
    231         {
    232             //niData.dwInfoFlags = NIIF_USER; /* Use an own icon instead of the default one */
    233             niData.hIcon = LoadIcon(hInst, MAKEINTRESOURCE(IDI_VIRTUALBOX));
    234         }
    235 #ifdef BALLOON_WITH_VISTA_TOOLTIP_ICON
    236         else if (info.dwMajorVersion == 6) /* Vista and up */
    237         {
    238             niData.dwInfoFlags = NIIF_USER | NIIF_LARGE_ICON; /* Use an own icon instead of the default one */
    239             niData.hBalloonIcon = LoadIcon(hInst, MAKEINTRESOURCE(IDI_VIRTUALBOX));
    240         }
    241 #endif
    242     }
    243 
    244     strcpy(niData.szInfo, pszMsg ? pszMsg : "");
    245     strcpy(niData.szInfoTitle, pszTitle ? pszTitle : "");
     256    /* Do we want to have */
     257
     258    /* Get running OS version. */
     259    OSVERSIONINFO osInfo;
     260    osInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
     261    if (FALSE == GetVersionEx(&osInfo))
     262        return RTErrConvertFromWin32(GetLastError());
     263
     264    /* Is the current OS supported (at least WinXP) for displaying
     265     * our own icon and do we actually *want* to display our own stuff? */
     266    if (   osInfo.dwMajorVersion >= 5
     267        && (dwInfoFlags & NIIF_INFO))
     268    {
     269        /* Load (or retrieve handle of) the app's icon. */
     270        HICON hIcon = LoadIcon(hInst, MAKEINTRESOURCE(IDI_VIRTUALBOX));
     271        if (hIcon)
     272            niData.dwInfoFlags = NIIF_USER; /* Use an own notification icon. */
     273
     274        if (   osInfo.dwMajorVersion == 5
     275            && osInfo.dwMinorVersion == 1) /* WinXP. */
     276        {
     277            /* Use an own icon instead of the default one. */
     278            niData.hIcon = hIcon;
     279        }
     280        else if (osInfo.dwMajorVersion == 6) /* Vista and up. */
     281        {
     282            /* Use an own icon instead of the default one. */
     283            niData.dwInfoFlags |= NIIF_LARGE_ICON; /* Use a  large icon if available! */
     284            niData.hIcon        = hIcon;
     285            niData.hBalloonIcon = hIcon;
     286        }
     287    }
     288    else
     289    {
     290        /* This might be a warning, error message or a to old OS. Use the
     291         * standard icons provided by Windows (if any). */
     292    }
     293
     294    strcpy(niData.szInfo, pszMsg ? pszMsg : "-");
     295    strcpy(niData.szInfoTitle, pszTitle ? pszTitle : "Information");
    246296
    247297    if (!Shell_NotifyIcon(NIM_MODIFY, &niData))
    248         return GetLastError();
    249     return 0;
    250 }
    251 
     298    {
     299        DWORD dwErr = GetLastError();
     300        return RTErrConvertFromWin32(dwErr);
     301    }
     302    return VINF_SUCCESS;
     303}
     304
  • trunk/src/VBox/Additions/WINNT/VBoxTray/VBoxHelpers.h

    r33966 r34025  
    2727#endif /* !DEBUG_DISPLAY_CHANGE */
    2828
     29extern void hlpReloadCursor(void);
    2930extern void hlpResizeRect(RECTL *paRects, unsigned nRects, unsigned uPrimary, unsigned uResized, int iNewWidth, int iNewHeight);
    3031extern int hlpShowBalloonTip(HINSTANCE hInst, HWND hWnd, UINT uID, const char *pszMsg, const char *pszTitle, UINT uTimeout, DWORD dwInfoFlags);
  • trunk/src/VBox/Additions/WINNT/VBoxTray/VBoxHostVersion.cpp

    r33966 r34025  
    4949                _snprintf(szMsg, sizeof(szMsg), "Your guest is currently running the Guest Additions version %s. "
    5050                                                "We recommend updating to the latest version (%s) by choosing the "
    51                                                 "install option from the Devices menu.", pszGuestVersion, pszHostVersion);
     51                                                "install option from the Devices menu.", "1", "2");
    5252
    53                 rc = hlpShowBalloonTip(gInstance, gToolWindow, ID_TRAYICON, szMsg, szTitle, 5000, 0);
     53                rc = hlpShowBalloonTip(gInstance, gToolWindow, ID_TRAYICON,
     54                                       szMsg, szTitle,
     55                                       5000 /* Time to display in msec */, NIIF_INFO);
    5456                if (RT_FAILURE(rc))
    5557                    Log(("VBoxTray: Guest Additions update found; however: could not show version notifier balloon tooltip! rc = %d\n", rc));
  • trunk/src/VBox/Additions/WINNT/VBoxTray/VBoxTray.cpp

    r33966 r34025  
    5151DWORD                 gMajorVersion;
    5252
     53/* Global message handler prototypes. */
     54int vboxTrayGlMsgTaskbarCreated(LPARAM lParam, WPARAM wParam);
     55int vboxTrayGlMsgShowBalloonMsg(LPARAM lParam, WPARAM wParam);
     56
    5357/* Prototypes */
     58int vboxTrayCreateTrayIcon(void);
    5459VOID DisplayChangeThread(void *dummy);
    5560LRESULT CALLBACK VBoxToolWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
     61
    5662
    5763/* The service table. */
     
    6268        VBoxDisplayInit,
    6369        VBoxDisplayThread,
    64         VBoxDisplayDestroy,
     70        VBoxDisplayDestroy
    6571    },
    6672    {
     
    8187        VBoxRestoreInit,
    8288        VBoxRestoreThread,
    83         VBoxRestoreDestroy,
     89        VBoxRestoreDestroy
    8490    },
    8591#endif
     
    8894        VBoxVRDPInit,
    8995        VBoxVRDPThread,
    90         VBoxVRDPDestroy,
     96        VBoxVRDPDestroy
    9197    },
    9298    {
     
    95101};
    96102
    97 static BOOL vboxTrayIconAdd()
     103/* The global message table. */
     104static VBOXGLOBALMESSAGE s_vboxGlobalMessageTable[] =
     105{
     106    /* Windows specific stuff. */
     107    {
     108        "TaskbarCreated",
     109        vboxTrayGlMsgTaskbarCreated
     110    },
     111
     112    /* VBoxTray specific stuff. */
     113    {
     114        "VBoxTrayShowBalloonMsg",
     115        vboxTrayGlMsgShowBalloonMsg
     116    },
     117
     118    {
     119        NULL
     120    }
     121};
     122
     123/**
     124 * Gets called whenever the Windows main taskbar
     125 * get (re-)created. Nice to install our tray icon.
     126 *
     127 * @return  IPRT status code.
     128 * @param   wParam
     129 * @param   lParam
     130 */
     131static int vboxTrayGlMsgTaskbarCreated(LPARAM lParam, WPARAM wParam)
     132{
     133    return vboxTrayCreateTrayIcon();
     134}
     135
     136/**
     137 * Shows a balloon tooltip message in VBoxTray's
     138 * message area in the Windows main taskbar.
     139 *
     140 * @return  IPRT status code.
     141 * @param   wParam
     142 * @param   lParam
     143 */
     144static int vboxTrayGlMsgShowBalloonMsg(LPARAM wParam, WPARAM lParam)
     145{
     146    int rc = hlpShowBalloonTip(gInstance, gToolWindow, ID_TRAYICON,
     147                               (char*)wParam /* Ugly hack! */, "Foo",
     148                               5000 /* Time to display in msec */, NIIF_INFO);
     149    /*
     150     * If something went wrong while displaying, log the message into the
     151     * the release log so that the user still is being informed, at least somehow.
     152     */
     153    if (RT_FAILURE(rc))
     154        LogRel(("VBoxTray Information: %s\n", "Foo"));
     155    return rc;
     156}
     157
     158static int vboxTrayCreateTrayIcon(void)
    98159{
    99160    HICON hIcon = LoadIcon(gInstance, MAKEINTRESOURCE(IDI_VIRTUALBOX));
    100161    if (hIcon == NULL)
    101162    {
    102         Log(("VBoxTray: Could not load tray icon, err %08X\n", GetLastError()));
    103         return FALSE;
     163        DWORD dwErr = GetLastError();
     164        Log(("VBoxTray: Could not load tray icon, error %08X\n", dwErr));
     165        return RTErrConvertFromWin32(dwErr);
    104166    }
    105167
     
    116178            VBOX_PRODUCT, VBOX_VERSION_MAJOR, VBOX_VERSION_MINOR, VBOX_VERSION_BUILD, VBOX_SVN_REV);
    117179
    118     BOOL fCreated = Shell_NotifyIcon(NIM_ADD, &gNotifyIconData);
    119     if (!fCreated)
    120     {
    121         Log(("VBoxTray: Could not create tray icon, err %08X\n", GetLastError()));
     180    int rc = VINF_SUCCESS;
     181    if (!Shell_NotifyIcon(NIM_ADD, &gNotifyIconData))
     182    {
     183        DWORD dwErr = GetLastError();
     184        Log(("VBoxTray: Could not create tray icon, error = %08X\n", dwErr));
     185        rc = RTErrConvertFromWin32(dwErr);
    122186        RT_ZERO(gNotifyIconData);
    123187    }
     
    125189    if (hIcon)
    126190        DestroyIcon(hIcon);
    127     return fCreated;
    128 }
    129 
    130 static void vboxTrayIconRemove()
     191    return rc;
     192}
     193
     194static void vboxTrayRemoveTrayIcon()
    131195{
    132196    if (gNotifyIconData.cbSize > 0)
     
    145209}
    146210
    147 static int vboxStartServices(VBOXSERVICEENV *pEnv, VBOXSERVICEINFO *pTable)
     211static int vboxTrayStartServices(VBOXSERVICEENV *pEnv, VBOXSERVICEINFO *pTable)
    148212{
    149213    Log(("VBoxTray: Starting services ...\n"));
     
    209273}
    210274
    211 static void vboxStopServices(VBOXSERVICEENV *pEnv, VBOXSERVICEINFO *pTable)
     275static void vboxTrayStopServices(VBOXSERVICEENV *pEnv, VBOXSERVICEINFO *pTable)
    212276{
    213277    if (!pEnv->hStopEvent)
     
    242306}
    243307
    244 
    245 /**
    246  * Attempt to force Windows to reload the cursor image by attaching to the
    247  * thread of the window currently under the mouse, hiding the cursor and
    248  * showing it again.  This could fail to work in any number of ways (no
    249  * window under the cursor, the cursor has moved to a different window while
    250  * we are processing), but we just accept this, as the cursor will be reloaded
    251  * at some point anyway.
    252  */
    253 void VBoxServiceReloadCursor(void)
    254 {
    255     LogFlowFunc(("\n"));
    256     POINT mousePos;
    257     HWND hWin;
    258     DWORD hThread, hCurrentThread;
    259 
    260     GetCursorPos(&mousePos);
    261     hWin = WindowFromPoint(mousePos);
    262     if (hWin)
    263     {
    264         hThread = GetWindowThreadProcessId(hWin, NULL);
    265         hCurrentThread = GetCurrentThreadId();
    266         if (hCurrentThread != hThread)
    267             AttachThreadInput(hCurrentThread, hThread, TRUE);
    268     }
    269     ShowCursor(false);
    270     ShowCursor(true);
    271     if (hWin && (hCurrentThread != hThread))
    272         AttachThreadInput(hCurrentThread, hThread, FALSE);
    273     LogFlowFunc(("exiting\n"));
    274 }
    275 
     308int vboxTrayRegisterGlobalMessages(PVBOXGLOBALMESSAGE pTable)
     309{
     310    int rc = VINF_SUCCESS;
     311    if (pTable == NULL) /* No table to register? Skip. */
     312        return rc;
     313    while (   pTable->pszName
     314           && RT_SUCCESS(rc))
     315    {
     316        /* Register global accessible window messages. */
     317        pTable->uMsgID = RegisterWindowMessage(TEXT(pTable->pszName));
     318        if (!pTable->uMsgID)
     319        {
     320            DWORD dwErr = GetLastError();
     321            Log(("VBoxTray: Registering global message \"%s\" failed, error = %08X\n", dwErr));
     322            rc = RTErrConvertFromWin32(dwErr);
     323        }
     324
     325        /* Advance to next table element. */
     326        pTable++;
     327    }
     328    return rc;
     329}
     330
     331bool vboxTrayHandleGlobalMessages(PVBOXGLOBALMESSAGE pTable, UINT uMsg,
     332                                  WPARAM wParam, LPARAM lParam)
     333{
     334    if (pTable == NULL)
     335        return false;
     336    while (pTable->pszName)
     337    {
     338        if (pTable->uMsgID == uMsg)
     339        {
     340            if (pTable->pfnHandler)
     341                pTable->pfnHandler(wParam, lParam);
     342            return true;
     343        }
     344
     345        /* Advance to next table element. */
     346        pTable++;
     347    }
     348    return false;
     349}
    276350
    277351void WINAPI VBoxServiceStart(void)
     
    280354
    281355    VBOXSERVICEENV svcEnv;
    282 
    283     DWORD status = NO_ERROR;
     356    DWORD dwErr = NO_ERROR;
    284357
    285358    /* Open VBox guest driver. */
     
    293366    if (gVBoxDriver == INVALID_HANDLE_VALUE)
    294367    {
    295         LogRel(("VBoxTray: Could not open VirtualBox Guest Additions driver! Please install / start it first! rc = %d\n", GetLastError()));
    296         status = ERROR_GEN_FAILURE;
    297     }
    298 
    299     Log(("VBoxTray: Driver Handle = %p, Status = %p\n", gVBoxDriver, status));
    300 
    301     if (status == NO_ERROR)
     368        dwErr = GetLastError();
     369        LogRel(("VBoxTray: Could not open VirtualBox Guest Additions driver! Please install / start it first! Error = %08X\n", dwErr));
     370    }
     371
     372    if (dwErr == NO_ERROR)
    302373    {
    303374        /* Create a custom window class. */
     
    307378        windowClass.hInstance     = gInstance;
    308379        windowClass.hCursor       = LoadCursor(NULL, IDC_ARROW);
    309         windowClass.lpszClassName = "VirtualBoxTool";
     380        windowClass.lpszClassName = "VBoxTrayToolWndClass";
    310381        if (!RegisterClass(&windowClass))
    311             status = GetLastError();
    312     }
    313 
    314     Log(("VBoxTray: Class st %p\n", status));
    315 
    316     if (status == NO_ERROR)
     382        {
     383            dwErr = GetLastError();
     384            Log(("VBoxTray: Registering invisible tool window failed, error = %08X\n", dwErr));
     385        }
     386    }
     387
     388    if (dwErr == NO_ERROR)
    317389    {
    318390        /* Create our (invisible) tool window. */
     391        /* Note: The window name ("VBoxTrayToolWnd") and class ("VBoxTrayToolWndClass") is
     392         * needed for posting globally registered messages to VBoxTray and must not be
     393         * changed! Otherwise things get broken! */
    319394        gToolWindow = CreateWindowEx(WS_EX_TOOLWINDOW | WS_EX_TRANSPARENT | WS_EX_TOPMOST,
    320                                      "VirtualBoxTool", "VirtualBoxTool",
     395                                     "VBoxTrayToolWndClass", "VBoxTrayToolWnd",
    321396                                     WS_POPUPWINDOW,
    322397                                     -200, -200, 100, 100, NULL, NULL, gInstance, NULL);
    323398        if (!gToolWindow)
    324             status = GetLastError();
     399        {
     400            dwErr = GetLastError();
     401            Log(("VBoxTray: Creating invisible tool window failed, error = %08X\n", dwErr));
     402        }
    325403        else
    326             VBoxServiceReloadCursor();
    327     }
    328 
    329     Log(("VBoxTray: Window Handle = %p, Status = %p\n", gToolWindow, status));
     404        {
     405            hlpReloadCursor();
     406        }
     407    }
     408
     409    Log(("VBoxTray: Window Handle = %p, Status = %p\n", gToolWindow, dwErr));
    330410
    331411    OSVERSIONINFO info;
     
    334414    if (GetVersionEx(&info))
    335415    {
    336         Log(("VBoxTray: Windows version major %d minor %d\n", info.dwMajorVersion, info.dwMinorVersion));
     416        Log(("VBoxTray: Windows version %ld.%ld\n", info.dwMajorVersion, info.dwMinorVersion));
    337417        gMajorVersion = info.dwMajorVersion;
    338418    }
    339419
    340     if (status == NO_ERROR)
     420    if (dwErr == NO_ERROR)
    341421    {
    342422        gStopSem = CreateEvent(NULL, TRUE, FALSE, NULL);
    343423        if (gStopSem == NULL)
    344424        {
    345             Log(("VBoxTray: CreateEvent for Stopping failed: rc = %d\n", GetLastError()));
     425            Log(("VBoxTray: CreateEvent for stopping VBoxTray failed, error = %08X\n", GetLastError()));
    346426            return;
    347427        }
     
    358438        ret = SetSecurityDescriptorDacl(SecAttr.lpSecurityDescriptor, TRUE, 0, FALSE);
    359439        if (!ret)
    360             Log(("VBoxTray: SetSecurityDescriptorDacl failed with %d\n", GetLastError()));
     440            Log(("VBoxTray: SetSecurityDescriptorDacl failed with error = %08X\n", GetLastError()));
    361441
    362442        /* For Vista and up we need to change the integrity of the security descriptor too */
     
    383463                                                                                  SDDL_REVISION_1, &pSD, NULL);
    384464                    if (!ret)
    385                         Log(("VBoxTray: ConvertStringSecurityDescriptorToSecurityDescriptorA failed with %d\n", GetLastError()));
     465                        Log(("VBoxTray: ConvertStringSecurityDescriptorToSecurityDescriptorA failed with error = %08X\n", GetLastError()));
    386466
    387467                    ret = GetSecurityDescriptorSacl(pSD, &fSaclPresent, &pSacl, &fSaclDefaulted);
    388468                    if (!ret)
    389                         Log(("VBoxTray: GetSecurityDescriptorSacl failed with %d\n", GetLastError()));
     469                        Log(("VBoxTray: GetSecurityDescriptorSacl failed with error = %08X\n", GetLastError()));
    390470
    391471                    ret = SetSecurityDescriptorSacl(SecAttr.lpSecurityDescriptor, TRUE, pSacl, FALSE);
    392472                    if (!ret)
    393                         Log(("VBoxTray: SetSecurityDescriptorSacl failed with %d\n", GetLastError()));
     473                        Log(("VBoxTray: SetSecurityDescriptorSacl failed with error = %08X\n", GetLastError()));
    394474                }
    395475            }
     
    401481            if (ghSeamlessNotifyEvent == NULL)
    402482            {
    403                 Log(("VBoxTray: CreateEvent for Seamless failed: rc = %d\n", GetLastError()));
     483                Log(("VBoxTray: CreateEvent for Seamless failed, error = %08X\n", GetLastError()));
    404484                return;
    405485            }
     
    414494
    415495    /* initializes disp-if to default (XPDM) mode */
    416     status = VBoxDispIfInit(&svcEnv.dispIf);
     496    dwErr = VBoxDispIfInit(&svcEnv.dispIf);
    417497#ifdef VBOX_WITH_WDDM
    418498    /*
     
    422502#endif
    423503
    424     if (status == NO_ERROR)
    425     {
    426         int rc = vboxStartServices(&svcEnv, vboxServiceTable);
    427 
     504    if (dwErr == NO_ERROR)
     505    {
     506        int rc = vboxTrayStartServices(&svcEnv, vboxServiceTable);
    428507        if (RT_FAILURE (rc))
    429508        {
    430             status = ERROR_GEN_FAILURE;
     509            dwErr = ERROR_GEN_FAILURE;
    431510        }
    432511    }
    433512
    434513    /* terminate service if something went wrong */
    435     if (status != NO_ERROR)
    436     {
    437         vboxStopServices(&svcEnv, vboxServiceTable);
     514    if (dwErr != NO_ERROR)
     515    {
     516        vboxTrayStopServices(&svcEnv, vboxServiceTable);
    438517        return;
    439518    }
    440519
    441     if (   vboxTrayIconAdd()
     520    int rc = vboxTrayCreateTrayIcon();
     521    if (   RT_SUCCESS(rc)
    442522        && gMajorVersion >= 5) /* Only for W2K and up ... */
    443523    {
     
    450530    }
    451531
     532    /* Do the Shared Folders auto-mounting stuff. */
    452533    VBoxSharedFoldersAutoMount();
    453534
     
    510591    Log(("VBoxTray: Returned from main loop, exiting ...\n"));
    511592
    512     vboxTrayIconRemove();
     593    vboxTrayRemoveTrayIcon();
    513594
    514595    Log(("VBoxTray: Waiting for display change thread ...\n"));
    515596
    516     vboxStopServices(&svcEnv, vboxServiceTable);
     597    vboxTrayStopServices(&svcEnv, vboxServiceTable);
    517598
    518599    Log(("VBoxTray: Destroying tool window ...\n"));
     
    521602    DestroyWindow(gToolWindow);
    522603
    523     UnregisterClass("VirtualBoxTool", gInstance);
     604    UnregisterClass("VBoxTrayToolWndClass", gInstance);
    524605
    525606    CloseHandle(gVBoxDriver);
     
    540621    /* Do not use a global namespace ("Global\\") for mutex name here, will blow up NT4 compatibility! */
    541622    HANDLE hMutexAppRunning = CreateMutex(NULL, FALSE, "VBoxTray");
    542     if (   (hMutexAppRunning != NULL)
    543         && (GetLastError() == ERROR_ALREADY_EXISTS))
    544     {
    545       /* Close the mutex for this application instance. */
    546       CloseHandle (hMutexAppRunning);
    547       hMutexAppRunning = NULL;
    548       return 0;
     623    if (   hMutexAppRunning != NULL
     624        && GetLastError() == ERROR_ALREADY_EXISTS)
     625    {
     626        /* Close the mutex for this application instance. */
     627        CloseHandle (hMutexAppRunning);
     628        hMutexAppRunning = NULL;
     629        return 0;
    549630    }
    550631
     
    565646
    566647    /* Release instance mutex. */
    567     if (hMutexAppRunning != NULL) {
     648    if (hMutexAppRunning != NULL)
     649    {
    568650        CloseHandle(hMutexAppRunning);
    569651        hMutexAppRunning = NULL;
     
    577659 * Window procedure for our tool window
    578660 */
    579 LRESULT CALLBACK VBoxToolWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
    580 {
    581     static UINT s_uTaskbarCreated = 0;
    582 
    583     switch (msg)
     661LRESULT CALLBACK VBoxToolWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
     662{
     663    switch (uMsg)
    584664    {
    585665        case WM_CREATE:
     666        {
    586667            Log(("VBoxTray: Tool window created\n"));
    587             s_uTaskbarCreated = RegisterWindowMessage(TEXT("TaskbarCreated"));
    588             if (!s_uTaskbarCreated)
    589                 Log(("VBoxTray: Cannot register message \"TaskbarCreated\"! Error = %ld\n", GetLastError()));
    590             break;
     668
     669            int rc = vboxTrayRegisterGlobalMessages(&s_vboxGlobalMessageTable[0]);
     670            if (RT_FAILURE(rc))
     671                Log(("VBoxTray: Error registering global window messages, rc=%Rrc\n", rc));
     672            return 0;
     673        }
    591674
    592675        case WM_CLOSE:
    593             break;
     676            return 0;
    594677
    595678        case WM_DESTROY:
    596679            Log(("VBoxTray: Tool window destroyed\n"));
    597680            KillTimer(gToolWindow, TIMERID_VBOXTRAY_CHECK_HOSTVERSION);
    598             break;
     681            return 0;
    599682
    600683        case WM_TIMER:
    601684            switch (wParam)
    602685            {
    603                 case WM_VBOXTRAY_CHECK_HOSTVERSION:
     686                case TIMERID_VBOXTRAY_CHECK_HOSTVERSION:
    604687                    if (RT_SUCCESS(VBoxCheckHostVersion()))
    605688                    {
     
    612695                    break;
    613696            }
    614 
    615             break;
     697            break; /* Make sure other timers get processed the usual way! */
    616698
    617699        case WM_VBOXTRAY_TRAY_ICON:
     
    624706                    break;
    625707            }
    626             break;
     708            return 0;
    627709
    628710        case WM_VBOX_INSTALL_SEAMLESS_HOOK:
    629711            VBoxSeamlessInstallHook();
    630             break;
     712            return 0;
    631713
    632714        case WM_VBOX_REMOVE_SEAMLESS_HOOK:
    633715            VBoxSeamlessRemoveHook();
    634             break;
     716            return 0;
    635717
    636718        case WM_VBOX_SEAMLESS_UPDATE:
    637719            VBoxSeamlessCheckWindows();
    638             break;
     720            return 0;
    639721
    640722        case WM_VBOXTRAY_VM_RESTORED:
    641723            VBoxRestoreSession();
    642             break;
     724            return 0;
    643725
    644726        case WM_VBOXTRAY_VRDP_CHECK:
    645727            VBoxRestoreCheckVRDP();
    646             break;
     728            return 0;
    647729
    648730        default:
    649731
    650             if(msg == s_uTaskbarCreated)
    651             {
    652                 Log(("VBoxTray: Taskbar (re-)created, installing tray icon ...\n"));
    653                 vboxTrayIconAdd();
    654             }
    655             break;
    656     }
    657     return DefWindowProc(hwnd, msg, wParam, lParam);
    658 }
     732            /* Handle all globally registered window messages. */
     733            if (vboxTrayHandleGlobalMessages(&s_vboxGlobalMessageTable[0], uMsg,
     734                                             wParam, lParam))
     735            {
     736                return 0; /* We handled the message. @todo Add return value!*/
     737            }
     738            break; /* We did not handle the message, dispatch to DefWndProc. */
     739    }
     740
     741    /* Only if message was *not* handled by our switch above, dispatch
     742     * to DefWindowProc. */
     743    return DefWindowProc(hWnd, uMsg, wParam, lParam);
     744}
  • trunk/src/VBox/Additions/WINNT/VBoxTray/VBoxTray.h

    r33966 r34025  
    4444 */
    4545#define WM_VBOXTRAY_TRAY_ICON                   WM_APP + 40
    46 #define WM_VBOXTRAY_TRAY_DISPLAY_BALLOON        WM_APP + 41
    4746/**
    4847 * VM/VMMDev related messsages.
     
    5352 */
    5453#define WM_VBOXTRAY_VRDP_CHECK                  WM_APP + 301
    55 /**
    56  * Misc. utility functions.
    57  */
    58 #define WM_VBOXTRAY_CHECK_HOSTVERSION           WM_APP + 1000
    5954
    6055
    6156/* The tray icon's ID. */
    62 #define ID_TRAYICON                     2000
     57#define ID_TRAYICON                             2000
    6358
    6459
     
    8782
    8883    /* Variables. */
    89     HANDLE hThread;
    90     void  *pInstance;
    91     bool   fStarted;
    92 
     84    HANDLE   hThread;
     85    void    *pInstance;
     86    bool     fStarted;
    9387} VBOXSERVICEINFO;
    9488
     89/* Globally unique (system wide) message registration. */
     90typedef struct _VBOXGLOBALMESSAGE
     91{
     92    /** Message name. */
     93    char    *pszName;
     94    /** Function pointer for handling the message. */
     95    int      (* pfnHandler)          (LPARAM lParam, WPARAM wParam);
     96
     97    /* Variables. */
     98
     99    /** Message ID;
     100     *  to be filled in when registering the actual message. */
     101    UINT     uMsgID;
     102} VBOXGLOBALMESSAGE, *PVBOXGLOBALMESSAGE;
    95103
    96104extern HWND         gToolWindow;
    97105extern HINSTANCE    gInstance;
    98106
    99 extern void VBoxServiceReloadCursor(void);
    100 
    101107#endif /* !___VBOXTRAY_H */
    102108
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