This is a mirror of official site: http://jasper-net.blogspot.com/

An HTML5 Remote Desktop

| Thursday, May 13, 2010
VNC and Remote Desktop software were around for a long while now. Undoubtedly they work great for most of purposes but, I wanted to bring the old VNC / Remote Desktop concept over the web, to allow full web-application integration and full cross-browser cross-platform support out-of-the-box.

Despite its name, ThinVNC is not a traditional VNC, as it does not implement the AT&T RFB protocol. Instead, it is built on top of today's web standards: AJAX, JSON and HTML5.

The Code (Part I)

In this first part we'll see the code to do the screen capture. The standard aproach is to capture the whole desktop. However, in this case, we'll capture every window individually, applying clipping regions and saving the individual bitmap for later comparison and difference extracting.

Firstly we need to enumerate all visible top windows:

TWin = class(TObject)
private
 Wnd : Hwnd;
 Rect : TRect;
 Pid : Cardinal;
public
 constructor Create(AWnd:HWND;ARect:TRect;APid:Cardinal);
end;

function EnumWindowsProc(Wnd: HWnd; const obj:TList<TWin>): Bool; export; stdcall;
var ProcessId : Cardinal;
 R,R1 : TRect;
 Win : TWin;
begin
 Result:=True;
 GetWindowThreadProcessId(Wnd,ProcessId);
 if IsWindowVisible(Wnd) and not IsIconic(wnd)then begin
   GetWindowRect(Wnd,R);
   IntersectRect(R1,R,Screen.DesktopRect);
   if not IsRectEmpty(R1) then begin
     win := TWin.Create(Wnd,R,ProcessId);
     obj.Add(win);
   end;
 end;
end;

procedure GetProcessWindowList(WinList:TList<TWin>);
begin
 WinList.Clear;
 EnumWindows(@EnumWindowsProc, Longint(WinList));
end;
We want to keep a list of windows, with their basic attributes and their bitmaps, so we can compare with the new ones and send the differences to the client. Here we merge the window list into a list of TWindowMirror:

TWindowMirror = class
private
 FIndex : Integer;
 FRgn : HRGN;
 FHandle : THandle;
 FBoundsRect : TRect;
 FProcessId : Integer;
 FImage : TBitmap;
 FDiffStreamList : TList<TImagePart>;
 ...
 ...
end;

procedure TMirrorManager.RefreshMirrorList(out OneMoved:Boolean);
 procedure GetProcessWindowList(WinList:TList<TWin>);
 begin
   WinList.Clear;
   EnumWindows(@EnumWindowsProc, Longint(WinList));
 end;

Read more: Codeproject

Posted via email from jasper22's posterous

0 comments: