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.

153 lines
4.0 KiB

  1. /*******************************************************************************
  2. *
  3. * (C) COPYRIGHT MICROSOFT CORP., 1993-1994
  4. *
  5. * TITLE: SYSTRAY.C
  6. *
  7. * VERSION: 2.0
  8. *
  9. * AUTHOR: TCS/RAL
  10. *
  11. * DATE: 08 Feb 1994
  12. *
  13. ********************************************************************************
  14. *
  15. * CHANGE LOG:
  16. *
  17. * DATE REV DESCRIPTION
  18. * ----------- --- -------------------------------------------------------------
  19. * 08 Feb 1994 TCS Original implementation.
  20. * 11 Nov 1994 RAL Converted from batmeter to systray
  21. * 11 Aug 1995 JEM Split batmeter functions into power.c & minor enahncements
  22. * 23 Oct 1995 Shawnb Unicode enabled
  23. * 07 Aug 1998 dsheldon Created systray.dll and made this into a stub exe
  24. *
  25. *******************************************************************************/
  26. #include <nt.h>
  27. #include <ntrtl.h>
  28. #include <nturtl.h>
  29. #include <windows.h>
  30. #include <shlobj.h>
  31. #include <shellapi.h>
  32. #include <systrayp.h>
  33. #include <initguid.h>
  34. #include <stclsid.h>
  35. // Global instance handle of this application.
  36. HINSTANCE g_hInstance;
  37. INT intval(LPCTSTR lpsz)
  38. {
  39. INT i = 0;
  40. while (*lpsz >= TEXT ('0') && *lpsz <= TEXT ('9'))
  41. {
  42. i = i * 10 + (int)(*lpsz - TEXT ('0'));
  43. lpsz++;
  44. }
  45. return(i);
  46. }
  47. // stolen from the CRT, used to shrink our code
  48. int _stdcall ModuleEntry(void)
  49. {
  50. int i;
  51. STARTUPINFO si;
  52. LPTSTR pszCmdLine = GetCommandLine ();
  53. if ( *pszCmdLine == TEXT ('\"') )
  54. {
  55. /*
  56. * Scan, and skip over, subsequent characters until
  57. * another double-quote or a null is encountered.
  58. */
  59. while ( *++pszCmdLine && (*pszCmdLine != TEXT ('\"')) )
  60. ;
  61. /*
  62. * If we stopped on a double-quote (usual case), skip
  63. * over it.
  64. */
  65. if ( *pszCmdLine == TEXT ('\"') )
  66. pszCmdLine++;
  67. }
  68. else
  69. {
  70. while (*pszCmdLine > ' ')
  71. pszCmdLine++;
  72. }
  73. /*
  74. * Skip past any white space preceeding the second token.
  75. */
  76. while (*pszCmdLine && (*pszCmdLine <= ' '))
  77. {
  78. pszCmdLine++;
  79. }
  80. si.dwFlags = 0;
  81. GetStartupInfo (&si);
  82. i = WinMain(GetModuleHandle(NULL), NULL, (LPSTR)pszCmdLine,
  83. si.dwFlags & STARTF_USESHOWWINDOW ? si.wShowWindow : SW_SHOWDEFAULT);
  84. ExitProcess(i);
  85. return i; // We never come here.
  86. }
  87. /*******************************************************************************
  88. *
  89. * WinMain
  90. *
  91. * DESCRIPTION:
  92. *
  93. * PARAMETERS:
  94. * if lpCmdLine contains an integer value then we'll enable that service
  95. *
  96. *******************************************************************************/
  97. STDAPI_(int) WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdLine, int nCmdShow)
  98. {
  99. HWND hWnd;
  100. HWND hExistWnd = FindWindow(SYSTRAY_CLASSNAME, NULL);
  101. UINT iEnableServ = intval((LPTSTR)lpszCmdLine);
  102. g_hInstance = hInstance;
  103. if (hExistWnd)
  104. {
  105. //
  106. // NOTE: Send an enable message even if the command line parameter
  107. // is 0 to force us to re-check for all enabled services.
  108. //
  109. PostMessage(hExistWnd, STWM_ENABLESERVICE, iEnableServ, TRUE);
  110. goto ExitMain;
  111. }
  112. else
  113. {
  114. int i;
  115. // We have to inject systray.dll into the explorer process
  116. if (SUCCEEDED(SHLoadInProc(&CLSID_SysTrayInvoker)))
  117. {
  118. // Wait for up to 30 seconds for the window to be created,
  119. // send our message every second
  120. for (i = 0; i < 30; i ++)
  121. {
  122. Sleep(1000);
  123. hExistWnd = FindWindow(SYSTRAY_CLASSNAME, NULL);
  124. if (hExistWnd)
  125. {
  126. PostMessage(hExistWnd, STWM_ENABLESERVICE, iEnableServ, TRUE);
  127. goto ExitMain;
  128. }
  129. }
  130. }
  131. }
  132. ExitMain:
  133. return 0;
  134. }