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
3 // found in the LICENSE file.
8 #include "base/callback.h"
9 #include "base/compiler_specific.h"
10 #include "base/location.h"
11 #include "base/logging.h"
12 #include "base/process/memory.h"
13 #include "base/single_thread_task_runner.h"
14 #include "base/strings/utf_string_conversions.h"
15 #include "remoting/host/continue_window.h"
16 #include "remoting/host/win/core_resource.h"
22 class ContinueWindowWin
: public ContinueWindow
{
25 virtual ~ContinueWindowWin();
28 // ContinueWindow overrides.
29 virtual void ShowUi() override
;
30 virtual void HideUi() override
;
33 static BOOL CALLBACK
DialogProc(HWND hwmd
, UINT msg
, WPARAM wParam
,
36 BOOL
OnDialogMessage(HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
);
42 DISALLOW_COPY_AND_ASSIGN(ContinueWindowWin
);
45 ContinueWindowWin::ContinueWindowWin()
49 ContinueWindowWin::~ContinueWindowWin() {
53 void ContinueWindowWin::ShowUi() {
54 DCHECK(CalledOnValidThread());
57 HMODULE instance
= base::GetModuleFromAddress(&DialogProc
);
58 hwnd_
= CreateDialogParam(instance
, MAKEINTRESOURCE(IDD_CONTINUE
), nullptr,
59 (DLGPROC
)DialogProc
, (LPARAM
)this);
61 LOG(ERROR
) << "Unable to create Disconnect dialog for remoting.";
65 ShowWindow(hwnd_
, SW_SHOW
);
68 void ContinueWindowWin::HideUi() {
69 DCHECK(CalledOnValidThread());
74 BOOL CALLBACK
ContinueWindowWin::DialogProc(HWND hwnd
, UINT msg
,
75 WPARAM wParam
, LPARAM lParam
) {
76 ContinueWindowWin
* win
= nullptr;
77 if (msg
== WM_INITDIALOG
) {
78 win
= reinterpret_cast<ContinueWindowWin
*>(lParam
);
80 SetWindowLongPtr(hwnd
, DWLP_USER
, (LONG_PTR
)win
);
82 LONG_PTR lp
= GetWindowLongPtr(hwnd
, DWLP_USER
);
83 win
= reinterpret_cast<ContinueWindowWin
*>(lp
);
87 return win
->OnDialogMessage(hwnd
, msg
, wParam
, lParam
);
90 BOOL
ContinueWindowWin::OnDialogMessage(HWND hwnd
, UINT msg
,
91 WPARAM wParam
, LPARAM lParam
) {
92 DCHECK(CalledOnValidThread());
96 // Ignore close messages.
99 // Ensure we don't try to use the HWND anymore.
103 switch (LOWORD(wParam
)) {
104 case IDC_CONTINUE_DEFAULT
:
106 ::EndDialog(hwnd
, LOWORD(wParam
));
109 case IDC_CONTINUE_CANCEL
:
111 ::EndDialog(hwnd
, LOWORD(wParam
));
119 void ContinueWindowWin::EndDialog() {
120 DCHECK(CalledOnValidThread());
123 ::DestroyWindow(hwnd_
);
131 scoped_ptr
<HostWindow
> HostWindow::CreateContinueWindow() {
132 return make_scoped_ptr(new ContinueWindowWin());
135 } // namespace remoting