Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "stdafx.h" | 5 #include "stdafx.h" |
| 6 #include <corewindow.h> | |
| 7 | |
| 8 #include "base/logging.h" | |
| 6 | 9 |
| 7 EXTERN_C IMAGE_DOS_HEADER __ImageBase; | 10 EXTERN_C IMAGE_DOS_HEADER __ImageBase; |
| 8 | 11 |
| 9 struct Globals { | |
| 10 LPTHREAD_START_ROUTINE host_main; | |
| 11 void* host_context; | |
| 12 HWND core_window; | |
| 13 HWND host_window; | |
| 14 HANDLE host_thread; | |
| 15 DWORD main_thread_id; | |
| 16 } globals; | |
| 17 | |
| 18 | |
| 19 void ODS(const char* str, LONG_PTR val = 0) { | |
| 20 char buf[80]; | |
| 21 size_t len = strlen(str); | |
| 22 if (len > 50) { | |
| 23 ::OutputDebugStringA("ODS: buffer too long"); | |
| 24 return; | |
| 25 } | |
| 26 | |
| 27 if (str[0] == '!') { | |
| 28 // Fatal error. | |
| 29 DWORD gle = ::GetLastError(); | |
| 30 if (::IsDebuggerPresent()) | |
| 31 __debugbreak(); | |
| 32 wsprintfA(buf, "ODS:fatal %s (%p) gle=0x%x", str, val, gle); | |
| 33 ::MessageBoxA(NULL, buf, "!!!", MB_OK); | |
| 34 ::ExitProcess(gle); | |
| 35 } else { | |
| 36 // Just information. | |
| 37 wsprintfA(buf, "ODS:%s (%p)\n", str, val); | |
| 38 ::OutputDebugStringA(buf); | |
| 39 } | |
| 40 } | |
| 41 | |
| 42 LRESULT CALLBACK WndProc(HWND hwnd, UINT message, | 12 LRESULT CALLBACK WndProc(HWND hwnd, UINT message, |
| 43 WPARAM wparam, LPARAM lparam) { | 13 WPARAM wparam, LPARAM lparam) { |
| 44 PAINTSTRUCT ps; | 14 PAINTSTRUCT ps; |
| 45 HDC hdc; | 15 HDC hdc; |
| 46 switch (message) { | 16 switch (message) { |
| 47 case WM_PAINT: | 17 case WM_PAINT: |
| 48 hdc = BeginPaint(hwnd, &ps); | 18 hdc = BeginPaint(hwnd, &ps); |
| 49 EndPaint(hwnd, &ps); | 19 EndPaint(hwnd, &ps); |
| 50 break; | 20 break; |
| 51 case WM_DESTROY: | 21 case WM_DESTROY: |
| 52 PostQuitMessage(0); | 22 PostQuitMessage(0); |
| 53 ODS("Metro WM_DESTROY received"); | |
| 54 break; | 23 break; |
| 55 default: | 24 default: |
| 56 return DefWindowProc(hwnd, message, wparam, lparam); | 25 return DefWindowProc(hwnd, message, wparam, lparam); |
| 57 } | 26 } |
| 58 return 0; | 27 return 0; |
| 59 } | 28 } |
| 60 | 29 |
| 61 HWND CreateMetroTopLevelWindow() { | 30 HWND CreateMetroTopLevelWindow() { |
| 62 HINSTANCE hInst = reinterpret_cast<HINSTANCE>(&__ImageBase); | 31 HINSTANCE hInst = reinterpret_cast<HINSTANCE>(&__ImageBase); |
| 63 WNDCLASSEXW wcex; | 32 WNDCLASSEXW wcex; |
| 64 wcex.cbSize = sizeof(wcex); | 33 wcex.cbSize = sizeof(wcex); |
| 65 wcex.style = CS_HREDRAW | CS_VREDRAW; | 34 wcex.style = CS_HREDRAW | CS_VREDRAW; |
| 66 wcex.lpfnWndProc = WndProc; | 35 wcex.lpfnWndProc = WndProc; |
| 67 wcex.cbClsExtra = 0; | 36 wcex.cbClsExtra = 0; |
| 68 wcex.cbWndExtra = 0; | 37 wcex.cbWndExtra = 0; |
| 69 wcex.hInstance = hInst; | 38 wcex.hInstance = hInst; |
| 70 wcex.hIcon = 0; | 39 wcex.hIcon = 0; |
| 71 wcex.hCursor = LoadCursor(NULL, IDC_ARROW); | 40 wcex.hCursor = LoadCursor(NULL, IDC_ARROW); |
| 72 wcex.hbrBackground = (HBRUSH)(COLOR_INACTIVECAPTION+1); | 41 wcex.hbrBackground = (HBRUSH)(COLOR_INACTIVECAPTION+1); |
| 73 wcex.lpszMenuName = 0; | 42 wcex.lpszMenuName = 0; |
| 74 wcex.lpszClassName = L"Windows.UI.Core.CoreWindow"; | 43 wcex.lpszClassName = L"Windows.UI.Core.CoreWindow"; |
| 75 wcex.hIconSm = 0; | 44 wcex.hIconSm = 0; |
| 76 | 45 |
| 77 HWND hwnd = ::CreateWindowExW(0, | 46 HWND hwnd = ::CreateWindowExW(0, |
| 78 MAKEINTATOM(::RegisterClassExW(&wcex)), | 47 MAKEINTATOM(::RegisterClassExW(&wcex)), |
| 79 L"metro_metro", | 48 L"metro_win7", |
| 80 WS_POPUP, | 49 WS_POPUP, |
| 81 0, 0, 0, 0, | 50 0, 0, 0, 0, |
| 82 NULL, NULL, hInst, NULL); | 51 NULL, NULL, hInst, NULL); |
| 83 return hwnd; | 52 return hwnd; |
| 84 } | 53 } |
| 85 | 54 |
| 86 DWORD WINAPI HostThread(void*) { | 55 typedef winfoundtn::ITypedEventHandler< |
| 87 // The sleeps simulates the delay we have in the actual metro code | 56 winapp::Core::CoreApplicationView*, |
| 88 // which takes in account the corewindow being created and some other | 57 winapp::Activation::IActivatedEventArgs*> ActivatedHandler; |
| 89 // unknown machinations of metro. | 58 |
| 90 ODS("Chrome main thread", ::GetCurrentThreadId()); | 59 typedef winfoundtn::ITypedEventHandler< |
| 91 ::Sleep(30); | 60 winui::Core::CoreWindow*, |
| 92 return globals.host_main(globals.host_context); | 61 winui::Core::WindowActivatedEventArgs*> WindowActivatedHandler; |
| 62 | |
| 63 typedef winfoundtn::ITypedEventHandler< | |
| 64 winui::Core::CoreWindow*, | |
| 65 winui::Core::AutomationProviderRequestedEventArgs*> | |
| 66 AutomationProviderHandler; | |
| 67 | |
| 68 typedef winfoundtn::ITypedEventHandler< | |
| 69 winui::Core::CoreWindow*, | |
| 70 winui::Core::CharacterReceivedEventArgs*> CharEventHandler; | |
| 71 | |
| 72 typedef winfoundtn::ITypedEventHandler< | |
| 73 winui::Core::CoreWindow*, | |
| 74 winui::Core::CoreWindowEventArgs*> CoreWindowEventHandler; | |
| 75 | |
| 76 typedef winfoundtn::ITypedEventHandler< | |
| 77 winui::Core::CoreWindow*, | |
| 78 winui::Core::InputEnabledEventArgs*> InputEnabledEventHandler; | |
| 79 | |
| 80 typedef winfoundtn::ITypedEventHandler< | |
| 81 winui::Core::CoreWindow*, | |
| 82 winui::Core::KeyEventArgs*> KeyEventHandler; | |
| 83 | |
| 84 typedef winfoundtn::ITypedEventHandler< | |
| 85 winui::Core::CoreWindow*, | |
| 86 winui::Core::PointerEventArgs*> PointerEventHandler; | |
| 87 | |
| 88 typedef winfoundtn::ITypedEventHandler< | |
| 89 winui::Core::CoreWindow*, | |
| 90 winui::Core::WindowSizeChangedEventArgs*> SizeChangedHandler; | |
| 91 | |
| 92 typedef winfoundtn::ITypedEventHandler< | |
| 93 winui::Core::CoreWindow*, | |
| 94 winui::Core::TouchHitTestingEventArgs*> TouchHitTestHandler; | |
| 95 | |
| 96 typedef winfoundtn::ITypedEventHandler< | |
| 97 winui::Core::CoreWindow*, | |
| 98 winui::Core::VisibilityChangedEventArgs*> VisibilityChangedHandler; | |
| 99 | |
| 100 // The following classes are the emulation of the WinRT system as exposed | |
| 101 // to metro applications. There is one application (ICoreApplication) which | |
| 102 // contains a series of Views (ICoreApplicationView) each one of them | |
| 103 // containing a CoreWindow which represents a surface that can drawnt to | |
|
zturner
2014/03/20 18:14:14
s/drawnt/drawn/
cpu_(ooo_6.6-7.5)
2014/03/20 22:13:13
Done.
zturner
2014/03/20 22:29:24
On a second look, it should actually say "that can
| |
| 104 // and that receives events. | |
| 105 // | |
| 106 // Here is the general dependency hierachy in terms of interfaces: | |
| 107 // | |
| 108 // IFrameworkViewSource --> IFrameworkView | |
| 109 // ^ | | |
| 110 // | | metro app | |
| 111 // --------------------------------------------------------------------- | |
| 112 // | | winRT system | |
| 113 // | v | |
| 114 // ICoreApplication ICoreApplicationView | |
| 115 // | | |
| 116 // v | |
| 117 // ICoreWindow ----> ICoreWindowInterop | |
| 118 // | | |
| 119 // | | |
| 120 // V | |
| 121 // real HWND | |
| 122 // | |
| 123 | |
| 124 class CoreWindowEmulation | |
| 125 : public mswr::RuntimeClass< | |
| 126 mswr::RuntimeClassFlags<mswr::WinRtClassicComMix>, | |
| 127 winui::Core::ICoreWindow, ICoreWindowInterop> { | |
| 128 public: | |
| 129 // ICoreWindow implementation: | |
| 130 virtual HRESULT STDMETHODCALLTYPE get_AutomationHostProvider( | |
| 131 IInspectable **value) { | |
| 132 return S_OK; | |
| 133 } | |
| 134 | |
| 135 virtual HRESULT STDMETHODCALLTYPE get_Bounds( | |
| 136 winfoundtn::Rect* value) { | |
| 137 return S_OK; | |
| 138 } | |
| 139 | |
| 140 virtual HRESULT STDMETHODCALLTYPE get_CustomProperties( | |
| 141 winfoundtn::Collections::IPropertySet **value) { | |
| 142 return S_OK; | |
| 143 } | |
| 144 | |
| 145 virtual HRESULT STDMETHODCALLTYPE get_Dispatcher( | |
| 146 winui::Core::ICoreDispatcher **value) { | |
| 147 return S_OK; | |
| 148 } | |
| 149 | |
| 150 virtual HRESULT STDMETHODCALLTYPE get_FlowDirection( | |
| 151 winui::Core::CoreWindowFlowDirection* value) { | |
| 152 return S_OK; | |
| 153 } | |
| 154 | |
| 155 virtual HRESULT STDMETHODCALLTYPE put_FlowDirection( | |
| 156 winui::Core::CoreWindowFlowDirection value) { | |
| 157 return S_OK; | |
| 158 } | |
| 159 | |
| 160 virtual HRESULT STDMETHODCALLTYPE get_IsInputEnabled( | |
| 161 boolean* value) { | |
| 162 return S_OK; | |
| 163 } | |
| 164 | |
| 165 virtual HRESULT STDMETHODCALLTYPE put_IsInputEnabled( | |
| 166 boolean value) { | |
| 167 return S_OK; | |
| 168 } | |
| 169 | |
| 170 virtual HRESULT STDMETHODCALLTYPE get_PointerCursor( | |
| 171 winui::Core::ICoreCursor **value) { | |
| 172 return S_OK; | |
| 173 } | |
| 174 | |
| 175 virtual HRESULT STDMETHODCALLTYPE put_PointerCursor( | |
| 176 winui::Core::ICoreCursor* value) { | |
| 177 return S_OK; | |
| 178 } | |
| 179 | |
| 180 virtual HRESULT STDMETHODCALLTYPE get_PointerPosition( | |
| 181 winfoundtn::Point* value) { | |
| 182 return S_OK; | |
| 183 } | |
| 184 | |
| 185 virtual HRESULT STDMETHODCALLTYPE get_Visible( | |
| 186 boolean* value) { | |
| 187 return S_OK; | |
| 188 } | |
| 189 | |
| 190 virtual HRESULT STDMETHODCALLTYPE Activate(void) { | |
| 191 return S_OK; | |
| 192 } | |
| 193 | |
| 194 virtual HRESULT STDMETHODCALLTYPE Close(void) { | |
| 195 return S_OK; | |
| 196 } | |
| 197 | |
| 198 virtual HRESULT STDMETHODCALLTYPE GetAsyncKeyState( | |
| 199 ABI::Windows::System::VirtualKey virtualKey, | |
| 200 winui::Core::CoreVirtualKeyStates* KeyState) { | |
| 201 return S_OK; | |
| 202 } | |
| 203 | |
| 204 virtual HRESULT STDMETHODCALLTYPE GetKeyState( | |
| 205 ABI::Windows::System::VirtualKey virtualKey, | |
| 206 winui::Core::CoreVirtualKeyStates* KeyState) { | |
| 207 return S_OK; | |
| 208 } | |
| 209 | |
| 210 virtual HRESULT STDMETHODCALLTYPE ReleasePointerCapture(void) { | |
| 211 return S_OK; | |
| 212 } | |
| 213 | |
| 214 virtual HRESULT STDMETHODCALLTYPE SetPointerCapture(void) { | |
| 215 return S_OK; | |
| 216 } | |
| 217 | |
| 218 virtual HRESULT STDMETHODCALLTYPE add_Activated( | |
| 219 WindowActivatedHandler* handler, | |
| 220 EventRegistrationToken* pCookie) { | |
| 221 return S_OK; | |
| 222 } | |
| 223 | |
| 224 virtual HRESULT STDMETHODCALLTYPE remove_Activated( | |
| 225 EventRegistrationToken cookie) { | |
| 226 return S_OK; | |
| 227 } | |
| 228 | |
| 229 virtual HRESULT STDMETHODCALLTYPE add_AutomationProviderRequested( | |
| 230 AutomationProviderHandler* handler, | |
| 231 EventRegistrationToken* cookie) { | |
| 232 return S_OK; | |
| 233 } | |
| 234 | |
| 235 virtual HRESULT STDMETHODCALLTYPE remove_AutomationProviderRequested( | |
| 236 EventRegistrationToken cookie) { | |
| 237 return S_OK; | |
| 238 } | |
| 239 | |
| 240 virtual HRESULT STDMETHODCALLTYPE add_CharacterReceived( | |
| 241 CharEventHandler* handler, | |
| 242 EventRegistrationToken* pCookie) { | |
| 243 return S_OK; | |
| 244 } | |
| 245 | |
| 246 virtual HRESULT STDMETHODCALLTYPE remove_CharacterReceived( | |
| 247 EventRegistrationToken cookie) { | |
| 248 return S_OK; | |
| 249 } | |
| 250 | |
| 251 virtual HRESULT STDMETHODCALLTYPE add_Closed( | |
| 252 CoreWindowEventHandler* handler, | |
| 253 EventRegistrationToken* pCookie) { | |
| 254 return S_OK; | |
| 255 } | |
| 256 | |
| 257 virtual HRESULT STDMETHODCALLTYPE remove_Closed( | |
| 258 EventRegistrationToken cookie) { | |
| 259 return S_OK; | |
| 260 } | |
| 261 | |
| 262 virtual HRESULT STDMETHODCALLTYPE add_InputEnabled( | |
| 263 InputEnabledEventHandler* handler, | |
| 264 EventRegistrationToken* pCookie) { | |
| 265 return S_OK; | |
| 266 } | |
| 267 | |
| 268 virtual HRESULT STDMETHODCALLTYPE remove_InputEnabled( | |
| 269 EventRegistrationToken cookie) { | |
| 270 return S_OK; | |
| 271 } | |
| 272 | |
| 273 virtual HRESULT STDMETHODCALLTYPE add_KeyDown( | |
| 274 KeyEventHandler* handler, | |
| 275 EventRegistrationToken* pCookie) { | |
| 276 return S_OK; | |
| 277 } | |
| 278 | |
| 279 virtual HRESULT STDMETHODCALLTYPE remove_KeyDown( | |
| 280 EventRegistrationToken cookie) { | |
| 281 return S_OK; | |
| 282 } | |
| 283 | |
| 284 virtual HRESULT STDMETHODCALLTYPE add_KeyUp( | |
| 285 KeyEventHandler* handler, | |
| 286 EventRegistrationToken* pCookie) { | |
| 287 return S_OK; | |
| 288 } | |
| 289 | |
| 290 virtual HRESULT STDMETHODCALLTYPE remove_KeyUp( | |
| 291 EventRegistrationToken cookie) { | |
| 292 return S_OK; | |
| 293 } | |
| 294 | |
| 295 virtual HRESULT STDMETHODCALLTYPE add_PointerCaptureLost( | |
| 296 PointerEventHandler* handler, | |
| 297 EventRegistrationToken* cookie) { | |
| 298 return S_OK; | |
| 299 } | |
| 300 | |
| 301 virtual HRESULT STDMETHODCALLTYPE remove_PointerCaptureLost( | |
| 302 EventRegistrationToken cookie) { | |
| 303 return S_OK; | |
| 304 } | |
| 305 | |
| 306 virtual HRESULT STDMETHODCALLTYPE add_PointerEntered( | |
| 307 PointerEventHandler* handler, | |
| 308 EventRegistrationToken* cookie) { | |
| 309 return S_OK; | |
| 310 } | |
| 311 | |
| 312 virtual HRESULT STDMETHODCALLTYPE remove_PointerEntered( | |
| 313 EventRegistrationToken cookie) { | |
| 314 return S_OK; | |
| 315 } | |
| 316 | |
| 317 virtual HRESULT STDMETHODCALLTYPE add_PointerExited( | |
| 318 PointerEventHandler* handler, | |
| 319 EventRegistrationToken* cookie) { | |
| 320 return S_OK; | |
| 321 } | |
| 322 | |
| 323 virtual HRESULT STDMETHODCALLTYPE remove_PointerExited( | |
| 324 EventRegistrationToken cookie) { | |
| 325 return S_OK; | |
| 326 } | |
| 327 | |
| 328 virtual HRESULT STDMETHODCALLTYPE add_PointerMoved( | |
| 329 PointerEventHandler* handler, | |
| 330 EventRegistrationToken* cookie) { | |
| 331 return S_OK; | |
| 332 } | |
| 333 | |
| 334 virtual HRESULT STDMETHODCALLTYPE remove_PointerMoved( | |
| 335 EventRegistrationToken cookie) { | |
| 336 return S_OK; | |
| 337 } | |
| 338 | |
| 339 virtual HRESULT STDMETHODCALLTYPE add_PointerPressed( | |
| 340 PointerEventHandler* handler, | |
| 341 EventRegistrationToken* cookie) { | |
| 342 return S_OK; | |
| 343 } | |
| 344 | |
| 345 virtual HRESULT STDMETHODCALLTYPE remove_PointerPressed( | |
| 346 EventRegistrationToken cookie) { | |
| 347 return S_OK; | |
| 348 } | |
| 349 | |
| 350 virtual HRESULT STDMETHODCALLTYPE add_PointerReleased( | |
| 351 PointerEventHandler* handler, | |
| 352 EventRegistrationToken* cookie) { | |
| 353 return S_OK; | |
| 354 } | |
| 355 | |
| 356 virtual HRESULT STDMETHODCALLTYPE remove_PointerReleased( | |
| 357 EventRegistrationToken cookie) { | |
| 358 return S_OK; | |
| 359 } | |
| 360 | |
| 361 virtual HRESULT STDMETHODCALLTYPE add_TouchHitTesting( | |
| 362 TouchHitTestHandler* handler, | |
| 363 EventRegistrationToken* pCookie) { | |
| 364 return S_OK; | |
| 365 } | |
| 366 | |
| 367 virtual HRESULT STDMETHODCALLTYPE remove_TouchHitTesting( | |
| 368 EventRegistrationToken cookie) { | |
| 369 return S_OK; | |
| 370 } | |
| 371 | |
| 372 virtual HRESULT STDMETHODCALLTYPE add_PointerWheelChanged( | |
| 373 PointerEventHandler* handler, | |
| 374 EventRegistrationToken* cookie) { | |
| 375 return S_OK; | |
| 376 } | |
| 377 | |
| 378 virtual HRESULT STDMETHODCALLTYPE remove_PointerWheelChanged( | |
| 379 EventRegistrationToken cookie) { | |
| 380 return S_OK; | |
| 381 } | |
| 382 | |
| 383 virtual HRESULT STDMETHODCALLTYPE add_SizeChanged( | |
| 384 SizeChangedHandler* handler, | |
| 385 EventRegistrationToken* pCookie) { | |
| 386 return S_OK; | |
| 387 } | |
| 388 | |
| 389 virtual HRESULT STDMETHODCALLTYPE remove_SizeChanged( | |
| 390 EventRegistrationToken cookie) { | |
| 391 return S_OK; | |
| 392 } | |
| 393 | |
| 394 virtual HRESULT STDMETHODCALLTYPE add_VisibilityChanged( | |
| 395 VisibilityChangedHandler* handler, | |
| 396 EventRegistrationToken* pCookie) { | |
| 397 return S_OK; | |
| 398 } | |
| 399 | |
| 400 virtual HRESULT STDMETHODCALLTYPE remove_VisibilityChanged( | |
| 401 EventRegistrationToken cookie) { | |
| 402 return S_OK; | |
| 403 } | |
| 404 | |
| 405 // ICoreWindowInterop implementation: | |
| 406 virtual HRESULT STDMETHODCALLTYPE get_WindowHandle( | |
| 407 HWND *hwnd) { | |
| 408 return S_OK; | |
| 409 } | |
| 410 | |
| 411 virtual HRESULT STDMETHODCALLTYPE put_MessageHandled( | |
| 412 boolean value) { | |
| 413 return S_OK; | |
| 414 } | |
| 415 | |
| 416 }; | |
| 417 | |
| 418 class CoreApplicationViewEmulation | |
| 419 : public mswr::RuntimeClass<winapp::Core::ICoreApplicationView> { | |
| 420 public: | |
| 421 CoreApplicationViewEmulation() { | |
| 422 core_window_ = mswr::Make<CoreWindowEmulation>(); | |
| 423 } | |
| 424 | |
| 425 virtual HRESULT STDMETHODCALLTYPE get_CoreWindow( | |
| 426 winui::Core::ICoreWindow **value) { | |
| 427 if (!core_window_) | |
| 428 return E_FAIL; | |
| 429 *value = core_window_.Get(); | |
| 430 return S_OK; | |
| 431 } | |
| 432 | |
| 433 virtual HRESULT STDMETHODCALLTYPE add_Activated( | |
| 434 ActivatedHandler* handler, | |
| 435 EventRegistrationToken* token) { | |
| 436 return S_OK; | |
| 437 } | |
| 438 | |
| 439 virtual HRESULT STDMETHODCALLTYPE remove_Activated( | |
| 440 EventRegistrationToken token) { | |
| 441 return S_OK; | |
| 442 } | |
| 443 | |
| 444 virtual HRESULT STDMETHODCALLTYPE get_IsMain( | |
| 445 boolean* value) { | |
| 446 return S_OK; | |
| 447 } | |
| 448 | |
| 449 virtual HRESULT STDMETHODCALLTYPE get_IsHosted( | |
| 450 boolean* value) { | |
| 451 return S_OK; | |
| 452 } | |
| 453 | |
| 454 private: | |
| 455 mswr::ComPtr<winui::Core::ICoreWindow> core_window_; | |
| 456 }; | |
| 457 | |
| 458 // Hey I'm just fakeMetro, | |
| 459 // And this is crazy, | |
| 460 // But here's my ICoreApplication, | |
| 461 // So call me, maybe! | |
|
cpu_(ooo_6.6-7.5)
2014/03/20 17:50:32
I'll remove the silly comment.
cpu_(ooo_6.6-7.5)
2014/03/20 22:13:13
Done.
| |
| 462 class CoreApplicationWin7Emulation | |
| 463 : public mswr::RuntimeClass<winapp::Core::ICoreApplication, | |
| 464 winapp::Core::ICoreApplicationExit> { | |
| 465 public: | |
| 466 // ICoreApplication implementation: | |
| 467 | |
| 468 virtual HRESULT STDMETHODCALLTYPE get_Id( | |
|
zturner
2014/03/20 18:14:14
Don't these (and other similar) methods need to se
cpu_(ooo_6.6-7.5)
2014/03/20 22:13:13
Correct, I am trying to reduce the size of the CL.
| |
| 469 HSTRING* value) { | |
| 470 return S_OK; | |
| 471 } | |
| 472 | |
| 473 virtual HRESULT STDMETHODCALLTYPE add_Suspending( | |
| 474 winfoundtn::IEventHandler<winapp::SuspendingEventArgs*>* handler, | |
| 475 EventRegistrationToken* token) { | |
| 476 return S_OK; | |
| 477 } | |
| 478 | |
| 479 virtual HRESULT STDMETHODCALLTYPE remove_Suspending( | |
| 480 EventRegistrationToken token) { | |
| 481 return S_OK; | |
| 482 } | |
| 483 | |
| 484 virtual HRESULT STDMETHODCALLTYPE add_Resuming( | |
| 485 winfoundtn::IEventHandler<IInspectable*>* handler, | |
| 486 EventRegistrationToken* token) { | |
| 487 return S_OK; | |
| 488 } | |
| 489 | |
| 490 virtual HRESULT STDMETHODCALLTYPE remove_Resuming( | |
| 491 EventRegistrationToken token) { | |
| 492 return S_OK; | |
| 493 } | |
| 494 | |
| 495 virtual HRESULT STDMETHODCALLTYPE get_Properties( | |
| 496 winfoundtn::Collections::IPropertySet** value) { | |
| 497 return S_OK; | |
| 498 } | |
| 499 | |
| 500 virtual HRESULT STDMETHODCALLTYPE GetCurrentView( | |
| 501 winapp::Core::ICoreApplicationView** value) { | |
| 502 return S_OK; | |
| 503 } | |
| 504 | |
| 505 virtual HRESULT STDMETHODCALLTYPE Run( | |
|
cpu_(ooo_6.6-7.5)
2014/03/20 17:50:32
Here is the only meat in this new set of classes.
| |
| 506 winapp::Core::IFrameworkViewSource* viewSource) { | |
| 507 HRESULT hr = viewSource->CreateView(app_view_.GetAddressOf()); | |
| 508 if (FAILED(hr)) | |
| 509 return hr; | |
| 510 view_emulation_ = mswr::Make<CoreApplicationViewEmulation>(); | |
| 511 hr = app_view_->Initialize(view_emulation_.Get()); | |
| 512 if (FAILED(hr)) | |
| 513 return hr; | |
| 514 mswr::ComPtr<winui::Core::ICoreWindow> core_window; | |
| 515 hr = view_emulation_->get_CoreWindow(core_window.GetAddressOf()); | |
| 516 if (FAILED(hr)) | |
| 517 return hr; | |
| 518 hr = app_view_->SetWindow(core_window.Get()); | |
| 519 return hr; | |
| 520 } | |
| 521 | |
| 522 virtual HRESULT STDMETHODCALLTYPE RunWithActivationFactories( | |
| 523 winfoundtn::IGetActivationFactory* activationFactoryCallback) { | |
| 524 return S_OK; | |
| 525 } | |
| 526 | |
| 527 // ICoreApplicationExit implementation: | |
| 528 | |
| 529 virtual HRESULT STDMETHODCALLTYPE Exit(void) { | |
| 530 return S_OK; | |
| 531 } | |
| 532 | |
| 533 virtual HRESULT STDMETHODCALLTYPE add_Exiting( | |
| 534 winfoundtn::IEventHandler<IInspectable*>* handler, | |
| 535 EventRegistrationToken* token) { | |
| 536 return S_OK; | |
| 537 } | |
| 538 | |
| 539 virtual HRESULT STDMETHODCALLTYPE remove_Exiting( | |
| 540 EventRegistrationToken token) { | |
| 541 return S_OK; | |
| 542 } | |
| 543 | |
| 544 private: | |
| 545 mswr::ComPtr<winapp::Core::IFrameworkView> app_view_; | |
| 546 mswr::ComPtr<winapp::Core::ICoreApplicationView> view_emulation_; | |
| 547 }; | |
| 548 | |
| 549 | |
| 550 mswr::ComPtr<winapp::Core::ICoreApplication> InitWindows7() { | |
| 551 HRESULT hr = ::CoInitializeEx(NULL, COINIT_MULTITHREADED); | |
|
zturner
2014/03/20 18:14:14
Where do we call CoUninitialize()?
cpu_(ooo_6.6-7.5)
2014/03/20 22:13:13
We don't. I normally never call that. It only brin
| |
| 552 if (FAILED(hr)) | |
| 553 CHECK(false); | |
| 554 return mswr::Make<CoreApplicationWin7Emulation>(); | |
| 93 } | 555 } |
| 94 | 556 |
| 95 extern "C" __declspec(dllexport) | |
| 96 int InitMetro(LPTHREAD_START_ROUTINE thread_proc, void* context) { | |
| 97 ODS("InitMetro [Win7 emulation]"); | |
| 98 HWND window = CreateMetroTopLevelWindow(); | |
| 99 if (!window) | |
| 100 return 1; | |
| 101 // This magic incatation tells windows that the window is going fullscreen | |
| 102 // so the taskbar gets out of the wait automatically. | |
| 103 ::SetWindowPos(window, | |
| 104 HWND_TOP, | |
| 105 0,0, | |
| 106 GetSystemMetrics(SM_CXSCREEN), | |
| 107 GetSystemMetrics(SM_CYSCREEN), | |
| 108 SWP_SHOWWINDOW); | |
| 109 | |
| 110 // Ready to start our caller. | |
| 111 globals.core_window = window; | |
| 112 globals.host_main = thread_proc; | |
| 113 globals.host_context = context; | |
| 114 HANDLE thread = ::CreateThread(NULL, 0, &HostThread, NULL, 0, NULL); | |
| 115 | |
| 116 // Main message loop. | |
| 117 MSG msg = {0}; | |
| 118 while (GetMessage(&msg, NULL, 0, 0)) { | |
| 119 TranslateMessage(&msg); | |
| 120 DispatchMessage(&msg); | |
| 121 } | |
| 122 | |
| 123 return (int) msg.wParam; | |
| 124 } | |
| 125 | |
| 126 extern "C" _declspec(dllexport) HWND GetRootWindow() { | |
| 127 ODS("GetRootWindow", ULONG_PTR(globals.core_window)); | |
| 128 return globals.core_window; | |
| 129 } | |
| 130 | |
| 131 extern "C" _declspec(dllexport) void SetFrameWindow(HWND window) { | |
| 132 ODS("SetFrameWindow", ULONG_PTR(window)); | |
| 133 globals.host_window = window; | |
| 134 } | |
| 135 | |
| 136 extern "C" __declspec(dllexport) const wchar_t* GetInitialUrl() { | |
| 137 return L""; | |
| 138 } | |
| 139 | |
| OLD | NEW |