blob: b146ced6ce81c044cea6e79060b2718a931b6a16 [file] [log] [blame]
Constantin Kaplinsky47ed8d32004-10-08 09:43:57 +00001/* Copyright (C) 2002-2003 RealVNC Ltd. All Rights Reserved.
2 *
3 * This is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This software is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this software; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
16 * USA.
17 */
18
19// -=- ConnectingDialog.h
20
21// Dialog to indicate to the user that the viewer is attempting to make an
22// outgoing connection.
23
24#ifndef __RFB_WIN32_CONNECTING_DLG_H__
25#define __RFB_WIN32_CONNECTING_DLG_H__
26
27#include <rfb_win32/Dialog.h>
28#include <rfb/Threading.h>
29#include <vncviewer/resource.h>
30
31namespace rfb {
32
33 namespace win32 {
34
35 BOOL CALLBACK ConnectingDlgProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam ) {
36 switch (uMsg) {
37 case WM_INITDIALOG:
38 {
39 SetWindowLong(hwnd, GWL_USERDATA, lParam);
40 return TRUE;
41 }
42 case WM_COMMAND:
43 switch (LOWORD(wParam)) {
44 case IDCANCEL:
45 network::Socket* sock = (network::Socket*) GetWindowLong(hwnd, GWL_USERDATA);
46 sock->shutdown();
47 EndDialog(hwnd, FALSE);
48 return TRUE;
49 }
50 break;
51 case WM_DESTROY:
52 EndDialog(hwnd, TRUE);
53 return TRUE;
54 }
55 return 0;
56 }
57
58 // *** hacky bit - should use async connect so dialog behaves properly
59 class ConnectingDialog : public Thread {
60 public:
61 ConnectingDialog() : Thread("ConnectingDialog") {
62 dialog = 0;
63 active = true;
64 start();
65 }
66 virtual ~ConnectingDialog() {
67 // *** join() required here because otherwise ~Thread calls Thread::join()
68 join();
69 }
70 virtual void run() {
71 dialog = CreateDialogParam(GetModuleHandle(0),
72 MAKEINTRESOURCE(IDD_CONNECTING_DLG), 0, &ConnectingDlgProc, 0);
73 ShowWindow(dialog, SW_SHOW);
74 MSG msg;
75 while (active && GetMessage(&msg, dialog, 0, 0)) {
76 DispatchMessage(&msg);
77 }
78 DestroyWindow(dialog);
79 }
80 virtual Thread* join() {
81 active = false;
82 if (dialog)
83 PostMessage(dialog, WM_QUIT, 0, 0);
84 return Thread::join();
85 }
86 protected:
87 HWND dialog;
88 bool active;
89 };
90
91 };
92
93};
94
95#endif