Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

147 lines
3.7 KiB

  1. /*++
  2. Copyright (c) 1996 Microsoft Corporation
  3. Module Name:
  4. print.cpp
  5. Abstract:
  6. This module implements the tray icon for printers.
  7. Author:
  8. Lazar Ivanov (lazari) 17-May-2000 (initial creation)
  9. Revision History:
  10. --*/
  11. #include "stdafx.h"
  12. extern "C" {
  13. #include <systray.h>
  14. typedef BOOL WINAPI fntype_PrintNotifyTrayInit();
  15. typedef BOOL WINAPI fntype_PrintNotifyTrayExit();
  16. }
  17. static HMODULE g_hPrintUI = NULL;
  18. static fntype_PrintNotifyTrayInit *g_pfnPrintNotifyTrayInit = NULL;
  19. static fntype_PrintNotifyTrayExit *g_pfnPrintNotifyTrayExit = NULL;
  20. static LPCITEMIDLIST g_pidlPrintersFolder = NULL;
  21. static UINT g_uPrintNotify = 0;
  22. BOOL Print_SHChangeNotify_Register(HWND hWnd)
  23. {
  24. if (NULL == g_hPrintUI && NULL == g_pidlPrintersFolder && 0 == g_uPrintNotify)
  25. {
  26. g_pidlPrintersFolder = SHCloneSpecialIDList(hWnd, CSIDL_PRINTERS, FALSE);
  27. if (g_pidlPrintersFolder)
  28. {
  29. SHChangeNotifyEntry fsne = {g_pidlPrintersFolder, TRUE};
  30. g_uPrintNotify = SHChangeNotifyRegister(hWnd, SHCNRF_NewDelivery | SHCNRF_ShellLevel,
  31. SHCNE_CREATE | SHCNE_UPDATEITEM | SHCNE_DELETE,
  32. WM_PRINT_NOTIFY, 1, &fsne);
  33. }
  34. }
  35. return (g_pidlPrintersFolder && g_uPrintNotify);
  36. }
  37. BOOL Print_SHChangeNotify_Unregister()
  38. {
  39. BOOL bReturn = (g_pidlPrintersFolder && g_uPrintNotify);
  40. if (g_uPrintNotify)
  41. {
  42. SHChangeNotifyDeregister(g_uPrintNotify);
  43. g_uPrintNotify = 0;
  44. }
  45. if (g_pidlPrintersFolder)
  46. {
  47. SHFree((void*)g_pidlPrintersFolder);
  48. g_pidlPrintersFolder = NULL;
  49. }
  50. return bReturn;
  51. }
  52. LRESULT Print_Notify(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  53. {
  54. LRESULT lres = 0;
  55. switch( uMsg )
  56. {
  57. case WM_PRINT_NOTIFY:
  58. {
  59. LPSHChangeNotificationLock pshcnl = SHChangeNotification_Lock((HANDLE)wParam, (DWORD)lParam, NULL, NULL);
  60. if (pshcnl)
  61. {
  62. // a print job was printed, init tray code
  63. Print_TrayInit();
  64. SHChangeNotification_Unlock(pshcnl);
  65. lres = 1;
  66. }
  67. }
  68. break;
  69. }
  70. return lres;
  71. }
  72. BOOL Print_TrayInit()
  73. {
  74. BOOL bReturn = FALSE;
  75. if (!g_hPrintUI)
  76. {
  77. g_hPrintUI = LoadLibrary(TEXT("printui.dll"));
  78. g_pfnPrintNotifyTrayInit = g_hPrintUI ? (fntype_PrintNotifyTrayInit *)GetProcAddress(g_hPrintUI, "PrintNotifyTray_Init") : NULL;
  79. g_pfnPrintNotifyTrayExit = g_hPrintUI ? (fntype_PrintNotifyTrayInit *)GetProcAddress(g_hPrintUI, "PrintNotifyTray_Exit") : NULL;
  80. }
  81. if( g_pfnPrintNotifyTrayInit && g_pfnPrintNotifyTrayExit )
  82. {
  83. // initialize print notify code
  84. bReturn = g_pfnPrintNotifyTrayInit();
  85. /*
  86. * temporary solution for bug #175462 until
  87. * we come up with better solution after Beta1
  88. *
  89. if (bReturn)
  90. {
  91. // no need to listen further...
  92. Print_SHChangeNotify_Unregister();
  93. }
  94. */
  95. }
  96. return bReturn;
  97. }
  98. BOOL Print_TrayExit()
  99. {
  100. BOOL bReturn = FALSE;
  101. if( g_hPrintUI && g_pfnPrintNotifyTrayInit && g_pfnPrintNotifyTrayExit )
  102. {
  103. // shutdown the print tray notify code
  104. bReturn = g_pfnPrintNotifyTrayExit();
  105. }
  106. // cleanup...
  107. if( g_hPrintUI )
  108. {
  109. g_pfnPrintNotifyTrayInit = NULL;
  110. g_pfnPrintNotifyTrayExit = NULL;
  111. FreeLibrary(g_hPrintUI);
  112. g_hPrintUI = NULL;
  113. }
  114. return bReturn;
  115. }