blob: 134bdeec212b5622994af73f818580a7b3ac07e6 [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);
george828a471482005-02-06 07:15:53 +0000368 sliderDraging = false;
369 return 0;
370 default:
371 break;
372 }
373 }
374 break;
george829e6e6cc2005-01-29 13:12:05 +0000375
376 case WM_NOTIFY:
377 switch (((NMHDR*)lParam)->code) {
378 case UDN_DELTAPOS:
379 if ((int)wParam == ID_SPEED_UPDOWN) {
george824ea27f62005-01-29 15:03:06 +0000380 BOOL lResult = FALSE;
george829e6e6cc2005-01-29 13:12:05 +0000381 char speedStr[20] = "\0";
382 DWORD speedRange = SendMessage(speedUpDown, UDM_GETRANGE, 0, 0);
383 LPNM_UPDOWN upDown = (LPNM_UPDOWN)lParam;
384 double speed;
385
george824ea27f62005-01-29 15:03:06 +0000386 // The out of range checking
george829e6e6cc2005-01-29 13:12:05 +0000387 if (upDown->iDelta > 0) {
388 speed = min(upDown->iPos + upDown->iDelta, LOWORD(speedRange)) * 0.5;
389 } else {
george824ea27f62005-01-29 15:03:06 +0000390 // It's need to round the UpDown position
391 if ((upDown->iPos * 0.5) != getSpeed()) {
392 upDown->iDelta = 0;
393 lResult = TRUE;
394 }
george829e6e6cc2005-01-29 13:12:05 +0000395 speed = max(upDown->iPos + upDown->iDelta, HIWORD(speedRange)) * 0.5;
396 }
397 _gcvt(speed, 5, speedStr);
398 sprintf(speedStr, "%.2f", speed);
399 SetWindowText(speedEdit, speedStr);
400 setSpeed(speed);
george824ea27f62005-01-29 15:03:06 +0000401 return lResult;
george829e6e6cc2005-01-29 13:12:05 +0000402 }
george824ea27f62005-01-29 15:03:06 +0000403 }
george829e6e6cc2005-01-29 13:12:05 +0000404 return 0;
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +0000405
406 case WM_CLOSE:
407 vlog.debug("WM_CLOSE %x", getMainHandle());
408 PostQuitMessage(0);
409 break;
410 }
411
412 return rfb::win32::SafeDefWindowProc(getMainHandle(), msg, wParam, lParam);
413}
414
415LRESULT RfbPlayer::processFrameMessage(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) {
416 switch (msg) {
417
418 case WM_PAINT:
419 {
420 if (is->isSeeking()) {
421 seekMode = true;
422 return 0;
423 } else {
424 if (seekMode) {
425 seekMode = false;
426 InvalidateRect(getFrameHandle(), 0, true);
427 UpdateWindow(getFrameHandle());
428 return 0;
429 }
430 }
431
432 PAINTSTRUCT ps;
433 HDC paintDC = BeginPaint(getFrameHandle(), &ps);
434 if (!paintDC)
435 throw SystemException("unable to BeginPaint", GetLastError());
436 Rect pr = Rect(ps.rcPaint.left, ps.rcPaint.top, ps.rcPaint.right, ps.rcPaint.bottom);
437
438 if (!pr.is_empty()) {
439
440 if (buffer->bitmap) {
441
442 // Get device context
443 BitmapDC bitmapDC(paintDC, buffer->bitmap);
444
445 // Blit the border if required
446 Rect bufpos = bufferToClient(buffer->getRect());
447 if (!pr.enclosed_by(bufpos)) {
448 vlog.debug("draw border");
449 HBRUSH black = (HBRUSH) GetStockObject(BLACK_BRUSH);
450 RECT r;
451 SetRect(&r, 0, 0, bufpos.tl.x, client_size.height()); FillRect(paintDC, &r, black);
452 SetRect(&r, bufpos.tl.x, 0, bufpos.br.x, bufpos.tl.y); FillRect(paintDC, &r, black);
453 SetRect(&r, bufpos.br.x, 0, client_size.width(), client_size.height()); FillRect(paintDC, &r, black);
454 SetRect(&r, bufpos.tl.x, bufpos.br.y, bufpos.br.x, client_size.height()); FillRect(paintDC, &r, black);
455 }
456
457 // Do the blit
458 Point buf_pos = clientToBuffer(pr.tl);
459 if (!BitBlt(paintDC, pr.tl.x, pr.tl.y, pr.width(), pr.height(),
460 bitmapDC, buf_pos.x, buf_pos.y, SRCCOPY))
461 throw SystemException("unable to BitBlt to window", GetLastError());
462
463 } else {
464 // Blit a load of black
465 if (!BitBlt(paintDC, pr.tl.x, pr.tl.y, pr.width(), pr.height(),
466 0, 0, 0, BLACKNESS))
467 throw SystemException("unable to BitBlt to blank window", GetLastError());
468 }
469 }
470 EndPaint(getFrameHandle(), &ps);
471 }
472 return 0;
473
474 case WM_VSCROLL:
475 case WM_HSCROLL:
476 {
477 Point delta;
478 int newpos = (msg == WM_VSCROLL) ? scrolloffset.y : scrolloffset.x;
479
480 switch (LOWORD(wParam)) {
481 case SB_PAGEUP: newpos -= 50; break;
482 case SB_PAGEDOWN: newpos += 50; break;
483 case SB_LINEUP: newpos -= 5; break;
484 case SB_LINEDOWN: newpos += 5; break;
485 case SB_THUMBTRACK:
486 case SB_THUMBPOSITION: newpos = HIWORD(wParam); break;
487 default: vlog.info("received unknown scroll message");
488 };
489
490 if (msg == WM_HSCROLL)
491 setViewportOffset(Point(newpos, scrolloffset.y));
492 else
493 setViewportOffset(Point(scrolloffset.x, newpos));
494
495 SCROLLINFO si;
496 si.cbSize = sizeof(si);
497 si.fMask = SIF_POS;
498 si.nPos = newpos;
499 SetScrollInfo(getFrameHandle(), (msg == WM_VSCROLL) ? SB_VERT : SB_HORZ, &si, TRUE);
500 }
501 break;
502 }
503
504 return DefWindowProc(hwnd, msg, wParam, lParam);
505}
506
507void RfbPlayer::setOptions(long _initTime = 0, double _playbackSpeed = 1.0,
508 bool _autoplay = false, bool _showControls = true) {
509 showControls = _showControls;
510 autoplay = _autoplay;
511 playbackSpeed = _playbackSpeed;
512 initTime = _initTime;
513}
514
515void RfbPlayer::applyOptions() {
516 if (initTime >= 0)
517 setPos(initTime);
518 setSpeed(playbackSpeed);
519 setPaused(!autoplay);
george82d070c692005-01-19 16:44:04 +0000520}
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +0000521
george82d070c692005-01-19 16:44:04 +0000522void RfbPlayer::createToolBar(HWND parentHwnd) {
523 RECT tRect;
524 InitCommonControls();
525
526 tb.create(ID_TOOLBAR, parentHwnd);
527 tb.addBitmap(4, IDB_TOOLBAR);
528
529 // Create the control buttons
530 tb.addButton(0, ID_PLAY);
531 tb.addButton(1, ID_PAUSE);
532 tb.addButton(2, ID_STOP);
533 tb.addButton(0, 0, TBSTATE_ENABLED, TBSTYLE_SEP);
534 tb.addButton(3, ID_FULLSCREEN);
535 tb.addButton(0, 0, TBSTATE_ENABLED, TBSTYLE_SEP);
536
537 // Create the static control for the time output
538 tb.addButton(125, 0, TBSTATE_ENABLED, TBSTYLE_SEP);
539 tb.getButtonRect(6, &tRect);
540 timeStatic = CreateWindowEx(0, "Static", "00m:00s (00m:00s)",
541 WS_CHILD | WS_VISIBLE, tRect.left, tRect.top+2, tRect.right-tRect.left,
542 tRect.bottom-tRect.top, tb.getHandle(), (HMENU)ID_TIME_STATIC,
543 GetModuleHandle(0), 0);
544 tb.addButton(0, 10, TBSTATE_ENABLED, TBSTYLE_SEP);
545
546 // Create the trackbar control for the time position
547 tb.addButton(200, 0, TBSTATE_ENABLED, TBSTYLE_SEP);
548 tb.getButtonRect(8, &tRect);
george82d4d69e62005-02-05 09:23:18 +0000549 posTrackBar = CreateWindowEx(0, TRACKBAR_CLASS, "Trackbar Control",
george82d070c692005-01-19 16:44:04 +0000550 WS_CHILD | WS_VISIBLE | TBS_AUTOTICKS | TBS_ENABLESELRANGE,
551 tRect.left, tRect.top, tRect.right-tRect.left, tRect.bottom-tRect.top,
552 parentHwnd, (HMENU)ID_POS_TRACKBAR, GetModuleHandle(0), 0);
553 // It's need to send notify messages to toolbar parent window
george82d4d69e62005-02-05 09:23:18 +0000554 SetParent(posTrackBar, tb.getHandle());
george82d070c692005-01-19 16:44:04 +0000555 tb.addButton(0, 10, TBSTATE_ENABLED, TBSTYLE_SEP);
556
557 // Create the label with "Speed:" caption
558 tb.addButton(50, 0, TBSTATE_ENABLED, TBSTYLE_SEP);
559 tb.getButtonRect(10, &tRect);
560 CreateWindowEx(0, "Static", "Speed:", WS_CHILD | WS_VISIBLE,
561 tRect.left, tRect.top+2, tRect.right-tRect.left, tRect.bottom-tRect.top,
562 tb.getHandle(), (HMENU)ID_SPEED_STATIC, GetModuleHandle(0), 0);
563
564 // Create the edit control and the spin for the speed managing
565 tb.addButton(60, 0, TBSTATE_ENABLED, TBSTYLE_SEP);
566 tb.getButtonRect(11, &tRect);
567 speedEdit = CreateWindowEx(WS_EX_CLIENTEDGE, "Edit", "1.00",
568 WS_CHILD | WS_VISIBLE | ES_RIGHT, tRect.left, tRect.top,
569 tRect.right-tRect.left, tRect.bottom-tRect.top, parentHwnd,
570 (HMENU)ID_SPEED_EDIT, GetModuleHandle(0), 0);
571 // It's need to send notify messages to toolbar parent window
572 SetParent(speedEdit, tb.getHandle());
573
574 speedUpDown = CreateUpDownControl(WS_CHILD | WS_VISIBLE
575 | WS_BORDER | UDS_ALIGNRIGHT, 0, 0, 0, 0, tb.getHandle(),
george829e6e6cc2005-01-29 13:12:05 +0000576 ID_SPEED_UPDOWN, GetModuleHandle(0), speedEdit, 20, 1, 2);
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +0000577}
578
579void RfbPlayer::setVisible(bool visible) {
580 ShowWindow(getMainHandle(), visible ? SW_SHOW : SW_HIDE);
581 if (visible) {
582 // When the window becomes visible, make it active
583 SetForegroundWindow(getMainHandle());
584 SetActiveWindow(getMainHandle());
585 }
586}
587
588void RfbPlayer::setTitle(const char *title) {
589 char _title[256];
590 strcpy(_title, AppName);
591 strcat(_title, " - ");
592 strcat(_title, title);
593 SetWindowText(getMainHandle(), _title);
594}
595
596void RfbPlayer::setFrameSize(int width, int height) {
597 // Calculate and set required size for main window
598 RECT r = {0, 0, width, height};
599 AdjustWindowRectEx(&r, GetWindowLong(getFrameHandle(), GWL_STYLE), FALSE,
600 GetWindowLong(getFrameHandle(), GWL_EXSTYLE));
601 r.bottom += CTRL_BAR_HEIGHT; // Include RfbPlayr's controls area
602 AdjustWindowRect(&r, GetWindowLong(getMainHandle(), GWL_STYLE), FALSE);
603 SetWindowPos(getMainHandle(), 0, 0, 0, r.right-r.left, r.bottom-r.top,
604 SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOOWNERZORDER);
605
606 // Enable/disable scrollbars as appropriate
607 calculateScrollBars();
608}
609
610void RfbPlayer::calculateScrollBars() {
611 // Calculate the required size of window
612 DWORD current_style = GetWindowLong(getFrameHandle(), GWL_STYLE);
613 DWORD style = current_style & ~(WS_VSCROLL | WS_HSCROLL);
614 DWORD old_style;
615 RECT r;
616 SetRect(&r, 0, 0, buffer->width(), buffer->height());
617 AdjustWindowRectEx(&r, style, FALSE, GetWindowLong(getFrameHandle(), GWL_EXSTYLE));
618 Rect reqd_size = Rect(r.left, r.top, r.right, r.bottom);
619
620 // Work out whether scroll bars are required
621 do {
622 old_style = style;
623
624 if (!(style & WS_HSCROLL) && (reqd_size.width() > window_size.width())) {
625 style |= WS_HSCROLL;
626 reqd_size.br.y += GetSystemMetrics(SM_CXHSCROLL);
627 }
628 if (!(style & WS_VSCROLL) && (reqd_size.height() > window_size.height())) {
629 style |= WS_VSCROLL;
630 reqd_size.br.x += GetSystemMetrics(SM_CXVSCROLL);
631 }
632 } while (style != old_style);
633
634 // Tell Windows to update the window style & cached settings
635 if (style != current_style) {
636 SetWindowLong(getFrameHandle(), GWL_STYLE, style);
637 SetWindowPos(getFrameHandle(), NULL, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED);
638 }
639
640 // Update the scroll settings
641 SCROLLINFO si;
642 if (style & WS_VSCROLL) {
643 si.cbSize = sizeof(si);
644 si.fMask = SIF_RANGE | SIF_PAGE | SIF_POS;
645 si.nMin = 0;
646 si.nMax = buffer->height();
647 si.nPage = buffer->height() - (reqd_size.height() - window_size.height());
648 maxscrolloffset.y = max(0, si.nMax-si.nPage);
649 scrolloffset.y = min(maxscrolloffset.y, scrolloffset.y);
650 si.nPos = scrolloffset.y;
651 SetScrollInfo(getFrameHandle(), SB_VERT, &si, TRUE);
652 }
653 if (style & WS_HSCROLL) {
654 si.cbSize = sizeof(si);
655 si.fMask = SIF_RANGE | SIF_PAGE | SIF_POS;
656 si.nMin = 0;
657 si.nMax = buffer->width();
658 si.nPage = buffer->width() - (reqd_size.width() - window_size.width());
659 maxscrolloffset.x = max(0, si.nMax-si.nPage);
660 scrolloffset.x = min(maxscrolloffset.x, scrolloffset.x);
661 si.nPos = scrolloffset.x;
662 SetScrollInfo(getFrameHandle(), SB_HORZ, &si, TRUE);
663 }
664}
665
666bool RfbPlayer::setViewportOffset(const Point& tl) {
667/* ***
668 Point np = Point(max(0, min(maxscrolloffset.x, tl.x)),
669 max(0, min(maxscrolloffset.y, tl.y)));
670 */
671 Point np = Point(max(0, min(tl.x, buffer->width()-client_size.width())),
672 max(0, min(tl.y, buffer->height()-client_size.height())));
673 Point delta = np.translate(scrolloffset.negate());
674 if (!np.equals(scrolloffset)) {
675 scrolloffset = np;
676 ScrollWindowEx(getFrameHandle(), -delta.x, -delta.y, 0, 0, 0, 0, SW_INVALIDATE);
677 UpdateWindow(getFrameHandle());
678 return true;
679 }
680 return false;
681}
682
683void RfbPlayer::close(const char* reason) {
684 setVisible(false);
685 if (reason) {
686 vlog.info("closing - %s", reason);
687 MessageBox(NULL, TStr(reason), "RfbPlayer", MB_ICONINFORMATION | MB_OK);
688 }
689 SendMessage(getFrameHandle(), WM_CLOSE, 0, 0);
690}
691
692void RfbPlayer::blankBuffer() {
693 fillRect(buffer->getRect(), 0);
694}
695
696void RfbPlayer::rewind() {
george8223e08562005-01-31 15:16:42 +0000697 bool paused = isPaused();
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +0000698 blankBuffer();
699 newSession(fileName);
700 skipHandshaking();
george8223e08562005-01-31 15:16:42 +0000701 setSpeed(playbackSpeed);
george828a471482005-02-06 07:15:53 +0000702 if (paused) is->pausePlayback();
703 else is->resumePlayback();
george8223e08562005-01-31 15:16:42 +0000704}
705
706void RfbPlayer::processMsg() {
707 static long update_time = GetTickCount();
708 try {
george828a471482005-02-06 07:15:53 +0000709 if ((!isSeeking()) && ((GetTickCount() - update_time) > 250)
710 && (!sliderDraging)) {
george8223e08562005-01-31 15:16:42 +0000711 // Update pos in the toolbar 4 times in 1 second
george828a471482005-02-06 07:15:53 +0000712 updatePos(getTimeOffset());
george8223e08562005-01-31 15:16:42 +0000713 update_time = GetTickCount();
714 }
715 RfbProto::processMsg();
716 } catch (rdr::Exception e) {
717 if (strcmp(e.str(), "[End Of File]") == 0) {
718 rewind();
719 setPaused(true);
george828a471482005-02-06 07:15:53 +0000720 updatePos(getTimeOffset());
george829403bee2005-02-06 11:14:39 +0000721 SendMessage(posTrackBar, TBM_SETPOS, TRUE, 0);
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);
george828a471482005-02-06 07:15:53 +0000768 updatePos(getTimeOffset());
george82d4d69e62005-02-05 09:23:18 +0000769
george82006f2792005-02-05 07:40:47 +0000770 setPaused(!autoplay);
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +0000771}
772
773void RfbPlayer::setColourMapEntries(int first, int count, U16* rgbs) {
774 vlog.debug("setColourMapEntries: first=%d, count=%d", first, count);
775 throw rdr::Exception("Can't handle SetColourMapEntries message", "RfbPlayer");
776/* int i;
777 for (i=0;i<count;i++) {
778 buffer->setColour(i+first, rgbs[i*3], rgbs[i*3+1], rgbs[i*3+2]);
779 }
780 // *** change to 0, 256?
781 refreshWindowPalette(first, count);
782 palette_changed = true;
783 InvalidateRect(getFrameHandle(), 0, FALSE);*/
784}
785
786void RfbPlayer::bell() {
787 if (acceptBell)
788 MessageBeep(-1);
789}
790
791void RfbPlayer::serverCutText(const char* str, int len) {
792 if (cutText != NULL)
793 delete [] cutText;
794 cutText = new char[len + 1];
795 memcpy(cutText, str, len);
796 cutText[len] = '\0';
797}
798
799void RfbPlayer::frameBufferUpdateEnd() {
800};
801
802void RfbPlayer::beginRect(const Rect& r, unsigned int encoding) {
803}
804
805void RfbPlayer::endRect(const Rect& r, unsigned int encoding) {
806}
807
808
809void RfbPlayer::fillRect(const Rect& r, Pixel pix) {
810 buffer->fillRect(r, pix);
811 invalidateBufferRect(r);
812}
813
814void RfbPlayer::imageRect(const Rect& r, void* pixels) {
815 buffer->imageRect(r, pixels);
816 invalidateBufferRect(r);
817}
818
819void RfbPlayer::copyRect(const Rect& r, int srcX, int srcY) {
820 buffer->copyRect(r, Point(r.tl.x-srcX, r.tl.y-srcY));
821 invalidateBufferRect(r);
822}
823
824bool RfbPlayer::invalidateBufferRect(const Rect& crect) {
825 Rect rect = bufferToClient(crect);
826 if (rect.intersect(client_size).is_empty()) return false;
827 RECT invalid = {rect.tl.x, rect.tl.y, rect.br.x, rect.br.y};
828 InvalidateRect(getFrameHandle(), &invalid, FALSE);
829 return true;
830}
831
george8257f13522005-02-05 08:48:22 +0000832long RfbPlayer::calculateSessionTime(char *filename) {
833 FbsInputStream sessionFile(filename);
george828a471482005-02-06 07:15:53 +0000834 sessionFile.setTimeOffset(100000000);
george8257f13522005-02-05 08:48:22 +0000835 try {
836 while (TRUE) {
837 sessionFile.skip(1024);
838 }
839 } catch (rdr::Exception e) {
840 if (strcmp(e.str(), "[End Of File]") == 0) {
george828a471482005-02-06 07:15:53 +0000841 return sessionFile.getTimeOffset();
george8257f13522005-02-05 08:48:22 +0000842 } else {
843 MessageBox(getMainHandle(), e.str(), e.type(), MB_OK | MB_ICONERROR);
844 return 0;
845 }
846 }
847 return 0;
848}
849
george8217e92cb2005-01-31 16:01:02 +0000850void RfbPlayer::openSessionFile(char *_fileName) {
851 fileName = strDup(_fileName);
852
853 // Close the previous reading thread
854 if (rfbReader) {
george8217e92cb2005-01-31 16:01:02 +0000855 delete rfbReader->join();
856 }
857 blankBuffer();
858 newSession(fileName);
859 setSpeed(playbackSpeed);
860 rfbReader = new rfbSessionReader(this);
861 rfbReader->start();
862}
863
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +0000864void RfbPlayer::setPaused(bool paused) {
865 if (paused) {
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +0000866 is->pausePlayback();
george82006f2792005-02-05 07:40:47 +0000867 tb.checkButton(ID_PAUSE, true);
868 tb.checkButton(ID_PLAY, false);
869 tb.checkButton(ID_STOP, false);
870 CheckMenuItem(hMenu, ID_PLAYPAUSE, MF_CHECKED);
871 CheckMenuItem(hMenu, ID_STOP, MF_UNCHECKED);
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +0000872 } else {
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +0000873 is->resumePlayback();
george82006f2792005-02-05 07:40:47 +0000874 tb.checkButton(ID_PLAY, true);
875 tb.checkButton(ID_STOP, false);
876 tb.checkButton(ID_PAUSE, false);
877 CheckMenuItem(hMenu, ID_PLAYPAUSE, MF_CHECKED);
878 CheckMenuItem(hMenu, ID_STOP, MF_UNCHECKED);
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +0000879 }
880}
881
george82006f2792005-02-05 07:40:47 +0000882void RfbPlayer::stopPlayback() {
883 setPos(0);
884 is->pausePlayback();
885 tb.checkButton(ID_STOP, true);
886 tb.checkButton(ID_PLAY, false);
887 tb.checkButton(ID_PAUSE, false);
888 CheckMenuItem(hMenu, ID_STOP, MF_CHECKED);
889 CheckMenuItem(hMenu, ID_PLAYPAUSE, MF_UNCHECKED);
890}
891
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +0000892void RfbPlayer::setSpeed(double speed) {
893 serverInitTime = serverInitTime * getSpeed() / speed;
894 is->setSpeed(speed);
george8223e08562005-01-31 15:16:42 +0000895 playbackSpeed = speed;
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +0000896}
897
898double RfbPlayer::getSpeed() {
899 return is->getSpeed();
900}
901
902void RfbPlayer::setPos(long pos) {
903 is->setTimeOffset(max(pos, serverInitTime));
904}
905
906long RfbPlayer::getSeekOffset() {
907 return is->getSeekOffset();
908}
909
910bool RfbPlayer::isSeeking() {
911 return is->isSeeking();
912}
913
914bool RfbPlayer::isSeekMode() {
915 return seekMode;
916}
917
918bool RfbPlayer::isPaused() {
919 return is->isPaused();
920}
921
922long RfbPlayer::getTimeOffset() {
george828a471482005-02-06 07:15:53 +0000923 return max(is->getTimeOffset(), is->getSeekOffset());
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +0000924}
925
george828a471482005-02-06 07:15:53 +0000926void RfbPlayer::updatePos(long newPos) {
927 // Update time pos in static control
george823c8fbbf2005-01-24 11:09:08 +0000928 char timePos[30] = "\0";
george829403bee2005-02-06 11:14:39 +0000929 long sliderPos = newPos;
george828a471482005-02-06 07:15:53 +0000930 newPos /= 1000;
george8244325492005-02-06 07:29:51 +0000931 sprintf(timePos, "%.2um:%.2us (%s)", newPos/60, newPos%60, fullSessionTime);
george823c8fbbf2005-01-24 11:09:08 +0000932 SetWindowText(timeStatic, timePos);
george828a471482005-02-06 07:15:53 +0000933
934 // Update the position of slider
935 if (!sliderDraging) {
936 sliderPos /= sliderStepMs;
george829403bee2005-02-06 11:14:39 +0000937 if (sliderPos > SendMessage(posTrackBar, TBM_GETPOS, 0, 0))
938 SendMessage(posTrackBar, TBM_SETPOS, TRUE, sliderPos);
george828a471482005-02-06 07:15:53 +0000939 }
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};