Source code of Windows XP (NT5)
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.

134 lines
3.7 KiB

  1. /**********************************************************************/
  2. /** Microsoft Windows/NT **/
  3. /** Copyright(c) Microsoft Corporation, 1997 - 1998 **/
  4. /**********************************************************************/
  5. /*
  6. timeofday.cpp
  7. Implementation of convenient functions to start timeofday dialog
  8. FILE HISTORY:
  9. */
  10. #include "stdafx.h"
  11. #include "timeofday.h"
  12. #ifdef _DEBUG
  13. #define new DEBUG_NEW
  14. #undef THIS_FILE
  15. static char THIS_FILE[] = __FILE__;
  16. #endif
  17. // hour map ( one bit for an hour of a week )
  18. static BYTE bitSetting[8] = { 0x80, 0x40, 0x20, 0x10, 0x8, 0x4, 0x2, 0x1};
  19. //+---------------------------------------------------------------------------
  20. //
  21. // Function: ReverseHourMap
  22. //
  23. // Synopsis: reverse each byte in the hour map
  24. //
  25. // we have to do this because LogonUI changes the way HourMap is stored(they
  26. // reversed all the bit. We need to do this so our conversion code can leave
  27. // intact.
  28. //
  29. // Arguments: [in] BYTE* map - hour map
  30. // [in] INT nByte - how many bytes are in this hour map
  31. //
  32. // History: byao 4/10/98 10:33:57 PM
  33. //
  34. //+---------------------------------------------------------------------------
  35. void ReverseHourMap(BYTE *map, int nByte)
  36. {
  37. int i, j, temp;
  38. for (i=0; i<nByte; i++)
  39. {
  40. temp = 0;
  41. for (j=0;j<8;j++)
  42. {
  43. // set the value temp
  44. if ( map[i] & bitSetting[j] )
  45. {
  46. temp |= bitSetting[7-j];
  47. }
  48. }
  49. map[i] = (BYTE) temp;
  50. }
  51. }
  52. void ShiftHourMap(BYTE* map, int nByte, int nShiftByte)
  53. {
  54. ASSERT(nShiftByte);
  55. ASSERT(nByte > abs(nShiftByte));
  56. nShiftByte = (nByte + nShiftByte) % nByte;
  57. BYTE* pTemp = (BYTE*)_alloca(nShiftByte);
  58. // put the tail to the buffer
  59. memmove(pTemp, map + nByte - nShiftByte, nShiftByte);
  60. // shift the body to right
  61. memmove(map + nShiftByte, map, nByte - nShiftByte);
  62. // put the tail back to the head
  63. memcpy(map, pTemp, nShiftByte);
  64. }
  65. HRESULT OpenTimeOfDayDlgEx(
  66. HWND hwndParent, // parent window
  67. BYTE ** pprgbData, // pointer to pointer to array of 21 bytes
  68. LPCTSTR pszTitle, // dialog title
  69. DWORD dwFlags
  70. )
  71. {
  72. PFN_LOGONSCHEDULEDIALOGEX pfnLogonScheduleDialog = NULL;
  73. HMODULE hLogonScheduleDLL = NULL;
  74. HRESULT hr = S_OK;
  75. // ReverseHourMap() will reverse each byte of the hour map, basically
  76. // reverse every bit in the byte.
  77. // we have to do this because LogonUI changes the way HourMap is stored(they
  78. // reversed all the bit. We need to do this so our conversion code can leave
  79. // intact.
  80. //
  81. // We reverse it here so it can be understood by the LogonSchedule api
  82. //
  83. ReverseHourMap(*pprgbData,21);
  84. hLogonScheduleDLL = LoadLibrary(LOGHOURSDLL);
  85. if ( NULL == hLogonScheduleDLL )
  86. {
  87. hr = HRESULT_FROM_WIN32(GetLastError());
  88. AfxMessageBox(IDS_ERR_TOD_LOADLOGHOURDLL);
  89. goto L_ERR;
  90. }
  91. // load the API pointer
  92. pfnLogonScheduleDialog = (PFN_LOGONSCHEDULEDIALOGEX) GetProcAddress(hLogonScheduleDLL, DIALINHOURSEXAPI);
  93. if ( NULL == pfnLogonScheduleDialog )
  94. {
  95. hr = HRESULT_FROM_WIN32(GetLastError());
  96. AfxMessageBox(IDS_ERR_TOD_FINDLOGHOURSAPI);
  97. goto L_ERR;
  98. }
  99. //
  100. // now we do have this DLL, call the API
  101. //
  102. hr = pfnLogonScheduleDialog(hwndParent, pprgbData, pszTitle, dwFlags);
  103. if (FAILED(hr)) goto L_ERR;
  104. // We need to reverse it first so our conversion code can understand it.
  105. //
  106. ReverseHourMap(*pprgbData,21);
  107. L_ERR:
  108. if(hLogonScheduleDLL != NULL)
  109. FreeLibrary(hLogonScheduleDLL);
  110. return hr;
  111. }