@ -3,7 +3,7 @@
# include "ep_weather_provider_google_script.h"
# include "ep_weather_provider_google_script.h"
# include "ep_weather_error_html.h"
# include "ep_weather_error_html.h"
LPCWSTR EP_Weather_Script_Provider_Google = L " <!DOCTYPE html> \n " ;
EPWeather * EPWeather_Instance ;
HRESULT STDMETHODCALLTYPE INetworkListManagerEvents_QueryInterface ( void * _this , REFIID riid , void * * ppv )
HRESULT STDMETHODCALLTYPE INetworkListManagerEvents_QueryInterface ( void * _this , REFIID riid , void * * ppv )
{
{
@ -24,7 +24,7 @@ ULONG STDMETHODCALLTYPE INetworkListManagerEvents_AddRefRelease(void* _this)
HRESULT STDMETHODCALLTYPE INetworkListManagerEvents_ConnectivityChanged ( void * _this2 , NLM_CONNECTIVITY newConnectivity )
HRESULT STDMETHODCALLTYPE INetworkListManagerEvents_ConnectivityChanged ( void * _this2 , NLM_CONNECTIVITY newConnectivity )
{
{
EPWeather * _this = GetWindowLongPtrW ( FindWindowW ( _T ( EPW_WEATHER_CLASSNAME ) , NULL ) , GWLP_USERDATA ) ;
EPWeather * _this = EPWeather_Instance ; // GetWindowLongPtrW(FindWindowW(_T(EPW_WEATHER_CLASSNAME), NULL), GWLP_USERDATA);
if ( _this )
if ( _this )
{
{
if ( ( newConnectivity & ( NLM_CONNECTIVITY_IPV4_INTERNET | NLM_CONNECTIVITY_IPV6_INTERNET ) ) ! = 0 )
if ( ( newConnectivity & ( NLM_CONNECTIVITY_IPV4_INTERNET | NLM_CONNECTIVITY_IPV6_INTERNET ) ) ! = 0 )
@ -99,15 +99,41 @@ HRESULT STDMETHODCALLTYPE ICoreWebView2_get_AllowSingleSignOnUsingOSPrimaryAccou
HRESULT STDMETHODCALLTYPE ICoreWebView2_CreateCoreWebView2EnvironmentCompleted ( ICoreWebView2CreateCoreWebView2EnvironmentCompletedHandler * _this , HRESULT hr , ICoreWebView2Environment * pCoreWebView2Environemnt )
HRESULT STDMETHODCALLTYPE ICoreWebView2_CreateCoreWebView2EnvironmentCompleted ( ICoreWebView2CreateCoreWebView2EnvironmentCompletedHandler * _this , HRESULT hr , ICoreWebView2Environment * pCoreWebView2Environemnt )
{
{
pCoreWebView2Environemnt - > lpVtbl - > CreateCoreWebView2Controller ( pCoreWebView2Environemnt , FindWindowW ( _T ( EPW_WEATHER_CLASSNAME ) , NULL ) , & EPWeather_ICoreWebView2CreateCoreWebView2ControllerCompletedHandler ) ;
pCoreWebView2Environemnt - > lpVtbl - > CreateCoreWebView2Controller ( pCoreWebView2Environemnt , EPWeather_Instance - > hWnd /* FindWindowW(_T(EPW_WEATHER_CLASSNAME), NULL) */ , & EPWeather_ICoreWebView2CreateCoreWebView2ControllerCompletedHandler ) ;
return S_OK ;
return S_OK ;
}
}
HRESULT STDMETHODCALLTYPE _epw_Weather_NavigateToError ( EPWeather * _this )
HRESULT STDMETHODCALLTYPE _epw_Weather_NavigateToError ( EPWeather * _this )
{
{
InterlockedExchange64 ( & _this - > bIsNavigatingToError , TRUE ) ;
InterlockedExchange64 ( & _this - > bIsNavigatingToError , TRUE ) ;
UINT dpi = GetDpiForWindow ( _this - > hWnd ) ;
int ch = MulDiv ( 305 , dpi , 96 ) ;
RECT rc ;
GetWindowRect ( _this - > hWnd , & rc ) ;
if ( rc . bottom - rc . top ! = ch )
{
SetWindowPos ( _this - > hWnd , NULL , 0 , 0 , rc . right - rc . left , ch , SWP_NOMOVE | SWP_NOSENDCHANGING ) ;
RECT bounds ;
GetClientRect ( _this - > hWnd , & bounds ) ;
if ( _this - > pCoreWebView2Controller )
{
_this - > pCoreWebView2Controller - > lpVtbl - > put_Bounds ( _this - > pCoreWebView2Controller , bounds ) ;
}
HWND hNotifyWnd = InterlockedAdd64 ( & _this - > hNotifyWnd , 0 ) ;
if ( hNotifyWnd )
{
InvalidateRect ( hNotifyWnd , NULL , TRUE ) ;
}
}
if ( _this - > pCoreWebView2 )
{
return _this - > pCoreWebView2 - > lpVtbl - > NavigateToString ( _this - > pCoreWebView2 , ep_weather_error_html ) ;
return _this - > pCoreWebView2 - > lpVtbl - > NavigateToString ( _this - > pCoreWebView2 , ep_weather_error_html ) ;
}
}
else
{
return E_FAIL ;
}
}
HRESULT STDMETHODCALLTYPE _epw_Weather_NavigateToProvider ( EPWeather * _this )
HRESULT STDMETHODCALLTYPE _epw_Weather_NavigateToProvider ( EPWeather * _this )
{
{
@ -123,7 +149,14 @@ HRESULT STDMETHODCALLTYPE _epw_Weather_NavigateToProvider(EPWeather* _this)
if ( _this - > wszScriptData )
if ( _this - > wszScriptData )
{
{
swprintf_s ( _this - > wszScriptData , EP_WEATHER_PROVIDER_GOOGLE_HTML_LEN , ep_weather_provider_google_html , _this - > wszLanguage , _this - > wszTerm [ 0 ] ? L " " : L " " , _this - > wszTerm ) ;
swprintf_s ( _this - > wszScriptData , EP_WEATHER_PROVIDER_GOOGLE_HTML_LEN , ep_weather_provider_google_html , _this - > wszLanguage , _this - > wszTerm [ 0 ] ? L " " : L " " , _this - > wszTerm ) ;
if ( _this - > pCoreWebView2 )
{
hr = _this - > pCoreWebView2 - > lpVtbl - > NavigateToString ( _this - > pCoreWebView2 , _this - > wszScriptData ) ;
hr = _this - > pCoreWebView2 - > lpVtbl - > NavigateToString ( _this - > pCoreWebView2 , _this - > wszScriptData ) ;
}
else
{
hr = E_FAIL ;
}
if ( FAILED ( hr ) )
if ( FAILED ( hr ) )
{
{
InterlockedExchange64 ( & _this - > bBrowserBusy , FALSE ) ;
InterlockedExchange64 ( & _this - > bBrowserBusy , FALSE ) ;
@ -154,7 +187,14 @@ HRESULT STDMETHODCALLTYPE _epw_Weather_ExecuteDataScript(EPWeather* _this)
LONG64 cbx = InterlockedAdd64 ( & _this - > cbx , 0 ) ;
LONG64 cbx = InterlockedAdd64 ( & _this - > cbx , 0 ) ;
swprintf_s ( _this - > wszScriptData , EP_WEATHER_PROVIDER_GOOGLE_SCRIPT_LEN , ep_weather_provider_google_script , dwTemperatureUnit = = EP_WEATHER_TUNIT_FAHRENHEIT ? L ' F ' : L ' C ' , cbx , cbx ) ;
swprintf_s ( _this - > wszScriptData , EP_WEATHER_PROVIDER_GOOGLE_SCRIPT_LEN , ep_weather_provider_google_script , dwTemperatureUnit = = EP_WEATHER_TUNIT_FAHRENHEIT ? L ' F ' : L ' C ' , cbx , cbx ) ;
//wprintf(L"%s\n", _this->wszScriptData);
//wprintf(L"%s\n", _this->wszScriptData);
if ( _this - > pCoreWebView2 )
{
hr = _this - > pCoreWebView2 - > lpVtbl - > ExecuteScript ( _this - > pCoreWebView2 , _this - > wszScriptData , & EPWeather_ICoreWebView2ExecuteScriptCompletedHandler ) ;
hr = _this - > pCoreWebView2 - > lpVtbl - > ExecuteScript ( _this - > pCoreWebView2 , _this - > wszScriptData , & EPWeather_ICoreWebView2ExecuteScriptCompletedHandler ) ;
}
else
{
return E_FAIL ;
}
if ( FAILED ( hr ) )
if ( FAILED ( hr ) )
{
{
InterlockedExchange64 ( & _this - > bBrowserBusy , FALSE ) ;
InterlockedExchange64 ( & _this - > bBrowserBusy , FALSE ) ;
@ -171,7 +211,7 @@ HRESULT STDMETHODCALLTYPE _epw_Weather_ExecuteDataScript(EPWeather* _this)
HRESULT STDMETHODCALLTYPE ICoreWebView2_CreateCoreWebView2ControllerCompleted ( ICoreWebView2CreateCoreWebView2ControllerCompletedHandler * _this2 , HRESULT hr , ICoreWebView2Controller * pCoreWebView2Controller )
HRESULT STDMETHODCALLTYPE ICoreWebView2_CreateCoreWebView2ControllerCompleted ( ICoreWebView2CreateCoreWebView2ControllerCompletedHandler * _this2 , HRESULT hr , ICoreWebView2Controller * pCoreWebView2Controller )
{
{
EPWeather * _this = GetWindowLongPtrW ( FindWindowW ( _T ( EPW_WEATHER_CLASSNAME ) , NULL ) , GWLP_USERDATA ) ;
EPWeather * _this = EPWeather_Instance ; // GetWindowLongPtrW(FindWindowW(_T(EPW_WEATHER_CLASSNAME), NULL), GWLP_USERDATA);
if ( ! _this - > pCoreWebView2Controller )
if ( ! _this - > pCoreWebView2Controller )
{
{
_this - > pCoreWebView2Controller = pCoreWebView2Controller ;
_this - > pCoreWebView2Controller = pCoreWebView2Controller ;
@ -228,7 +268,7 @@ HRESULT STDMETHODCALLTYPE ICoreWebView2_CreateCoreWebView2ControllerCompleted(IC
HRESULT STDMETHODCALLTYPE ICoreWebView2_NavigationCompleted ( ICoreWebView2NavigationCompletedEventHandler * _this2 , ICoreWebView2 * pCoreWebView2 , ICoreWebView2NavigationCompletedEventArgs * pCoreWebView2NavigationCompletedEventArgs )
HRESULT STDMETHODCALLTYPE ICoreWebView2_NavigationCompleted ( ICoreWebView2NavigationCompletedEventHandler * _this2 , ICoreWebView2 * pCoreWebView2 , ICoreWebView2NavigationCompletedEventArgs * pCoreWebView2NavigationCompletedEventArgs )
{
{
EPWeather * _this = GetWindowLongPtrW ( FindWindowW ( _T ( EPW_WEATHER_CLASSNAME ) , NULL ) , GWLP_USERDATA ) ;
EPWeather * _this = EPWeather_Instance ; // GetWindowLongPtrW(FindWindowW(_T(EPW_WEATHER_CLASSNAME), NULL), GWLP_USERDATA);
if ( _this - > wszScriptData )
if ( _this - > wszScriptData )
{
{
free ( _this - > wszScriptData ) ;
free ( _this - > wszScriptData ) ;
@ -259,7 +299,7 @@ HRESULT STDMETHODCALLTYPE ICoreWebView2_NavigationCompleted(ICoreWebView2Navigat
HRESULT STDMETHODCALLTYPE ICoreWebView2_ExecuteScriptCompleted ( ICoreWebView2ExecuteScriptCompletedHandler * _this2 , HRESULT hr , LPCWSTR pResultObjectAsJson )
HRESULT STDMETHODCALLTYPE ICoreWebView2_ExecuteScriptCompleted ( ICoreWebView2ExecuteScriptCompletedHandler * _this2 , HRESULT hr , LPCWSTR pResultObjectAsJson )
{
{
EPWeather * _this = GetWindowLongPtrW ( FindWindowW ( _T ( EPW_WEATHER_CLASSNAME ) , NULL ) , GWLP_USERDATA ) ;
EPWeather * _this = EPWeather_Instance ; // GetWindowLongPtrW(FindWindowW(_T(EPW_WEATHER_CLASSNAME), NULL), GWLP_USERDATA);
if ( _this )
if ( _this )
{
{
BOOL bOk = FALSE ;
BOOL bOk = FALSE ;
@ -283,9 +323,14 @@ HRESULT STDMETHODCALLTYPE ICoreWebView2_ExecuteScriptCompleted(ICoreWebView2Exec
epw_Weather_LockData ( _this ) ;
epw_Weather_LockData ( _this ) ;
WCHAR * wszTemperature = pResultObjectAsJson + 1 ;
WCHAR * wszHeight = pResultObjectAsJson + 1 ;
if ( wszHeight )
{
WCHAR * wszTemperature = wcschr ( wszHeight , L ' # ' ) ;
if ( wszTemperature )
if ( wszTemperature )
{
{
wszTemperature [ 0 ] = 0 ;
wszTemperature + + ;
WCHAR * wszUnit = wcschr ( wszTemperature , L ' # ' ) ;
WCHAR * wszUnit = wcschr ( wszTemperature , L ' # ' ) ;
if ( wszUnit )
if ( wszUnit )
{
{
@ -358,6 +403,25 @@ HRESULT STDMETHODCALLTYPE ICoreWebView2_ExecuteScriptCompleted(ICoreWebView2Exec
bOk = TRUE ;
bOk = TRUE ;
}
}
int h = _wtoi ( wszHeight ) ;
int ch = MulDiv ( h , EP_WEATHER_WIDTH , 367 ) ;
UINT dpi = GetDpiForWindow ( _this - > hWnd ) ;
ch = MulDiv ( ch , dpi , 96 ) ;
RECT rc ;
GetWindowRect ( _this - > hWnd , & rc ) ;
if ( rc . bottom - rc . top ! = ch )
{
SetWindowPos ( _this - > hWnd , NULL , 0 , 0 , rc . right - rc . left , ch , SWP_NOMOVE | SWP_NOSENDCHANGING ) ;
RECT bounds ;
GetClientRect ( _this - > hWnd , & bounds ) ;
_this - > pCoreWebView2Controller - > lpVtbl - > put_Bounds ( _this - > pCoreWebView2Controller , bounds ) ;
HWND hNotifyWnd = InterlockedAdd64 ( & _this - > hNotifyWnd , 0 ) ;
if ( hNotifyWnd )
{
InvalidateRect ( hNotifyWnd , NULL , TRUE ) ;
}
}
}
}
}
}
}
}
}
@ -515,8 +579,12 @@ LRESULT CALLBACK epw_Weather_WindowProc(_In_ HWND hWnd, _In_ UINT uMsg, _In_ WPA
{
{
RECT bounds ;
RECT bounds ;
GetClientRect ( _this - > hWnd , & bounds ) ;
GetClientRect ( _this - > hWnd , & bounds ) ;
if ( _this - > pCoreWebView2Controller )
{
_this - > pCoreWebView2Controller - > lpVtbl - > put_Bounds ( _this - > pCoreWebView2Controller , bounds ) ;
_this - > pCoreWebView2Controller - > lpVtbl - > put_Bounds ( _this - > pCoreWebView2Controller , bounds ) ;
}
KillTimer ( _this - > hWnd , EP_WEATHER_TIMER_REBOUND_BROWSER ) ;
KillTimer ( _this - > hWnd , EP_WEATHER_TIMER_REBOUND_BROWSER ) ;
return 0 ;
}
}
else if ( uMsg = = EP_WEATHER_WM_FETCH_DATA )
else if ( uMsg = = EP_WEATHER_WM_FETCH_DATA )
{
{
@ -655,7 +723,7 @@ DWORD WINAPI epw_Weather_MainThread(EPWeather* _this)
goto cleanup ;
goto cleanup ;
}
}
_this - > hWnd = CreateWindowExW ( 0 , _T ( EPW_WEATHER_CLASSNAME ) , L " " , WS_OVERLAPPED | WS_CAPTION , 100 , 100 , 690 * _this - > dpi , 425 * _this - > dpi , NULL , NULL , epw_hModule , _this ) ; // 1030, 630
_this - > hWnd = CreateWindowExW ( 0 , _T ( EPW_WEATHER_CLASSNAME ) , L " " , WS_OVERLAPPED | WS_CAPTION , _this - > rc . left , _this - > rc . top , _this - > rc . right - _this - > rc . left , _this - > rc . bottom - _this - > rc . top , NULL , NULL , epw_hModule , _this ) ; // 1030, 630
if ( ! _this - > hWnd )
if ( ! _this - > hWnd )
{
{
_this - > hrLastError = HRESULT_FROM_WIN32 ( GetLastError ( ) ) ;
_this - > hrLastError = HRESULT_FROM_WIN32 ( GetLastError ( ) ) ;
@ -822,7 +890,7 @@ DWORD WINAPI epw_Weather_MainThread(EPWeather* _this)
return 0 ;
return 0 ;
}
}
HRESULT STDMETHODCALLTYPE epw_Weather_Initialize ( EPWeather * _this , WCHAR wszName [ MAX_PATH ] , BOOL bAllocConsole , LONG64 dwProvider , LONG64 cbx , LONG64 cby , LONG64 dwTemperatureUnit , LONG64 dwUpdateSchedule , double dpi )
HRESULT STDMETHODCALLTYPE epw_Weather_Initialize ( EPWeather * _this , WCHAR wszName [ MAX_PATH ] , BOOL bAllocConsole , LONG64 dwProvider , LONG64 cbx , LONG64 cby , LONG64 dwTemperatureUnit , LONG64 dwUpdateSchedule , RECT rc , HWND * hWnd )
{
{
if ( bAllocConsole )
if ( bAllocConsole )
{
{
@ -836,7 +904,11 @@ HRESULT STDMETHODCALLTYPE epw_Weather_Initialize(EPWeather* _this, WCHAR wszName
) ;
) ;
}
}
_this - > dpi = dpi ;
if ( EPWeather_Instance )
{
return E_FAIL ;
}
EPWeather_Instance = _this ;
if ( dwUpdateSchedule < 0 )
if ( dwUpdateSchedule < 0 )
{
{
@ -887,6 +959,8 @@ HRESULT STDMETHODCALLTYPE epw_Weather_Initialize(EPWeather* _this, WCHAR wszName
return HRESULT_FROM_WIN32 ( GetLastError ( ) ) ;
return HRESULT_FROM_WIN32 ( GetLastError ( ) ) ;
}
}
_this - > rc = rc ;
_this - > hMainThread = CreateThread ( NULL , 0 , epw_Weather_MainThread , _this , 0 , NULL ) ;
_this - > hMainThread = CreateThread ( NULL , 0 , epw_Weather_MainThread , _this , 0 , NULL ) ;
if ( ! _this - > hMainThread )
if ( ! _this - > hMainThread )
{
{
@ -899,6 +973,8 @@ HRESULT STDMETHODCALLTYPE epw_Weather_Initialize(EPWeather* _this, WCHAR wszName
return _this - > hrLastError ;
return _this - > hrLastError ;
}
}
* hWnd = _this - > hWnd ;
return S_OK ;
return S_OK ;
}
}