blob: 6b187117780da7e06216b615ffd9628a69fc7b83 [file] [log] [blame]
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +00001/* Copyright (C) 2004 TightVNC Team. 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// -=- RFB Player for Win32
20
21#include <conio.h>
22
23#include <rfb/LogWriter.h>
24#include <rfb/Exception.h>
25#include <rfb/Threading.h>
26
27#include <rfb_win32/Win32Util.h>
28#include <rfb_win32/WMShatter.h>
29
30#include <rfbplayer/rfbplayer.h>
31#include <rfbplayer/utils.h>
32#include <rfbplayer/resource.h>
33
34using namespace rfb;
35using namespace rfb::win32;
36
37// -=- Variables & consts
38
39static LogWriter vlog("RfbPlayer");
40
41TStr rfb::win32::AppName("RfbPlayer");
42extern const char* buildTime;
43
44// -=- RfbPlayer's defines
45
46#define strcasecmp _stricmp
george824ea27f62005-01-29 15:03:06 +000047#define MAX_SPEED 10
george82d4d69e62005-02-05 09:23:18 +000048#define MAX_POS_TRACKBAR_RANGE 50
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +000049
george82d070c692005-01-19 16:44:04 +000050#define ID_TOOLBAR 500
51#define ID_PLAY 510
52#define ID_PAUSE 520
53#define ID_TIME_STATIC 530
54#define ID_SPEED_STATIC 540
55#define ID_SPEED_EDIT 550
56#define ID_POS_TRACKBAR 560
57#define ID_SPEED_UPDOWN 570
58
59
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +000060//
61// -=- RfbPlayerClass
62
63//
64// Window class used as the basis for RfbPlayer instance
65//
66
67class RfbPlayerClass {
68public:
69 RfbPlayerClass();
70 ~RfbPlayerClass();
71 ATOM classAtom;
72 HINSTANCE instance;
73};
74
75LRESULT CALLBACK RfbPlayerProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) {
76 LRESULT result;
77
78 if (msg == WM_CREATE)
79 SetWindowLong(hwnd, GWL_USERDATA, (long)((CREATESTRUCT*)lParam)->lpCreateParams);
80 else if (msg == WM_DESTROY) {
81 RfbPlayer* _this = (RfbPlayer*) GetWindowLong(hwnd, GWL_USERDATA);
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +000082
83 // Resume playback (It's need to quit from FbsInputStream::waitWhilePaused())
84 _this->setPaused(false);
85 SetWindowLong(hwnd, GWL_USERDATA, 0);
86 }
87 RfbPlayer* _this = (RfbPlayer*) GetWindowLong(hwnd, GWL_USERDATA);
88 if (!_this) {
89 vlog.info("null _this in %x, message %u", hwnd, msg);
90 return DefWindowProc(hwnd, msg, wParam, lParam);
91 }
92
93 try {
94 result = _this->processMainMessage(hwnd, msg, wParam, lParam);
95 } catch (rdr::Exception& e) {
96 vlog.error("untrapped: %s", e.str());
97 }
98
99 return result;
100};
101
102RfbPlayerClass::RfbPlayerClass() : classAtom(0) {
103 WNDCLASS wndClass;
104 wndClass.style = 0;
105 wndClass.lpfnWndProc = RfbPlayerProc;
106 wndClass.cbClsExtra = 0;
107 wndClass.cbWndExtra = 0;
108 wndClass.hInstance = instance = GetModuleHandle(0);
109 wndClass.hIcon = (HICON)LoadImage(GetModuleHandle(0),
george827214b822004-12-12 07:02:51 +0000110 MAKEINTRESOURCE(IDI_ICON), IMAGE_ICON, 0, 0, LR_SHARED);
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +0000111 if (!wndClass.hIcon)
112 printf("unable to load icon:%ld", GetLastError());
113 wndClass.hCursor = LoadCursor(NULL, IDC_ARROW);
114 wndClass.hbrBackground = HBRUSH(COLOR_WINDOW);
george82c2c691f2004-12-08 18:04:14 +0000115 wndClass.lpszMenuName = MAKEINTRESOURCE(IDR_MENU);
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +0000116 wndClass.lpszClassName = _T("RfbPlayerClass");
117 classAtom = RegisterClass(&wndClass);
118 if (!classAtom) {
119 throw rdr::SystemException("unable to register RfbPlayer window class",
120 GetLastError());
121 }
122}
123
124RfbPlayerClass::~RfbPlayerClass() {
125 if (classAtom) {
126 UnregisterClass((const TCHAR*)classAtom, instance);
127 }
128}
129
130RfbPlayerClass baseClass;
131
132//
133// -=- RfbFrameClass
134
135//
136// Window class used to displaying the rfb data
137//
138
139class RfbFrameClass {
140public:
141 RfbFrameClass();
142 ~RfbFrameClass();
143 ATOM classAtom;
144 HINSTANCE instance;
145};
146
147LRESULT CALLBACK FrameProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) {
148 LRESULT result;
149
150 if (msg == WM_CREATE)
151 SetWindowLong(hwnd, GWL_USERDATA, (long)((CREATESTRUCT*)lParam)->lpCreateParams);
152 else if (msg == WM_DESTROY)
153 SetWindowLong(hwnd, GWL_USERDATA, 0);
154 RfbPlayer* _this = (RfbPlayer*) GetWindowLong(hwnd, GWL_USERDATA);
155 if (!_this) {
156 vlog.info("null _this in %x, message %u", hwnd, msg);
157 return DefWindowProc(hwnd, msg, wParam, lParam);
158 }
159
160 try {
161 result = _this->processFrameMessage(hwnd, msg, wParam, lParam);
162 } catch (rdr::Exception& e) {
163 vlog.error("untrapped: %s", e.str());
164 }
165
166 return result;
167}
168
169RfbFrameClass::RfbFrameClass() : classAtom(0) {
170 WNDCLASS wndClass;
171 wndClass.style = 0;
172 wndClass.lpfnWndProc = FrameProc;
173 wndClass.cbClsExtra = 0;
174 wndClass.cbWndExtra = 0;
175 wndClass.hInstance = instance = GetModuleHandle(0);
176 wndClass.hIcon = 0;
177 wndClass.hCursor = LoadCursor(NULL, IDC_ARROW);
178 wndClass.hbrBackground = 0;
179 wndClass.lpszMenuName = 0;
180 wndClass.lpszClassName = _T("RfbPlayerClass1");
181 classAtom = RegisterClass(&wndClass);
182 if (!classAtom) {
183 throw rdr::SystemException("unable to register RfbPlayer window class",
184 GetLastError());
185 }
186}
187
188RfbFrameClass::~RfbFrameClass() {
189 if (classAtom) {
190 UnregisterClass((const TCHAR*)classAtom, instance);
191 }
192}
193
194RfbFrameClass frameClass;
195
196//
197// -=- RfbPlayer instance implementation
198//
199
200RfbPlayer::RfbPlayer(char *_fileName, long _initTime = 0, double _playbackSpeed = 1.0,
201 bool _autoplay = false, bool _showControls = true,
202 bool _acceptBell = false)
203: RfbProto(_fileName), initTime(_initTime), playbackSpeed(_playbackSpeed),
204 autoplay(_autoplay), showControls(_showControls), buffer(0), client_size(0, 0, 32, 32),
george82b4915432005-01-30 17:10:57 +0000205 window_size(0, 0, 32, 32), cutText(0), seekMode(false), fileName(_fileName),
george82d4d69e62005-02-05 09:23:18 +0000206 serverInitTime(0), lastPos(0), timeStatic(0), speedEdit(0), posTrackBar(0),
george828a471482005-02-06 07:15:53 +0000207 speedUpDown(0), acceptBell(_acceptBell), rfbReader(0), sessionTimeMs(0),
208 sliderDraging(false), sliderStepMs(0) {
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +0000209
210 if (showControls)
george82d070c692005-01-19 16:44:04 +0000211 CTRL_BAR_HEIGHT = 28;
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +0000212 else
213 CTRL_BAR_HEIGHT = 0;
214
george823c8fbbf2005-01-24 11:09:08 +0000215 // Reset the full session time
216 strcpy(fullSessionTime, "00m:00s");
217
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +0000218 // Create the main window
219 const TCHAR* name = _T("RfbPlayer");
220 mainHwnd = CreateWindow((const TCHAR*)baseClass.classAtom, name, WS_OVERLAPPEDWINDOW,
george8210313102005-01-17 13:11:40 +0000221 0, 0, 640, 480, 0, 0, baseClass.instance, this);
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +0000222 if (!mainHwnd) {
223 throw rdr::SystemException("unable to create WMNotifier window instance", GetLastError());
224 }
225 vlog.debug("created window \"%s\" (%x)", (const char*)CStr(name), getMainHandle());
226
227 // Create the backing buffer
228 buffer = new win32::DIBSectionBuffer(getFrameHandle());
george8210313102005-01-17 13:11:40 +0000229 setVisible(true);
george8217e92cb2005-01-31 16:01:02 +0000230
231 // Open the session file
232 if (fileName) {
233 openSessionFile(fileName);
234 }
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +0000235}
236
237RfbPlayer::~RfbPlayer() {
238 vlog.debug("~RfbPlayer");
george82ce8dc3a2005-01-31 13:06:54 +0000239 if (rfbReader) {
george82ce8dc3a2005-01-31 13:06:54 +0000240 delete rfbReader->join();
241 rfbReader = 0;
242 }
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +0000243 if (mainHwnd) {
244 setVisible(false);
245 DestroyWindow(mainHwnd);
246 mainHwnd = 0;
247 }
248 delete buffer;
249 delete cutText;
250 vlog.debug("~RfbPlayer done");
251}
252
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +0000253LRESULT
254RfbPlayer::processMainMessage(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) {
255 switch (msg) {
256
257 // -=- Process standard window messages
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +0000258
259 case WM_CREATE:
260 {
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +0000261 // Create the frame window
262 frameHwnd = CreateWindowEx(WS_EX_CLIENTEDGE, (const TCHAR*)frameClass.classAtom,
263 0, WS_CHILD | WS_VISIBLE, 0, CTRL_BAR_HEIGHT, 10, CTRL_BAR_HEIGHT + 10,
264 hwnd, 0, frameClass.instance, this);
265
george82d070c692005-01-19 16:44:04 +0000266 createToolBar(hwnd);
267
george82006f2792005-02-05 07:40:47 +0000268 hMenu = GetMenu(hwnd);
george825c13c662005-01-27 14:48:23 +0000269
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +0000270 return 0;
271 }
272
george827214b822004-12-12 07:02:51 +0000273 // Process the main menu and toolbar's messages
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +0000274
275 case WM_COMMAND:
george825c13c662005-01-27 14:48:23 +0000276 switch (LOWORD(wParam)) {
277 case ID_PLAY:
278 setPaused(false);
george825c13c662005-01-27 14:48:23 +0000279 break;
280 case ID_PAUSE:
281 setPaused(true);
george825c13c662005-01-27 14:48:23 +0000282 break;
283 case ID_STOP:
284 if (getTimeOffset() != 0) {
george82006f2792005-02-05 07:40:47 +0000285 stopPlayback();
george825c13c662005-01-27 14:48:23 +0000286 }
george825c13c662005-01-27 14:48:23 +0000287 break;
288 case ID_PLAYPAUSE:
289 if (isPaused()) {
290 setPaused(false);
george825c13c662005-01-27 14:48:23 +0000291 } else {
292 setPaused(true);
george825c13c662005-01-27 14:48:23 +0000293 }
george825c13c662005-01-27 14:48:23 +0000294 break;
295 case ID_FULLSCREEN:
296 MessageBox(getMainHandle(), "It is not working yet!", "RfbPlayer", MB_OK);
297 break;
george824ea27f62005-01-29 15:03:06 +0000298 case ID_RETURN:
299 // Update the speed if return pressed in speedEdit
300 if (speedEdit == GetFocus()) {
301 char speedStr[20], *stopStr;
302 GetWindowText(speedEdit, speedStr, sizeof(speedStr));
303 double speed = strtod(speedStr, &stopStr);
304 if (speed > 0) {
305 speed = min(MAX_SPEED, speed);
306 // Update speedUpDown position
307 SendMessage(speedUpDown, UDM_SETPOS,
308 0, MAKELONG((short)(speed / 0.5), 0));
309 } else {
310 speed = getSpeed();
311 }
312 setSpeed(speed);
313 sprintf(speedStr, "%.2f", speed);
314 SetWindowText(speedEdit, speedStr);
315 }
316 break;
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +0000317 }
318 break;
319
320 // Update frame's window size and add scrollbars if required
321
322 case WM_SIZE:
323 {
george82d070c692005-01-19 16:44:04 +0000324
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +0000325 Point old_offset = bufferToClient(Point(0, 0));
326
327 // Update the cached sizing information
328 RECT r;
329 GetClientRect(getMainHandle(), &r);
330 MoveWindow(getFrameHandle(), 0, CTRL_BAR_HEIGHT, r.right - r.left,
331 r.bottom - r.top - CTRL_BAR_HEIGHT, TRUE);
332
333 GetWindowRect(getFrameHandle(), &r);
334 window_size = Rect(r.left, r.top, r.right, r.bottom);
335 GetClientRect(getFrameHandle(), &r);
336 client_size = Rect(r.left, r.top, r.right, r.bottom);
337
338 // Determine whether scrollbars are required
339 calculateScrollBars();
george82d070c692005-01-19 16:44:04 +0000340
341 // Resize the ToolBar
342 tb.autoSize();
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +0000343
344 // Redraw if required
345 if (!old_offset.equals(bufferToClient(Point(0, 0))))
346 InvalidateRect(getFrameHandle(), 0, TRUE);
347 }
348 break;
george828a471482005-02-06 07:15:53 +0000349
350 // Process messages from posTrackBar
351
352 case WM_HSCROLL:
353 {
354 long Pos = SendMessage(posTrackBar, TBM_GETPOS, 0, 0);
355 Pos *= sliderStepMs;
356
357 switch (LOWORD(wParam)) {
358 case TB_PAGEUP:
359 case TB_PAGEDOWN:
360 case TB_LINEUP:
361 case TB_LINEDOWN:
362 case TB_THUMBTRACK:
363 sliderDraging = true;
364 updatePos(Pos);
365 return 0;
366 case TB_ENDTRACK:
367 setPos(Pos);
368 updatePos(Pos);
369 sliderDraging = false;
370 return 0;
371 default:
372 break;
373 }
374 }
375 break;
george829e6e6cc2005-01-29 13:12:05 +0000376
377 case WM_NOTIFY:
378 switch (((NMHDR*)lParam)->code) {
379 case UDN_DELTAPOS:
380 if ((int)wParam == ID_SPEED_UPDOWN) {
george824ea27f62005-01-29 15:03:06 +0000381 BOOL lResult = FALSE;
george829e6e6cc2005-01-29 13:12:05 +0000382 char speedStr[20] = "\0";
383 DWORD speedRange = SendMessage(speedUpDown, UDM_GETRANGE, 0, 0);
384 LPNM_UPDOWN upDown = (LPNM_UPDOWN)lParam;
385 double speed;
386
george824ea27f62005-01-29 15:03:06 +0000387 // The out of range checking
george829e6e6cc2005-01-29 13:12:05 +0000388 if (upDown->iDelta > 0) {
389 speed = min(upDown->iPos + upDown->iDelta, LOWORD(speedRange)) * 0.5;
390 } else {
george824ea27f62005-01-29 15:03:06 +0000391 // It's need to round the UpDown position
392 if ((upDown->iPos * 0.5) != getSpeed()) {
393 upDown->iDelta = 0;
394 lResult = TRUE;
395 }
george829e6e6cc2005-01-29 13:12:05 +0000396 speed = max(upDown->iPos + upDown->iDelta, HIWORD(speedRange)) * 0.5;
397 }
398 _gcvt(speed, 5, speedStr);
399 sprintf(speedStr, "%.2f", speed);
400 SetWindowText(speedEdit, speedStr);
401 setSpeed(speed);
george824ea27f62005-01-29 15:03:06 +0000402 return lResult;
george829e6e6cc2005-01-29 13:12:05 +0000403 }
george824ea27f62005-01-29 15:03:06 +0000404 }
george829e6e6cc2005-01-29 13:12:05 +0000405 return 0;
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +0000406
407 case WM_CLOSE:
408 vlog.debug("WM_CLOSE %x", getMainHandle());
409 PostQuitMessage(0);
410 break;
411 }
412
413 return rfb::win32::SafeDefWindowProc(getMainHandle(), msg, wParam, lParam);
414}
415
416LRESULT RfbPlayer::processFrameMessage(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) {
417 switch (msg) {
418
419 case WM_PAINT:
420 {
421 if (is->isSeeking()) {
422 seekMode = true;
423 return 0;
424 } else {
425 if (seekMode) {
426 seekMode = false;
427 InvalidateRect(getFrameHandle(), 0, true);
428 UpdateWindow(getFrameHandle());
429 return 0;
430 }
431 }
432
433 PAINTSTRUCT ps;
434 HDC paintDC = BeginPaint(getFrameHandle(), &ps);
435 if (!paintDC)
436 throw SystemException("unable to BeginPaint", GetLastError());
437 Rect pr = Rect(ps.rcPaint.left, ps.rcPaint.top, ps.rcPaint.right, ps.rcPaint.bottom);
438
439 if (!pr.is_empty()) {
440
441 if (buffer->bitmap) {
442
443 // Get device context
444 BitmapDC bitmapDC(paintDC, buffer->bitmap);
445
446 // Blit the border if required
447 Rect bufpos = bufferToClient(buffer->getRect());
448 if (!pr.enclosed_by(bufpos)) {
449 vlog.debug("draw border");
450 HBRUSH black = (HBRUSH) GetStockObject(BLACK_BRUSH);
451 RECT r;
452 SetRect(&r, 0, 0, bufpos.tl.x, client_size.height()); FillRect(paintDC, &r, black);
453 SetRect(&r, bufpos.tl.x, 0, bufpos.br.x, bufpos.tl.y); FillRect(paintDC, &r, black);
454 SetRect(&r, bufpos.br.x, 0, client_size.width(), client_size.height()); FillRect(paintDC, &r, black);
455 SetRect(&r, bufpos.tl.x, bufpos.br.y, bufpos.br.x, client_size.height()); FillRect(paintDC, &r, black);
456 }
457
458 // Do the blit
459 Point buf_pos = clientToBuffer(pr.tl);
460 if (!BitBlt(paintDC, pr.tl.x, pr.tl.y, pr.width(), pr.height(),
461 bitmapDC, buf_pos.x, buf_pos.y, SRCCOPY))
462 throw SystemException("unable to BitBlt to window", GetLastError());
463
464 } else {
465 // Blit a load of black
466 if (!BitBlt(paintDC, pr.tl.x, pr.tl.y, pr.width(), pr.height(),
467 0, 0, 0, BLACKNESS))
468 throw SystemException("unable to BitBlt to blank window", GetLastError());
469 }
470 }
471 EndPaint(getFrameHandle(), &ps);
472 }
473 return 0;
474
475 case WM_VSCROLL:
476 case WM_HSCROLL:
477 {
478 Point delta;
479 int newpos = (msg == WM_VSCROLL) ? scrolloffset.y : scrolloffset.x;
480
481 switch (LOWORD(wParam)) {
482 case SB_PAGEUP: newpos -= 50; break;
483 case SB_PAGEDOWN: newpos += 50; break;
484 case SB_LINEUP: newpos -= 5; break;
485 case SB_LINEDOWN: newpos += 5; break;
486 case SB_THUMBTRACK:
487 case SB_THUMBPOSITION: newpos = HIWORD(wParam); break;
488 default: vlog.info("received unknown scroll message");
489 };
490
491 if (msg == WM_HSCROLL)
492 setViewportOffset(Point(newpos, scrolloffset.y));
493 else
494 setViewportOffset(Point(scrolloffset.x, newpos));
495
496 SCROLLINFO si;
497 si.cbSize = sizeof(si);
498 si.fMask = SIF_POS;
499 si.nPos = newpos;
500 SetScrollInfo(getFrameHandle(), (msg == WM_VSCROLL) ? SB_VERT : SB_HORZ, &si, TRUE);
501 }
502 break;
503 }
504
505 return DefWindowProc(hwnd, msg, wParam, lParam);
506}
507
508void RfbPlayer::setOptions(long _initTime = 0, double _playbackSpeed = 1.0,
509 bool _autoplay = false, bool _showControls = true) {
510 showControls = _showControls;
511 autoplay = _autoplay;
512 playbackSpeed = _playbackSpeed;
513 initTime = _initTime;
514}
515
516void RfbPlayer::applyOptions() {
517 if (initTime >= 0)
518 setPos(initTime);
519 setSpeed(playbackSpeed);
520 setPaused(!autoplay);
george82d070c692005-01-19 16:44:04 +0000521}
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +0000522
george82d070c692005-01-19 16:44:04 +0000523void RfbPlayer::createToolBar(HWND parentHwnd) {
524 RECT tRect;
525 InitCommonControls();
526
527 tb.create(ID_TOOLBAR, parentHwnd);
528 tb.addBitmap(4, IDB_TOOLBAR);
529
530 // Create the control buttons
531 tb.addButton(0, ID_PLAY);
532 tb.addButton(1, ID_PAUSE);
533 tb.addButton(2, ID_STOP);
534 tb.addButton(0, 0, TBSTATE_ENABLED, TBSTYLE_SEP);
535 tb.addButton(3, ID_FULLSCREEN);
536 tb.addButton(0, 0, TBSTATE_ENABLED, TBSTYLE_SEP);
537
538 // Create the static control for the time output
539 tb.addButton(125, 0, TBSTATE_ENABLED, TBSTYLE_SEP);
540 tb.getButtonRect(6, &tRect);
541 timeStatic = CreateWindowEx(0, "Static", "00m:00s (00m:00s)",
542 WS_CHILD | WS_VISIBLE, tRect.left, tRect.top+2, tRect.right-tRect.left,
543 tRect.bottom-tRect.top, tb.getHandle(), (HMENU)ID_TIME_STATIC,
544 GetModuleHandle(0), 0);
545 tb.addButton(0, 10, TBSTATE_ENABLED, TBSTYLE_SEP);
546
547 // Create the trackbar control for the time position
548 tb.addButton(200, 0, TBSTATE_ENABLED, TBSTYLE_SEP);
549 tb.getButtonRect(8, &tRect);
george82d4d69e62005-02-05 09:23:18 +0000550 posTrackBar = CreateWindowEx(0, TRACKBAR_CLASS, "Trackbar Control",
george82d070c692005-01-19 16:44:04 +0000551 WS_CHILD | WS_VISIBLE | TBS_AUTOTICKS | TBS_ENABLESELRANGE,
552 tRect.left, tRect.top, tRect.right-tRect.left, tRect.bottom-tRect.top,
553 parentHwnd, (HMENU)ID_POS_TRACKBAR, GetModuleHandle(0), 0);
554 // It's need to send notify messages to toolbar parent window
george82d4d69e62005-02-05 09:23:18 +0000555 SetParent(posTrackBar, tb.getHandle());
george82d070c692005-01-19 16:44:04 +0000556 tb.addButton(0, 10, TBSTATE_ENABLED, TBSTYLE_SEP);
557
558 // Create the label with "Speed:" caption
559 tb.addButton(50, 0, TBSTATE_ENABLED, TBSTYLE_SEP);
560 tb.getButtonRect(10, &tRect);
561 CreateWindowEx(0, "Static", "Speed:", WS_CHILD | WS_VISIBLE,
562 tRect.left, tRect.top+2, tRect.right-tRect.left, tRect.bottom-tRect.top,
563 tb.getHandle(), (HMENU)ID_SPEED_STATIC, GetModuleHandle(0), 0);
564
565 // Create the edit control and the spin for the speed managing
566 tb.addButton(60, 0, TBSTATE_ENABLED, TBSTYLE_SEP);
567 tb.getButtonRect(11, &tRect);
568 speedEdit = CreateWindowEx(WS_EX_CLIENTEDGE, "Edit", "1.00",
569 WS_CHILD | WS_VISIBLE | ES_RIGHT, tRect.left, tRect.top,
570 tRect.right-tRect.left, tRect.bottom-tRect.top, parentHwnd,
571 (HMENU)ID_SPEED_EDIT, GetModuleHandle(0), 0);
572 // It's need to send notify messages to toolbar parent window
573 SetParent(speedEdit, tb.getHandle());
574
575 speedUpDown = CreateUpDownControl(WS_CHILD | WS_VISIBLE
576 | WS_BORDER | UDS_ALIGNRIGHT, 0, 0, 0, 0, tb.getHandle(),
george829e6e6cc2005-01-29 13:12:05 +0000577 ID_SPEED_UPDOWN, GetModuleHandle(0), speedEdit, 20, 1, 2);
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +0000578}
579
580void RfbPlayer::setVisible(bool visible) {
581 ShowWindow(getMainHandle(), visible ? SW_SHOW : SW_HIDE);
582 if (visible) {
583 // When the window becomes visible, make it active
584 SetForegroundWindow(getMainHandle());
585 SetActiveWindow(getMainHandle());
586 }
587}
588
589void RfbPlayer::setTitle(const char *title) {
590 char _title[256];
591 strcpy(_title, AppName);
592 strcat(_title, " - ");
593 strcat(_title, title);
594 SetWindowText(getMainHandle(), _title);
595}
596
597void RfbPlayer::setFrameSize(int width, int height) {
598 // Calculate and set required size for main window
599 RECT r = {0, 0, width, height};
600 AdjustWindowRectEx(&r, GetWindowLong(getFrameHandle(), GWL_STYLE), FALSE,
601 GetWindowLong(getFrameHandle(), GWL_EXSTYLE));
602 r.bottom += CTRL_BAR_HEIGHT; // Include RfbPlayr's controls area
603 AdjustWindowRect(&r, GetWindowLong(getMainHandle(), GWL_STYLE), FALSE);
604 SetWindowPos(getMainHandle(), 0, 0, 0, r.right-r.left, r.bottom-r.top,
605 SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOOWNERZORDER);
606
607 // Enable/disable scrollbars as appropriate
608 calculateScrollBars();
609}
610
611void RfbPlayer::calculateScrollBars() {
612 // Calculate the required size of window
613 DWORD current_style = GetWindowLong(getFrameHandle(), GWL_STYLE);
614 DWORD style = current_style & ~(WS_VSCROLL | WS_HSCROLL);
615 DWORD old_style;
616 RECT r;
617 SetRect(&r, 0, 0, buffer->width(), buffer->height());
618 AdjustWindowRectEx(&r, style, FALSE, GetWindowLong(getFrameHandle(), GWL_EXSTYLE));
619 Rect reqd_size = Rect(r.left, r.top, r.right, r.bottom);
620
621 // Work out whether scroll bars are required
622 do {
623 old_style = style;
624
625 if (!(style & WS_HSCROLL) && (reqd_size.width() > window_size.width())) {
626 style |= WS_HSCROLL;
627 reqd_size.br.y += GetSystemMetrics(SM_CXHSCROLL);
628 }
629 if (!(style & WS_VSCROLL) && (reqd_size.height() > window_size.height())) {
630 style |= WS_VSCROLL;
631 reqd_size.br.x += GetSystemMetrics(SM_CXVSCROLL);
632 }
633 } while (style != old_style);
634
635 // Tell Windows to update the window style & cached settings
636 if (style != current_style) {
637 SetWindowLong(getFrameHandle(), GWL_STYLE, style);
638 SetWindowPos(getFrameHandle(), NULL, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED);
639 }
640
641 // Update the scroll settings
642 SCROLLINFO si;
643 if (style & WS_VSCROLL) {
644 si.cbSize = sizeof(si);
645 si.fMask = SIF_RANGE | SIF_PAGE | SIF_POS;
646 si.nMin = 0;
647 si.nMax = buffer->height();
648 si.nPage = buffer->height() - (reqd_size.height() - window_size.height());
649 maxscrolloffset.y = max(0, si.nMax-si.nPage);
650 scrolloffset.y = min(maxscrolloffset.y, scrolloffset.y);
651 si.nPos = scrolloffset.y;
652 SetScrollInfo(getFrameHandle(), SB_VERT, &si, TRUE);
653 }
654 if (style & WS_HSCROLL) {
655 si.cbSize = sizeof(si);
656 si.fMask = SIF_RANGE | SIF_PAGE | SIF_POS;
657 si.nMin = 0;
658 si.nMax = buffer->width();
659 si.nPage = buffer->width() - (reqd_size.width() - window_size.width());
660 maxscrolloffset.x = max(0, si.nMax-si.nPage);
661 scrolloffset.x = min(maxscrolloffset.x, scrolloffset.x);
662 si.nPos = scrolloffset.x;
663 SetScrollInfo(getFrameHandle(), SB_HORZ, &si, TRUE);
664 }
665}
666
667bool RfbPlayer::setViewportOffset(const Point& tl) {
668/* ***
669 Point np = Point(max(0, min(maxscrolloffset.x, tl.x)),
670 max(0, min(maxscrolloffset.y, tl.y)));
671 */
672 Point np = Point(max(0, min(tl.x, buffer->width()-client_size.width())),
673 max(0, min(tl.y, buffer->height()-client_size.height())));
674 Point delta = np.translate(scrolloffset.negate());
675 if (!np.equals(scrolloffset)) {
676 scrolloffset = np;
677 ScrollWindowEx(getFrameHandle(), -delta.x, -delta.y, 0, 0, 0, 0, SW_INVALIDATE);
678 UpdateWindow(getFrameHandle());
679 return true;
680 }
681 return false;
682}
683
684void RfbPlayer::close(const char* reason) {
685 setVisible(false);
686 if (reason) {
687 vlog.info("closing - %s", reason);
688 MessageBox(NULL, TStr(reason), "RfbPlayer", MB_ICONINFORMATION | MB_OK);
689 }
690 SendMessage(getFrameHandle(), WM_CLOSE, 0, 0);
691}
692
693void RfbPlayer::blankBuffer() {
694 fillRect(buffer->getRect(), 0);
695}
696
697void RfbPlayer::rewind() {
george8223e08562005-01-31 15:16:42 +0000698 bool paused = isPaused();
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +0000699 blankBuffer();
700 newSession(fileName);
701 skipHandshaking();
george8223e08562005-01-31 15:16:42 +0000702 setSpeed(playbackSpeed);
george828a471482005-02-06 07:15:53 +0000703 if (paused) is->pausePlayback();
704 else is->resumePlayback();
george8223e08562005-01-31 15:16:42 +0000705}
706
707void RfbPlayer::processMsg() {
708 static long update_time = GetTickCount();
709 try {
george828a471482005-02-06 07:15:53 +0000710 if ((!isSeeking()) && ((GetTickCount() - update_time) > 250)
711 && (!sliderDraging)) {
george8223e08562005-01-31 15:16:42 +0000712 // Update pos in the toolbar 4 times in 1 second
george828a471482005-02-06 07:15:53 +0000713 updatePos(getTimeOffset());
george8223e08562005-01-31 15:16:42 +0000714 update_time = GetTickCount();
715 }
716 RfbProto::processMsg();
717 } catch (rdr::Exception e) {
718 if (strcmp(e.str(), "[End Of File]") == 0) {
719 rewind();
720 setPaused(true);
george828a471482005-02-06 07:15:53 +0000721 updatePos(getTimeOffset());
george8223e08562005-01-31 15:16:42 +0000722 return;
723 }
724 // It's a special exception to perform backward seeking.
725 // We only rewind the stream and seek the offset
726 if (strcmp(e.str(), "[REWIND]") == 0) {
727 long initTime = getSeekOffset();
728 rewind();
729 setPos(initTime);
george828a471482005-02-06 07:15:53 +0000730 updatePos(getTimeOffset());
george8223e08562005-01-31 15:16:42 +0000731 } else {
732 MessageBox(getMainHandle(), e.str(), e.type(), MB_OK | MB_ICONERROR);
733 return;
734 }
735 }
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +0000736}
737
738void RfbPlayer::serverInit() {
739 RfbProto::serverInit();
740
741 // Save the server init time for using in setPos()
742 serverInitTime = getTimeOffset() / getSpeed();
743
744 // Resize the backing buffer
745 buffer->setSize(cp.width, cp.height);
746
747 // Check on the true colour mode
748 if (!(cp.pf()).trueColour)
Peter Ã…strandc81a6522004-12-30 11:32:08 +0000749 throw rdr::Exception("This version plays only true color session!");
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +0000750
751 // Set the session pixel format
752 buffer->setPF(cp.pf());
753
754 // If the window is not maximised then resize it
755 if (!(GetWindowLong(getMainHandle(), GWL_STYLE) & WS_MAXIMIZE))
756 setFrameSize(cp.width, cp.height);
757
758 // Set the window title and show it
759 setTitle(cp.name());
george82006f2792005-02-05 07:40:47 +0000760
george82d4d69e62005-02-05 09:23:18 +0000761 // Calculate the full session time and update posTrackBar control
george828a471482005-02-06 07:15:53 +0000762 sessionTimeMs = calculateSessionTime(fileName);
763 sprintf(fullSessionTime, "%.2um:%.2us",
764 sessionTimeMs / 1000 / 60, sessionTimeMs / 1000 % 60);
george82d4d69e62005-02-05 09:23:18 +0000765 SendMessage(posTrackBar, TBM_SETRANGE,
george828a471482005-02-06 07:15:53 +0000766 TRUE, MAKELONG(0, min(sessionTimeMs / 1000, MAX_POS_TRACKBAR_RANGE)));
767 sliderStepMs = sessionTimeMs / SendMessage(posTrackBar, TBM_GETRANGEMAX, 0, 0);
768
769 updatePos(getTimeOffset());
george82d4d69e62005-02-05 09:23:18 +0000770
george82006f2792005-02-05 07:40:47 +0000771 setPaused(!autoplay);
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +0000772}
773
774void RfbPlayer::setColourMapEntries(int first, int count, U16* rgbs) {
775 vlog.debug("setColourMapEntries: first=%d, count=%d", first, count);
776 throw rdr::Exception("Can't handle SetColourMapEntries message", "RfbPlayer");
777/* int i;
778 for (i=0;i<count;i++) {
779 buffer->setColour(i+first, rgbs[i*3], rgbs[i*3+1], rgbs[i*3+2]);
780 }
781 // *** change to 0, 256?
782 refreshWindowPalette(first, count);
783 palette_changed = true;
784 InvalidateRect(getFrameHandle(), 0, FALSE);*/
785}
786
787void RfbPlayer::bell() {
788 if (acceptBell)
789 MessageBeep(-1);
790}
791
792void RfbPlayer::serverCutText(const char* str, int len) {
793 if (cutText != NULL)
794 delete [] cutText;
795 cutText = new char[len + 1];
796 memcpy(cutText, str, len);
797 cutText[len] = '\0';
798}
799
800void RfbPlayer::frameBufferUpdateEnd() {
801};
802
803void RfbPlayer::beginRect(const Rect& r, unsigned int encoding) {
804}
805
806void RfbPlayer::endRect(const Rect& r, unsigned int encoding) {
807}
808
809
810void RfbPlayer::fillRect(const Rect& r, Pixel pix) {
811 buffer->fillRect(r, pix);
812 invalidateBufferRect(r);
813}
814
815void RfbPlayer::imageRect(const Rect& r, void* pixels) {
816 buffer->imageRect(r, pixels);
817 invalidateBufferRect(r);
818}
819
820void RfbPlayer::copyRect(const Rect& r, int srcX, int srcY) {
821 buffer->copyRect(r, Point(r.tl.x-srcX, r.tl.y-srcY));
822 invalidateBufferRect(r);
823}
824
825bool RfbPlayer::invalidateBufferRect(const Rect& crect) {
826 Rect rect = bufferToClient(crect);
827 if (rect.intersect(client_size).is_empty()) return false;
828 RECT invalid = {rect.tl.x, rect.tl.y, rect.br.x, rect.br.y};
829 InvalidateRect(getFrameHandle(), &invalid, FALSE);
830 return true;
831}
832
george8257f13522005-02-05 08:48:22 +0000833long RfbPlayer::calculateSessionTime(char *filename) {
834 FbsInputStream sessionFile(filename);
george828a471482005-02-06 07:15:53 +0000835 sessionFile.setTimeOffset(100000000);
george8257f13522005-02-05 08:48:22 +0000836 try {
837 while (TRUE) {
838 sessionFile.skip(1024);
839 }
840 } catch (rdr::Exception e) {
841 if (strcmp(e.str(), "[End Of File]") == 0) {
george828a471482005-02-06 07:15:53 +0000842 return sessionFile.getTimeOffset();
george8257f13522005-02-05 08:48:22 +0000843 } else {
844 MessageBox(getMainHandle(), e.str(), e.type(), MB_OK | MB_ICONERROR);
845 return 0;
846 }
847 }
848 return 0;
849}
850
george8217e92cb2005-01-31 16:01:02 +0000851void RfbPlayer::openSessionFile(char *_fileName) {
852 fileName = strDup(_fileName);
853
854 // Close the previous reading thread
855 if (rfbReader) {
george8217e92cb2005-01-31 16:01:02 +0000856 delete rfbReader->join();
857 }
858 blankBuffer();
859 newSession(fileName);
860 setSpeed(playbackSpeed);
861 rfbReader = new rfbSessionReader(this);
862 rfbReader->start();
863}
864
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +0000865void RfbPlayer::setPaused(bool paused) {
866 if (paused) {
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +0000867 is->pausePlayback();
george82006f2792005-02-05 07:40:47 +0000868 tb.checkButton(ID_PAUSE, true);
869 tb.checkButton(ID_PLAY, false);
870 tb.checkButton(ID_STOP, false);
871 CheckMenuItem(hMenu, ID_PLAYPAUSE, MF_CHECKED);
872 CheckMenuItem(hMenu, ID_STOP, MF_UNCHECKED);
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +0000873 } else {
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +0000874 is->resumePlayback();
george82006f2792005-02-05 07:40:47 +0000875 tb.checkButton(ID_PLAY, true);
876 tb.checkButton(ID_STOP, false);
877 tb.checkButton(ID_PAUSE, false);
878 CheckMenuItem(hMenu, ID_PLAYPAUSE, MF_CHECKED);
879 CheckMenuItem(hMenu, ID_STOP, MF_UNCHECKED);
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +0000880 }
881}
882
george82006f2792005-02-05 07:40:47 +0000883void RfbPlayer::stopPlayback() {
884 setPos(0);
885 is->pausePlayback();
886 tb.checkButton(ID_STOP, true);
887 tb.checkButton(ID_PLAY, false);
888 tb.checkButton(ID_PAUSE, false);
889 CheckMenuItem(hMenu, ID_STOP, MF_CHECKED);
890 CheckMenuItem(hMenu, ID_PLAYPAUSE, MF_UNCHECKED);
891}
892
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +0000893void RfbPlayer::setSpeed(double speed) {
894 serverInitTime = serverInitTime * getSpeed() / speed;
895 is->setSpeed(speed);
george8223e08562005-01-31 15:16:42 +0000896 playbackSpeed = speed;
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +0000897}
898
899double RfbPlayer::getSpeed() {
900 return is->getSpeed();
901}
902
903void RfbPlayer::setPos(long pos) {
904 is->setTimeOffset(max(pos, serverInitTime));
905}
906
907long RfbPlayer::getSeekOffset() {
908 return is->getSeekOffset();
909}
910
911bool RfbPlayer::isSeeking() {
912 return is->isSeeking();
913}
914
915bool RfbPlayer::isSeekMode() {
916 return seekMode;
917}
918
919bool RfbPlayer::isPaused() {
920 return is->isPaused();
921}
922
923long RfbPlayer::getTimeOffset() {
george828a471482005-02-06 07:15:53 +0000924 return max(is->getTimeOffset(), is->getSeekOffset());
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +0000925}
926
george828a471482005-02-06 07:15:53 +0000927void RfbPlayer::updatePos(long newPos) {
928 // Update time pos in static control
george823c8fbbf2005-01-24 11:09:08 +0000929 char timePos[30] = "\0";
george828a471482005-02-06 07:15:53 +0000930 double sliderPos = newPos;
931 newPos /= 1000;
george8244325492005-02-06 07:29:51 +0000932 sprintf(timePos, "%.2um:%.2us (%s)", newPos/60, newPos%60, fullSessionTime);
george823c8fbbf2005-01-24 11:09:08 +0000933 SetWindowText(timeStatic, timePos);
george828a471482005-02-06 07:15:53 +0000934
935 // Update the position of slider
936 if (!sliderDraging) {
937 sliderPos /= sliderStepMs;
938 SendMessage(posTrackBar, TBM_SETPOS, TRUE, sliderPos);
939 }
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +0000940}
941
942void RfbPlayer::skipHandshaking() {
943 int skipBytes = 12 + 4 + 24 + strlen(cp.name());
944 is->skip(skipBytes);
945 state_ = RFBSTATE_NORMAL;
946}
947
948void programInfo() {
949 win32::FileVersionInfo inf;
950 _tprintf(_T("%s - %s, Version %s\n"),
951 inf.getVerString(_T("ProductName")),
952 inf.getVerString(_T("FileDescription")),
953 inf.getVerString(_T("FileVersion")));
954 printf("%s\n", buildTime);
955 _tprintf(_T("%s\n\n"), inf.getVerString(_T("LegalCopyright")));
956}
957
958void programUsage() {
959 printf("usage: rfbplayer <options> <filename>\n");
960 printf("Command-line options:\n");
961 printf(" -help - Provide usage information.\n");
962 printf(" -speed <value> - Sets playback speed, where 1 is normal speed,\n");
963 printf(" 2 is double speed, 0.5 is half speed. Default: 1.0.\n");
964 printf(" -pos <ms> - Sets initial time position in the session file,\n");
965 printf(" in milliseconds. Default: 0.\n");
966 printf(" -autoplay <yes|no> - Runs the player in the playback mode. Default: \"no\".\n");
967 printf(" -controls <yes|no> - Shows the control panel at the top. Default: \"yes\".\n");
968 printf(" -bell <yes|no> - Accepts the bell. Default: \"no\".\n");
969}
970
971double playbackSpeed = 1.0;
972long initTime = -1;
973bool autoplay = false;
974bool showControls = true;
975char *fileName;
976bool console = false;
977bool wrong_param = false;
978bool print_usage = false;
979bool acceptBell = false;
980
981bool processParams(int argc, char* argv[]) {
982 for (int i = 1; i < argc; i++) {
983 if ((strcasecmp(argv[i], "-help") == 0) ||
984 (strcasecmp(argv[i], "--help") == 0) ||
985 (strcasecmp(argv[i], "/help") == 0) ||
986 (strcasecmp(argv[i], "-h") == 0) ||
987 (strcasecmp(argv[i], "/h") == 0) ||
988 (strcasecmp(argv[i], "/?") == 0)) {
989 print_usage = true;
990 return true;
991 }
992
993 if ((strcasecmp(argv[i], "-speed") == 0) ||
994 (strcasecmp(argv[i], "/speed") == 0) && (i < argc-1)) {
995 playbackSpeed = atof(argv[++i]);
996 if (playbackSpeed <= 0) {
997 return false;
998 }
999 continue;
1000 }
1001
1002 if ((strcasecmp(argv[i], "-pos") == 0) ||
1003 (strcasecmp(argv[i], "/pos") == 0) && (i < argc-1)) {
1004 initTime = atol(argv[++i]);
1005 if (initTime <= 0)
1006 return false;
1007 continue;
1008 }
1009
1010 if ((strcasecmp(argv[i], "-autoplay") == 0) ||
1011 (strcasecmp(argv[i], "/autoplay") == 0) && (i < argc-1)) {
1012 i++;
1013 if (strcasecmp(argv[i], "yes") == 0) {
1014 autoplay = true;
1015 continue;
1016 }
1017 if (strcasecmp(argv[i], "no") == 0) {
1018 autoplay = false;
1019 continue;
1020 }
1021 return false;
1022 }
1023
1024 if ((strcasecmp(argv[i], "-controls") == 0) ||
1025 (strcasecmp(argv[i], "/controls") == 0) && (i < argc-1)) {
1026 i++;
1027 if (strcasecmp(argv[i], "yes") == 0) {
1028 showControls = true;
1029 continue;
1030 }
1031 if (strcasecmp(argv[i], "no") == 0) {
1032 showControls = false;
1033 continue;
1034 }
1035 return false;
1036 }
1037
1038 if ((strcasecmp(argv[i], "-bell") == 0) ||
1039 (strcasecmp(argv[i], "/bell") == 0) && (i < argc-1)) {
1040 i++;
1041 if (strcasecmp(argv[i], "yes") == 0) {
1042 acceptBell = true;
1043 continue;
1044 }
1045 if (strcasecmp(argv[i], "no") == 0) {
1046 acceptBell = false;
1047 continue;
1048 }
1049 return false;
1050 }
1051
1052 if (i != argc - 1)
1053 return false;
1054 }
1055
1056 fileName = strDup(argv[argc-1]);
1057 return true;
1058}
1059
1060//
1061// -=- WinMain
1062//
1063
1064int WINAPI WinMain(HINSTANCE inst, HINSTANCE prevInst, char* cmdLine, int cmdShow) {
1065
1066 // - Process the command-line
1067
1068 int argc = __argc;
1069 char** argv = __argv;
1070 if (argc > 1) {
1071 wrong_param = !processParams(argc, argv);
1072 console = print_usage | wrong_param;
1073 } else {
1074 console = true;
1075 }
1076
1077 if (console) {
1078 AllocConsole();
1079 freopen("CONOUT$","wb",stdout);
1080
1081 programInfo();
1082 if (wrong_param)
1083 printf("Wrong a command line.\n");
1084 else
1085 programUsage();
1086
1087 printf("\nPress Enter/Return key to continue\n");
1088 char c = getch();
1089 FreeConsole();
1090
1091 return 0;
george8267cbcd02005-01-16 15:39:56 +00001092 }
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +00001093
1094 // Create the player and the thread which reading the rfb data
1095 RfbPlayer *player = NULL;
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +00001096 try {
1097 player = new RfbPlayer(fileName, initTime, playbackSpeed, autoplay,
1098 showControls, acceptBell);
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +00001099 } catch (rdr::Exception e) {
1100 MessageBox(NULL, e.str(), e.type(), MB_OK | MB_ICONERROR);
1101 delete player;
1102 return 0;
1103 }
1104
1105 // Run the player
george825bbd61b2004-12-09 17:47:37 +00001106 HACCEL hAccel = LoadAccelerators(inst, MAKEINTRESOURCE(IDR_ACCELERATOR));
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +00001107 MSG msg;
1108 while (GetMessage(&msg, NULL, 0, 0) > 0) {
george825bbd61b2004-12-09 17:47:37 +00001109 if(!TranslateAccelerator(player->getMainHandle(), hAccel, &msg)) {
1110 TranslateMessage(&msg);
1111 DispatchMessage(&msg);
1112 }
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +00001113 }
1114
1115 // Wait while the thread destroying and then destroy the player
1116 try{
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +00001117 if (player) delete player;
1118 } catch (rdr::Exception e) {
1119 MessageBox(NULL, e.str(), e.type(), MB_OK | MB_ICONERROR);
1120 }
1121
1122 return 0;
1123};