Changeset 30928 in vbox for trunk/src/VBox/Additions/WINNT/VBoxTray
- Timestamp:
- Jul 20, 2010 1:27:46 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Additions/WINNT/VBoxTray/VBoxTray.cpp
r28800 r30928 4 4 5 5 /* 6 * Copyright (C) 2006-20 09Oracle Corporation6 * Copyright (C) 2006-2010 Oracle Corporation 7 7 * 8 8 * This file is part of VirtualBox Open Source Edition (OSE), as … … 40 40 HINSTANCE gInstance; 41 41 HWND gToolWindow; 42 NOTIFYICONDATA gNotifyIconData; 43 DWORD gMajorVersion; 42 44 43 45 /* Prototypes */ … … 85 87 }; 86 88 87 static int vboxStartServices (VBOXSERVICEENV *pEnv, VBOXSERVICEINFO *pTable) 89 static BOOL vboxTrayIconAdd() 90 { 91 HICON hIcon = LoadIcon(gInstance, MAKEINTRESOURCE(IDI_VIRTUALBOX)); 92 if (hIcon == NULL) 93 { 94 Log(("Could not load tray icon, err %08X\n", GetLastError())); 95 return FALSE; 96 } 97 98 /* Prepare the system tray icon. */ 99 RT_ZERO(gNotifyIconData); 100 gNotifyIconData.cbSize = NOTIFYICONDATA_V1_SIZE; // sizeof(NOTIFYICONDATA); 101 gNotifyIconData.hWnd = gToolWindow; 102 gNotifyIconData.uID = ID_TRAYICON; 103 gNotifyIconData.uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP; 104 gNotifyIconData.uCallbackMessage = WM_VBOX_TRAY; 105 gNotifyIconData.hIcon = hIcon; 106 107 sprintf(gNotifyIconData.szTip, "%s Guest Additions %d.%d.%dr%d", 108 VBOX_PRODUCT, VBOX_VERSION_MAJOR, VBOX_VERSION_MINOR, VBOX_VERSION_BUILD, VBOX_SVN_REV); 109 110 BOOL fCreated = Shell_NotifyIcon(NIM_ADD, &gNotifyIconData); 111 if (!fCreated) 112 { 113 Log(("Could not create tray icon, err %08X\n", GetLastError())); 114 RT_ZERO(gNotifyIconData); 115 } 116 117 if (hIcon) 118 DestroyIcon(hIcon); 119 return fCreated; 120 } 121 122 static void vboxTrayIconRemove() 123 { 124 if (gNotifyIconData.cbSize > 0) 125 { 126 /* Remove the system tray icon and refresh system tray. */ 127 Shell_NotifyIcon(NIM_DELETE, &gNotifyIconData); 128 HWND hTrayWnd = FindWindow("Shell_TrayWnd", NULL); /* We assume we only have one tray atm. */ 129 if (hTrayWnd) 130 { 131 HWND hTrayNotifyWnd = FindWindowEx(hTrayWnd, 0, "TrayNotifyWnd", NULL); 132 if (hTrayNotifyWnd) 133 SendMessage(hTrayNotifyWnd, WM_PAINT, 0, NULL); 134 } 135 RT_ZERO(gNotifyIconData); 136 } 137 } 138 139 static int vboxStartServices(VBOXSERVICEENV *pEnv, VBOXSERVICEINFO *pTable) 88 140 { 89 141 Log(("VBoxTray: Starting services...\n")); … … 159 211 } 160 212 161 static void vboxStopServices 213 static void vboxStopServices(VBOXSERVICEENV *pEnv, VBOXSERVICEINFO *pTable) 162 214 { 163 215 if (!pEnv->hStopEvent) … … 236 288 DWORD status = NO_ERROR; 237 289 238 /* open VBox guest driver*/290 /* Open VBox guest driver. */ 239 291 gVBoxDriver = CreateFile(VBOXGUEST_DEVICE_NAME, 240 292 GENERIC_READ | GENERIC_WRITE, … … 254 306 if (status == NO_ERROR) 255 307 { 256 /* create a custom window class*/308 /* Create a custom window class. */ 257 309 WNDCLASS windowClass = {0}; 258 310 windowClass.style = CS_NOCLOSE; … … 269 321 if (status == NO_ERROR) 270 322 { 271 /* create our window*/323 /* Create our (invisible) tool window. */ 272 324 gToolWindow = CreateWindowEx(WS_EX_TOOLWINDOW | WS_EX_TRANSPARENT | WS_EX_TOPMOST, 273 325 "VirtualBoxTool", "VirtualBoxTool", … … 282 334 Log(("VBoxTray: Window Handle = %p, Status = %p\n", gToolWindow, status)); 283 335 284 OSVERSIONINFO 285 DWORD dwMajorVersion = 5; /* default XP */336 OSVERSIONINFO info; 337 gMajorVersion = 5; /* default XP */ 286 338 info.dwOSVersionInfoSize = sizeof(info); 287 339 if (GetVersionEx(&info)) 288 340 { 289 Log(("VBoxTray: Windows version major %d minor %d \n", info.dwMajorVersion, info.dwMinorVersion));290 dwMajorVersion = info.dwMajorVersion;341 Log(("VBoxTray: Windows version major %d minor %d.\n", info.dwMajorVersion, info.dwMinorVersion)); 342 gMajorVersion = info.dwMajorVersion; 291 343 } 292 344 … … 314 366 315 367 /* For Vista and up we need to change the integrity of the security descriptor too */ 316 if ( dwMajorVersion >= 6)368 if (gMajorVersion >= 6) 317 369 { 318 370 HMODULE hModule; … … 349 401 } 350 402 351 if ( dwMajorVersion >= 5) /* Only for W2K and up ... */403 if (gMajorVersion >= 5) /* Only for W2K and up ... */ 352 404 { 353 405 ghSeamlessNotifyEvent = CreateEvent(&SecAttr, FALSE, FALSE, VBOXHOOK_GLOBAL_EVENT_NAME); … … 369 421 status = VBoxDispIfInit(&svcEnv.dispIf); 370 422 #ifdef VBOXWDDM 371 /* for now the display mode will be adjusted to WDDM mode if needed 372 * on display service initialization when it detects the display driver type */ 423 /* 424 * For now the display mode will be adjusted to WDDM mode if needed 425 * on display service initialization when it detects the display driver type. 426 */ 373 427 #endif 374 428 375 429 if (status == NO_ERROR) 376 430 { 377 int rc = vboxStartServices 431 int rc = vboxStartServices(&svcEnv, vboxServiceTable); 378 432 379 433 if (RT_FAILURE (rc)) … … 386 440 if (status != NO_ERROR) 387 441 { 388 vboxStopServices 442 vboxStopServices(&svcEnv, vboxServiceTable); 389 443 return; 390 444 } 391 445 392 BOOL fTrayIconCreated = false; 393 394 /* prepare the system tray icon */ 395 NOTIFYICONDATA ndata; 396 RT_ZERO (ndata); 397 ndata.cbSize = NOTIFYICONDATA_V1_SIZE; // sizeof(NOTIFYICONDATA); 398 ndata.hWnd = gToolWindow; 399 ndata.uID = ID_TRAYICON; 400 ndata.uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP; 401 ndata.uCallbackMessage = WM_VBOX_TRAY; 402 ndata.hIcon = LoadIcon(gInstance, MAKEINTRESOURCE(IDI_VIRTUALBOX)); 403 sprintf(ndata.szTip, "%s Guest Additions %d.%d.%dr%d", VBOX_PRODUCT, VBOX_VERSION_MAJOR, VBOX_VERSION_MINOR, VBOX_VERSION_BUILD, VBOX_SVN_REV); 404 Log(("VBoxTray: ndata.hWnd %08X, ndata.hIcon = %p\n", ndata.hWnd, ndata.hIcon)); 446 if ( vboxTrayIconAdd() 447 && gMajorVersion >= 5) /* Only for W2K and up ... */ 448 { 449 /* We're ready to create the tooltip balloon. */ 450 /* Check in 10 seconds (@todo make seconds configurable) ... */ 451 SetTimer(gToolWindow, 452 WM_VBOX_CHECK_HOSTVERSION, 453 10 * 1000, /* 10 seconds */ 454 NULL /* No timerproc */); 455 } 405 456 406 457 /* Boost thread priority to make sure we wake up early for seamless window notifications (not sure if it actually makes any difference though) */ … … 419 470 420 471 Log(("VBoxTray: Number of events to wait in main loop: %ld\n", dwEventCount)); 421 422 while(true) 472 while (true) 423 473 { 424 474 DWORD waitResult = MsgWaitForMultipleObjectsEx(dwEventCount, hWaitEvent, 500, QS_ALLINPUT, 0); 425 475 waitResult = waitResult - WAIT_OBJECT_0; 426 476 427 Log(("VBoxTray: Wait result = %ld.\n", waitResult)); 477 /* Only enable for message debugging, lots of traffic! */ 478 //Log(("VBoxTray: Wait result = %ld.\n", waitResult)); 428 479 429 480 if (waitResult == 0) … … 433 484 break; 434 485 } 435 else if ((waitResult == 1) && (ghSeamlessNotifyEvent!=0)) /* Only jump in, if seamless is active! */ 486 else if ( (waitResult == 1) 487 && (ghSeamlessNotifyEvent!=0)) /* Only jump in, if seamless is active! */ 436 488 { 437 489 Log(("VBoxTray: Event 'Seamless' triggered.\n")); … … 456 508 DispatchMessage(&msg); 457 509 } 458 /* we might have to repeat this operation because the shell might not be loaded yet */459 if (!fTrayIconCreated)460 {461 fTrayIconCreated = Shell_NotifyIcon(NIM_ADD, &ndata);462 Log(("VBoxTray: fTrayIconCreated = %d, err %08X\n", fTrayIconCreated, GetLastError ()));463 464 /* We're ready to create the tooltip balloon. */465 if (fTrayIconCreated && dwMajorVersion >= 5)466 {467 /* Check in 10 seconds (@todo make seconds configurable) ... */468 SetTimer(gToolWindow,469 WM_VBOX_CHECK_HOSTVERSION,470 10000, /* 10 seconds */471 NULL /* no timerproc */);472 }473 }474 510 } 475 511 } … … 477 513 Log(("VBoxTray: Returned from main loop, exiting ...\n")); 478 514 479 /* remove the system tray icon and refresh system tray */ 480 Shell_NotifyIcon(NIM_DELETE, &ndata); 481 HWND hTrayWnd = FindWindow("Shell_TrayWnd", NULL); /* We assume we only have one tray atm */ 482 HWND hTrayNotifyWnd = FindWindowEx(hTrayWnd, 0, "TrayNotifyWnd", NULL); 483 if (hTrayNotifyWnd) 484 SendMessage(hTrayNotifyWnd, WM_PAINT, 0, NULL); 485 486 Log(("VBoxTray: waiting for display change thread ...\n")); 487 488 vboxStopServices (&svcEnv, vboxServiceTable); 515 vboxTrayIconRemove(); 516 517 Log(("VBoxTray: Waiting for display change thread ...\n")); 518 519 vboxStopServices(&svcEnv, vboxServiceTable); 489 520 490 521 Log(("VBoxTray: Destroying tool window ...\n")); 491 522 492 /* destroy the tool window*/523 /* Destroy the tool window. */ 493 524 DestroyWindow(gToolWindow); 494 525 … … 551 582 LRESULT CALLBACK VBoxToolWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) 552 583 { 584 static UINT s_uTaskbarCreated = 0; 585 553 586 switch (msg) 554 587 { 588 case WM_CREATE: 589 Log(("VBoxTray: Tool window created.\n")); 590 s_uTaskbarCreated = RegisterWindowMessage(TEXT("TaskbarCreated")); 591 if (!s_uTaskbarCreated) 592 Log(("VBoxTray: Cannot register message \"TaskbarCreated\"! Error = %ld\n", GetLastError())); 593 break; 594 555 595 case WM_CLOSE: 556 596 break; 557 597 558 598 case WM_DESTROY: 599 Log(("VBoxTray: Tool window destroyed.\n")); 559 600 KillTimer(gToolWindow, WM_VBOX_CHECK_HOSTVERSION); 560 601 break; … … 609 650 610 651 default: 611 return DefWindowProc(hwnd, msg, wParam, lParam); 612 } 613 return 0; 652 653 if(msg == s_uTaskbarCreated) 654 { 655 Log(("VBoxTray: Taskbar (re-)created, installing tray icon ...\n")); 656 vboxTrayIconAdd(); 657 } 658 break; 659 } 660 return DefWindowProc(hwnd, msg, wParam, lParam); 614 661 } 615 662
Note:
See TracChangeset
for help on using the changeset viewer.