Index: win8/metro_driver/metro_driver_win7.cc |
diff --git a/win8/metro_driver/metro_driver_win7.cc b/win8/metro_driver/metro_driver_win7.cc |
index 2e5aba73fc4d6b2f9a065af77522ca5cce87dacb..76dc617d543052d064721479ed9d136011da0af5 100644 |
--- a/win8/metro_driver/metro_driver_win7.cc |
+++ b/win8/metro_driver/metro_driver_win7.cc |
@@ -5,25 +5,31 @@ |
#include "stdafx.h" |
#include <corewindow.h> |
+#include "base/command_line.h" |
#include "base/logging.h" |
EXTERN_C IMAGE_DOS_HEADER __ImageBase; |
+int g_window_count = 0; |
LRESULT CALLBACK WndProc(HWND hwnd, UINT message, |
WPARAM wparam, LPARAM lparam) { |
PAINTSTRUCT ps; |
HDC hdc; |
switch (message) { |
ananta
2014/04/11 02:25:24
Please add some comments here about why we need th
|
+ case WM_CREATE: |
+ ++g_window_count; |
+ break; |
case WM_PAINT: |
hdc = ::BeginPaint(hwnd, &ps); |
EndPaint(hwnd, &ps); |
break; |
- case WM_LBUTTONUP: |
- // TODO(cpu): Remove this test code. |
- ::InvalidateRect(hwnd, NULL, TRUE); |
+ case WM_CLOSE: |
+ DestroyWindow(hwnd); |
break; |
case WM_DESTROY: |
- PostQuitMessage(0); |
+ --g_window_count; |
+ if (!g_window_count) |
+ PostQuitMessage(0); |
break; |
default: |
return ::DefWindowProc(hwnd, message, wparam, lparam); |
@@ -51,7 +57,7 @@ HWND CreateMetroTopLevelWindow() { |
MAKEINTATOM(::RegisterClassExW(&wcex)), |
L"metro_win7", |
WS_POPUP | WS_VISIBLE, |
- 0, 0, 1024, 1024, |
+ 0, 0, 1600, 900, |
NULL, NULL, hInst, NULL); |
return hwnd; |
} |
@@ -146,7 +152,7 @@ class CoreDispacherEmulation : |
return E_FAIL; |
MSG msg = {0}; |
- while(::GetMessage(&msg, NULL, 0, 0) != 0) { |
+ while((::GetMessage(&msg, NULL, 0, 0) != 0) && g_window_count > 0) { |
::TranslateMessage(&msg); |
::DispatchMessage(&msg); |
} |
@@ -194,7 +200,8 @@ class CoreWindowEmulation |
} |
~CoreWindowEmulation() { |
- ::DestroyWindow(core_hwnd_); |
+ if (core_hwnd_) |
+ ::DestroyWindow(core_hwnd_); |
} |
// ICoreWindow implementation: |
@@ -269,6 +276,8 @@ class CoreWindowEmulation |
} |
virtual HRESULT STDMETHODCALLTYPE Close(void) { |
+ ::PostMessage(core_hwnd_, WM_CLOSE, 0, 0); |
+ core_hwnd_ = NULL; |
return S_OK; |
} |
@@ -542,6 +551,10 @@ class CoreApplicationViewEmulation |
HRESULT Activate() { |
if (activated_handler_) { |
+ // This form means chrome or a test has launched the viewer. |
+ if (CommandLine::ForCurrentProcess()->HasSwitch("connect")) |
+ return activated_handler_->Invoke(this, nullptr); |
+ // This form used to reach other integration code paths. |
auto ae = mswr::Make<ActivatedEvent>( |
winapp::Activation::ActivationKind_File); |
return activated_handler_->Invoke(this, ae.Get()); |
@@ -550,6 +563,10 @@ class CoreApplicationViewEmulation |
} |
} |
+ HRESULT Close() { |
+ return core_window_->Close(); |
+ } |
+ |
// ICoreApplicationView implementation: |
virtual HRESULT STDMETHODCALLTYPE get_CoreWindow( |
winui::Core::ICoreWindow** value) { |
@@ -585,7 +602,7 @@ class CoreApplicationViewEmulation |
} |
private: |
- mswr::ComPtr<winui::Core::ICoreWindow> core_window_; |
+ mswr::ComPtr<CoreWindowEmulation> core_window_; |
mswr::ComPtr<ActivatedHandler> activated_handler_; |
}; |
@@ -664,8 +681,8 @@ class CoreApplicationWin7Emulation |
// ICoreApplicationExit implementation: |
- virtual HRESULT STDMETHODCALLTYPE Exit(void) { |
- return S_OK; |
+ virtual HRESULT STDMETHODCALLTYPE Exit() { |
+ return view_emulation_->Close(); |
} |
virtual HRESULT STDMETHODCALLTYPE add_Exiting( |