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.

178 lines
7.0 KiB

  1. #include <windows.h>
  2. #include <ceconfig.h>
  3. #ifdef __cplusplus
  4. extern "C" {
  5. #endif /* __cplusplus */
  6. // On non-WBT, we want to be able to hide and show the shell's taskbar.
  7. // The two functions below were taken directly from the shell and are
  8. // used to perform that task by WM_ACTIVATE in UIMainWndProc below.
  9. // Only applies to non-WBT builds.
  10. const TCHAR c_szShellAutoHide[] = TEXT("Software\\Microsoft\\Shell\\AutoHide");
  11. void HHTaskBar_SetAutoHide(BOOL bAutoHide)
  12. {
  13. LONG lRet;
  14. HKEY hkey;
  15. DWORD dw;
  16. lRet = RegOpenKeyEx(HKEY_LOCAL_MACHINE, c_szShellAutoHide, 0, KEY_ALL_ACCESS, &hkey);
  17. if(lRet != ERROR_SUCCESS) {
  18. lRet = RegCreateKeyEx(HKEY_LOCAL_MACHINE, c_szShellAutoHide, 0, NULL, 0, KEY_ALL_ACCESS, NULL, &hkey, &dw);
  19. }
  20. if (lRet == ERROR_SUCCESS) {
  21. RegSetValueEx(hkey, TEXT(""), 0, REG_DWORD, (LPBYTE)&bAutoHide, sizeof(DWORD));
  22. RegCloseKey(hkey);
  23. }
  24. }
  25. BOOL HHTaskBar_GetAutoHide(BOOL *pbAutoHide)
  26. {
  27. HKEY hkey;
  28. DWORD dw = sizeof(*pbAutoHide);
  29. DWORD dwType;
  30. if (ERROR_SUCCESS == RegOpenKeyEx(HKEY_LOCAL_MACHINE, c_szShellAutoHide, 0, KEY_ALL_ACCESS, &hkey)) {
  31. RegQueryValueEx(hkey, TEXT(""), 0, &dwType, (LPBYTE) pbAutoHide, &dw);
  32. RegCloseKey(hkey);
  33. return TRUE;
  34. }
  35. return FALSE;
  36. }
  37. // We want to hide the taskbar if it's not in AutoHide mode and we're
  38. // being activated. Because we may have two separate TSC connections
  39. // active, we want to guard against problems that could result from
  40. // differing order of operations (like the taskbar being taken out of
  41. // AutoHide mode when a TSC window is still in use). In order to do
  42. // that, we'll create a system-wide named Mutex that we'll use to
  43. // indicate when we need to restore the taskbar's state.
  44. const TCHAR psWinCEHPCTaskBarMutexName[] = TEXT("WinCEHPCTaskBarMutex");
  45. // This function is called when the main window proc receives an WM_ACTIVATE
  46. // message. wParam indicates if we're being minimized or maximized, hwnd
  47. // is variable received from main window proc.
  48. // BUGBUG - to make ActiveX control work we may need to expose/doc this function.
  49. void AutoHideCE(HWND hwnd, WPARAM wParam)
  50. {
  51. static HANDLE hWinCEHPCTaskBarMutex = 0;
  52. HWND hwndTaskBar;
  53. hwndTaskBar = FindWindow(TEXT("HHTaskBar"), NULL);
  54. if(0 != hwndTaskBar)
  55. {
  56. BOOL bActivating = LOWORD(wParam) != WA_INACTIVE;
  57. if(bActivating)
  58. {
  59. // Window is being displayed
  60. // Assume that the taskbar is not in AutoHide mode, then find
  61. // out what mode it IS in
  62. #define WM_USER 0x0400
  63. #define WM_TASKBAR_FULLSCREEN (WM_USER + 7)
  64. #define SHFS_SHOWTASKBAR 0x0001
  65. #define SHFS_HIDETASKBAR 0x0002
  66. // BUGBUG -- this has not been well tested/integrated on Palmsized.
  67. // Use at your own risk.
  68. if (g_CEConfig == CE_CONFIG_PALMSIZED)
  69. {
  70. PostMessage(hwndTaskBar,
  71. WM_TASKBAR_FULLSCREEN, (WPARAM)hwnd, SHFS_HIDETASKBAR);
  72. }
  73. else
  74. {
  75. BOOL bAutoHide = FALSE;
  76. HHTaskBar_GetAutoHide(&bAutoHide);
  77. if(bAutoHide)
  78. {
  79. // Auto-Hide is already active - see if that's because
  80. // some other TSC window is responsible
  81. hWinCEHPCTaskBarMutex = CreateMutex(0, FALSE, psWinCEHPCTaskBarMutexName);
  82. if((0 != hWinCEHPCTaskBarMutex) && (ERROR_ALREADY_EXISTS != GetLastError()))
  83. {
  84. // We just created this Mutex, so Auto-Hide was
  85. // enabled by the user. Throw-away the Mutex we
  86. // just created so we know that this TSC window
  87. // didn't enable Auto-Hide.
  88. CloseHandle(hWinCEHPCTaskBarMutex);
  89. hWinCEHPCTaskBarMutex = 0;
  90. }
  91. else
  92. {
  93. // The Mutex was already present, so keep a handle on
  94. // it as a reference-count
  95. }
  96. }
  97. else
  98. {
  99. // We're about to set Auto-Hide, so create the Mutex to
  100. // tell other TSC windows that we've done so
  101. hWinCEHPCTaskBarMutex = CreateMutex(0, FALSE, psWinCEHPCTaskBarMutexName);
  102. if(0 != hWinCEHPCTaskBarMutex)
  103. {
  104. // Only hide the taskbar if we were able to indicate
  105. // that we have done so
  106. HHTaskBar_SetAutoHide(TRUE);
  107. PostMessage(hwndTaskBar, WM_WININICHANGE, 0, 5000);
  108. }
  109. }
  110. // If this or any other TSC window set Auto-Hide, then
  111. // (hWinCEHPCTaskBarMutex != 0) now
  112. }
  113. }
  114. else
  115. {
  116. // BUGBUG -- this has not been well tested/integrated on Palmsized devices.
  117. // Use at your own risk.
  118. if (g_CEConfig == CE_CONFIG_PALMSIZED)
  119. {
  120. PostMessage(hwndTaskBar,
  121. WM_TASKBAR_FULLSCREEN, (WPARAM)hwnd, SHFS_SHOWTASKBAR);
  122. }
  123. // Window is being hiden
  124. if(0 != hWinCEHPCTaskBarMutex)
  125. {
  126. // Some TSC window set the taskbar into Auto-Hide mode
  127. // Discard our Mutex handle to drop the reference-count
  128. // and see if the Mutex stays around
  129. CloseHandle(hWinCEHPCTaskBarMutex);
  130. hWinCEHPCTaskBarMutex = CreateMutex(0, FALSE, psWinCEHPCTaskBarMutexName);
  131. if(0 != hWinCEHPCTaskBarMutex)
  132. {
  133. if(ERROR_ALREADY_EXISTS == GetLastError())
  134. {
  135. // The Mutex was still present, so there is at
  136. // least one other TSC window that's active.
  137. // So we do nothing here.
  138. }
  139. else
  140. {
  141. // The Mutex went away after we closed our Mutex handle, so we are the last TSC window
  142. // We need to restore the Auto-Hide setting (and we know it used to be FALSE because
  143. // the Mutex was present)
  144. HHTaskBar_SetAutoHide(FALSE);
  145. PostMessage(hwndTaskBar, WM_WININICHANGE, 0, 5000);
  146. }
  147. // We didn't really want a handle to the Mutex, so
  148. // discard it now.
  149. CloseHandle(hWinCEHPCTaskBarMutex);
  150. }
  151. }
  152. else
  153. {
  154. // The Mutex was not present, so no TSC window set the
  155. // taskbar into Auto-Hide mode. That means we don't need
  156. // to restore anything here.
  157. }
  158. }
  159. }
  160. }
  161. #ifdef __cplusplus
  162. }
  163. #endif /* __cplusplus */