You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ConnectingDialog.h 2.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /* 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. // -=- ConnectingDialog.h
  19. // Dialog to indicate to the user that the viewer is attempting to make an
  20. // outgoing connection.
  21. #ifndef __RFB_WIN32_CONNECTING_DLG_H__
  22. #define __RFB_WIN32_CONNECTING_DLG_H__
  23. #include <rfb_win32/Dialog.h>
  24. #include <rfb/Threading.h>
  25. #include <vncviewer/resource.h>
  26. namespace rfb {
  27. namespace win32 {
  28. BOOL CALLBACK ConnectingDlgProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam ) {
  29. switch (uMsg) {
  30. case WM_INITDIALOG:
  31. {
  32. SetWindowLong(hwnd, GWL_USERDATA, lParam);
  33. return TRUE;
  34. }
  35. case WM_COMMAND:
  36. switch (LOWORD(wParam)) {
  37. case IDCANCEL:
  38. network::Socket* sock = (network::Socket*) GetWindowLong(hwnd, GWL_USERDATA);
  39. sock->shutdown();
  40. EndDialog(hwnd, FALSE);
  41. return TRUE;
  42. }
  43. break;
  44. case WM_DESTROY:
  45. EndDialog(hwnd, TRUE);
  46. return TRUE;
  47. }
  48. return 0;
  49. }
  50. // *** hacky bit - should use async connect so dialog behaves properly
  51. class ConnectingDialog : public Thread {
  52. public:
  53. ConnectingDialog() : Thread("ConnectingDialog") {
  54. dialog = 0;
  55. active = true;
  56. start();
  57. }
  58. virtual ~ConnectingDialog() {
  59. // *** join() required here because otherwise ~Thread calls Thread::join()
  60. join();
  61. }
  62. virtual void run() {
  63. dialog = CreateDialogParam(GetModuleHandle(0),
  64. MAKEINTRESOURCE(IDD_CONNECTING_DLG), 0, &ConnectingDlgProc, 0);
  65. ShowWindow(dialog, SW_SHOW);
  66. MSG msg;
  67. while (active && GetMessage(&msg, dialog, 0, 0)) {
  68. DispatchMessage(&msg);
  69. }
  70. DestroyWindow(dialog);
  71. }
  72. virtual Thread* join() {
  73. active = false;
  74. if (dialog)
  75. PostMessage(dialog, WM_QUIT, 0, 0);
  76. return Thread::join();
  77. }
  78. protected:
  79. HWND dialog;
  80. bool active;
  81. };
  82. };
  83. };
  84. #endif