1 // 2 // Contributor(s): 3 // DirectX 8.1 Screen Saver Framework from Microsoft. 4 // Microsoft Knowledge Base Article - 79212 5 // 6 7 #ifndef _SCREENSAVER_WIN_H 8 #define _SCREENSAVER_WIN_H 9 10 11 //----------------------------------------------------------------------------- 12 // Constants 13 //----------------------------------------------------------------------------- 14 #define MAX_DISPLAYS 9 15 #define NO_ADAPTER 0xffffffff 16 #define NO_MONITOR 0xffffffff 17 18 #define BSF_ALLOWSFW 0x00000080 19 20 #define BOINC_WINDOW_CLASS_NAME _T("BOINC_app") 21 22 23 //*************************************************************************************** 24 // Modes of operation for screensaver 25 enum SaverMode 26 { 27 sm_config, // Config dialog box 28 sm_preview, // Mini preview window in Display Properties dialog 29 sm_full, // Full-on screensaver mode 30 sm_test, // Test mode 31 sm_passwordchange // Change password 32 }; 33 34 35 //----------------------------------------------------------------------------- 36 // Name: struct INTERNALMONITORINFO 37 // Desc: Structure for holding information about a monitor 38 //----------------------------------------------------------------------------- 39 struct INTERNALMONITORINFO 40 { 41 TCHAR strDeviceName[128]; 42 TCHAR strMonitorName[128]; 43 HMONITOR hMonitor; 44 RECT rcScreen; 45 HWND hWnd; 46 47 DWORD dwTimeLastUpdate; 48 49 // Error message state 50 FLOAT xError; 51 FLOAT yError; 52 FLOAT widthError; 53 FLOAT heightError; 54 FLOAT xVelError; 55 FLOAT yVelError; 56 }; 57 58 59 //----------------------------------------------------------------------------- 60 // Name: struct INTERNALMONITORINFO 61 // Desc: Use the following structure rather than DISPLAY_DEVICE, since some 62 // old versions of DISPLAY_DEVICE are missing the last two fields and 63 // this can cause problems with EnumDisplayDevices on Windows 2000. 64 //----------------------------------------------------------------------------- 65 struct DISPLAY_DEVICE_FULL 66 { 67 DWORD cb; 68 TCHAR DeviceName[32]; 69 TCHAR DeviceString[128]; 70 DWORD StateFlags; 71 TCHAR DeviceID[128]; 72 TCHAR DeviceKey[128]; 73 }; 74 75 76 struct ss_periods 77 { 78 double GFXDefaultPeriod; 79 double GFXSciencePeriod; 80 double GFXChangePeriod; 81 bool Show_default_ss_first; 82 }; 83 84 85 //----------------------------------------------------------------------------- 86 // Name: class CScreensaver 87 // Desc: Screensaver class 88 //----------------------------------------------------------------------------- 89 class CScreensaver 90 { 91 public: 92 CScreensaver(); 93 94 virtual HRESULT Create( HINSTANCE hInstance ); 95 virtual HRESULT Run(); 96 virtual HRESULT Cleanup(); 97 HRESULT DisplayErrorMsg( HRESULT hr ); 98 99 100 // 101 // Infrastructure layer 102 // 103 protected: 104 SaverMode ParseCommandLine( TCHAR* pstrCommandLine ); 105 VOID EnumMonitors( VOID ); 106 107 BOOL UtilGetRegKey(LPCTSTR name, DWORD& keyval); 108 BOOL UtilSetRegKey(LPCTSTR name, DWORD value); 109 BOOL UtilGetRegDirectoryStr(LPCTSTR name, std::string& strDirectory); 110 111 BOOL CreateInfrastructureMutexes(); 112 113 BOOL GetError( BOOL& bErrorMode, HRESULT& hrError, TCHAR* pszError, size_t iErrorSize ); 114 BOOL SetError( BOOL bErrorMode, HRESULT hrError ); 115 VOID UpdateErrorBoxText(); 116 virtual BOOL GetTextForError( HRESULT hr, TCHAR* pszError, DWORD dwNumChars ); 117 118 119 // Variables for non-fatal error management 120 HANDLE m_hErrorManagementMutex; 121 BOOL m_bErrorMode; // Whether to display an error 122 HRESULT m_hrError; // Error code to display 123 TCHAR m_szError[400]; // Error message text 124 125 // Variables for configuration management 126 DWORD m_dwBlankScreen; 127 DWORD m_dwBlankTime; 128 DWORD m_dwDefaultTime; 129 DWORD m_dwRunTime; 130 DWORD m_dwSwitchTime; 131 std::string m_strBOINCInstallDirectory; 132 std::string m_strBOINCDataDirectory; 133 134 // 135 // Input Activity Detection 136 // 137 protected: 138 BOOL CreateInputActivityThread(); 139 BOOL DestroyInputActivityThread(); 140 141 DWORD WINAPI InputActivityProc(); 142 static DWORD WINAPI InputActivityProcStub( LPVOID lpParam ); 143 144 HANDLE m_hInputActivityThread; 145 146 147 // 148 // Graphics Window Promotion 149 // 150 protected: 151 BOOL CreateGraphicsWindowPromotionThread(); 152 BOOL DestroyGraphicsWindowPromotionThread(); 153 154 DWORD WINAPI GraphicsWindowPromotionProc(); 155 static DWORD WINAPI GraphicsWindowPromotionProcStub( LPVOID lpParam ); 156 157 HANDLE m_hGraphicsWindowPromotionThread; 158 159 160 // 161 // Data Management Layer 162 // 163 protected: 164 BOOL CreateDataManagementThread(); 165 BOOL DestroyDataManagementThread(); 166 167 DWORD WINAPI DataManagementProc(); 168 static DWORD WINAPI DataManagementProcStub( LPVOID lpParam ); 169 170 int terminate_v6_screensaver(HANDLE& graphics_application); 171 int terminate_screensaver(HANDLE& graphics_application, RESULT *worker_app); 172 int terminate_default_screensaver(HANDLE& graphics_application); 173 int launch_screensaver(RESULT* rp, HANDLE& graphics_application); 174 int launch_default_screensaver(char *dir_path, HANDLE& graphics_application); 175 void HandleRPCError(void); 176 void GetDefaultDisplayPeriods(struct ss_periods &periods); 177 BOOL HasProcessExited(HANDLE pid_handle, int &exitCode); 178 179 // Determine if two RESULT pointers refer to the same task 180 bool is_same_task(RESULT* taska, RESULT* taskb); 181 182 // Count the number of active graphics-capable apps 183 int count_active_graphic_apps(RESULTS& results, RESULT* exclude = NULL); 184 185 // Choose a ramdom graphics application from the vector that 186 // was passed in. 187 RESULT* get_random_graphics_app(RESULTS& results, RESULT* exclude = NULL); 188 189 RPC_CLIENT* rpc; 190 CC_STATE state; 191 RESULTS results; 192 RESULT m_running_result; 193 194 HANDLE m_hDataManagementThread; 195 HANDLE m_hGraphicsApplication; 196 BOOL m_bResetCoreState; 197 bool m_bQuitDataManagementProc; 198 bool m_bDataManagementProcStopped; 199 int m_iLastResultShown; 200 time_t m_tLastResultChangeTime; 201 time_t m_tThreadCreateTime; 202 203 double m_fGFXDefaultPeriod; 204 double m_fGFXSciencePeriod; 205 double m_fGFXChangePeriod; 206 bool m_bShow_default_ss_first; 207 208 bool m_bScience_gfx_running; 209 bool m_bDefault_gfx_running; 210 BOOL m_bConnected; 211 212 // 213 // Presentation layer 214 // 215 protected: 216 HRESULT CreateSaverWindow(); 217 VOID UpdateErrorBox(); 218 VOID FireInterruptSaverEvent(); 219 VOID ShutdownSaver(); 220 221 222 VOID DoConfig(); 223 HRESULT DoSaver(); 224 VOID DoPaint( HWND hwnd, HDC hdc, LPPAINTSTRUCT lpps ); 225 LRESULT SaverProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam ); 226 LRESULT GenericSaverProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam ); 227 228 DWORD ConvertSliderPositionToTime( DWORD dwPosition ); 229 DWORD ConvertTimeToSliderPosition( DWORD dwMinutes ); 230 VOID InitializeDefaultSlider( HWND hwndDlg, UINT uControl ); 231 DWORD GetSliderPosition( HWND hwndDlg, UINT uControl ); 232 VOID SetSliderPosition( HWND hwndDlg, UINT uControl, DWORD dwPosition ); 233 INT_PTR ConfigureDialogProc( HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam ); 234 235 static LRESULT CALLBACK SaverProcStub( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam ); 236 static LRESULT CALLBACK GenericSaverProcStub( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam ); 237 static INT_PTR CALLBACK ConfigureDialogProcStub( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam ); 238 239 protected: 240 SaverMode m_SaverMode; // sm_config, sm_full, sm_preview, etc. 241 BOOL m_bAllScreensSame; // If TRUE, show same image on all screens 242 HWND m_hWnd; // Focus window and device window on primary 243 HWND m_hWndParent; 244 HINSTANCE m_hInstance; 245 BOOL m_bWaitForInputIdle; // Used to pause when preview starts 246 DWORD m_dwSaverMouseMoveCount; 247 BOOL m_bWindowed; 248 BOOL m_bDefault_ss_exists; 249 250 INTERNALMONITORINFO m_Monitors[MAX_DISPLAYS]; 251 DWORD m_dwNumMonitors; 252 RECT m_rcRenderTotal; // Rect of entire area to be rendered 253 RECT m_rcRenderCurDevice; // Rect of render area of current device 254 BOOL m_bPaintingInitialized; 255 256 TCHAR m_strWindowTitle[200]; // Title for the app's window 257 258 DWORD m_dwLastInputTimeAtStartup; 259 }; 260 261 #endif 262