⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 vncdesktop.h

📁 teamviewer source code vc++
💻 H
字号:
//  Copyright (C) 2002 Ultr@VNC Team Members. All Rights Reserved.
//  Copyright (C) 2000-2002 Const Kaplinsky. All Rights Reserved.
//  Copyright (C) 2002 RealVNC Ltd. All Rights Reserved.
//  Copyright (C) 1999 AT&T Laboratories Cambridge. All Rights Reserved.
//
//  This file is part of TeamViewer.
//
//  TeamViewer is free software; you can redistribute it and/or modify
//  it under the terms of the GNU General Public License as published by
//  the Free Software Foundation; either version 2 of the License, or
//  (at your option) any later version.
//
//  This program is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//  GNU General Public License for more details.
//
//  You should have received a copy of the GNU General Public License
//  along with this program; if not, write to the Free Software
//  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,
//  USA.
//
//  If the source code for TeamViewer is not available from the place 
//  whence you received this file, check http://www.teamviewer.com
//  for information on obtaining it.


// vncDesktop object

// The vncDesktop object handles retrieval of data from the
// display buffer.  It also uses the RFBLib DLL to supply
// information on mouse movements and screen updates to
// the server

class vncDesktop;

#if !defined(_WINVNC_VNCDESKTOP)
#define _WINVNC_VNCDESKTOP
#pragma once

// Include files
class vncServer;
#include "rfbUpdateTracker.h"
#include "vncBuffer.h"
#include "translate.h"
#include "videodriver.h"
#include "textchat.h"
//#define COMPILE_MULTIMON_STUBS
//#include "Multimon.h"
#ifndef SM_CMONITORS

#define SM_XVIRTUALSCREEN       76
#define SM_YVIRTUALSCREEN       77
#define SM_CXVIRTUALSCREEN      78
#define SM_CYVIRTUALSCREEN      79
#define SM_CMONITORS            80
#define SM_SAMEDISPLAYFORMAT    81

// HMONITOR is already declared if WINVER >= 0x0500 in windef.h
// This is for components built with an older version number.
//
#if !defined(HMONITOR_DECLARED) && (WINVER < 0x0500)
DECLARE_HANDLE(HMONITOR);
#define HMONITOR_DECLARED
#endif

#define MONITOR_DEFAULTTONULL       0x00000000
#define MONITOR_DEFAULTTOPRIMARY    0x00000001
#define MONITOR_DEFAULTTONEAREST    0x00000002

#define MONITORINFOF_PRIMARY        0x00000001

typedef struct tagMONITORINFO
{
    DWORD   cbSize;
    RECT    rcMonitor;
    RECT    rcWork;
    DWORD   dwFlags;
} MONITORINFO, *LPMONITORINFO;

#ifndef CCHDEVICENAME
#define CCHDEVICENAME 32
#endif

#ifdef __cplusplus
typedef struct tagMONITORINFOEXA : public tagMONITORINFO
{
    CHAR        szDevice[CCHDEVICENAME];
} MONITORINFOEXA, *LPMONITORINFOEXA;
typedef struct tagMONITORINFOEXW : public tagMONITORINFO
{
    WCHAR       szDevice[CCHDEVICENAME];
} MONITORINFOEXW, *LPMONITORINFOEXW;
#ifdef UNICODE
typedef MONITORINFOEXW MONITORINFOEX;
typedef LPMONITORINFOEXW LPMONITORINFOEX;
#else
typedef MONITORINFOEXA MONITORINFOEX;
typedef LPMONITORINFOEXA LPMONITORINFOEX;
#endif // UNICODE
#else // ndef __cplusplus
typedef struct tagMONITORINFOEXA
{
    MONITORINFO;
    CHAR        szDevice[CCHDEVICENAME];
} MONITORINFOEXA, *LPMONITORINFOEXA;
typedef struct tagMONITORINFOEXW
{
    MONITORINFO;
    WCHAR       szDevice[CCHDEVICENAME];
} MONITORINFOEXW, *LPMONITORINFOEXW;
#ifdef UNICODE
typedef MONITORINFOEXW MONITORINFOEX;
typedef LPMONITORINFOEXW LPMONITORINFOEX;
#else
typedef MONITORINFOEXA MONITORINFOEX;
typedef LPMONITORINFOEXA LPMONITORINFOEX;
#endif // UNICODE
#endif
#endif

typedef std::list<COLORREF> RGBPixelList;   // List of RGB values (pixels)
// sf@2002 - Generates ClassName lenght warning in debug mode compile.
// typedef std::list<RGBPixelList*> GridsList; // List of Grids of pixels
typedef std::list<void*> GridsList; // List of Grids of pixels
typedef std::list<HWND> WindowsList;       // List of windows handles

//SC_MONITORPOWER states
const int MONITOR_ON = -1;
const int MONITOR_OFF = 2;
const int MONITOR_STANBY = 1;

// Constants
extern const UINT RFB_SCREEN_UPDATE;
extern const UINT RFB_COPYRECT_UPDATE;
extern const UINT RFB_MOUSE_UPDATE;
extern const UINT RFB_KEY;
extern const char szDesktopSink[];

#define NONE 0
#define MIRROR 1
#define PSEUDO 2

typedef struct DrvWatch
{
	HWND hwnd;
	bool *stop;
}DrvWatch;

typedef BOOL (*SetHooksFn)(DWORD thread_id,UINT UpdateMsg,UINT CopyMsg,UINT MouseMsg,UINT KeyMsg,BOOL ddihook);
typedef BOOL (*UnSetHooksFn)(DWORD thread_id);
typedef BOOL (*SetKeyboardFilterHookFn)(BOOL activate);	
typedef BOOL (*SetMouseFilterHookFn)(BOOL activate);
typedef BOOL (WINAPI*  pBlockInput) (BOOL);
typedef BOOL (WINAPI* LPGETMONITORINFO)(HMONITOR, LPMONITORINFO);
typedef HMONITOR (WINAPI* LPMONITOTFROMPOINT) (POINT,DWORD);
// Class definition
// multi monitor
struct monitor
{
	int Width;
	int Height;
	int Depth;
	char device[32];
	int offsetx;
	int offsety;
};

class vncDesktop
{

// Fields
public:

// Methods
public:
	// Make the desktop thread & window proc friends
	friend class vncDesktopThread;
	friend LRESULT CALLBACK DesktopWndProc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp);

	// Create/Destroy methods
	vncDesktop();
	~vncDesktop();

	BOOL Init(vncServer *pSrv);

	// Tell the desktop hooks to grab & update a particular rectangle
	void QueueRect(const rfb::Rect &rect);
	
	// Kick the desktop hooks to perform an update
	void TriggerUpdate();

	// Get a reference to the desktop update lock
	// The lock is held while data is being grabbed and copied
	// to the back buffer, and while changes are being passed to
	// clients
	omni_mutex &GetUpdateLock() {return m_update_lock;};

	// Screen translation, capture, info
	void FillDisplayInfo(rfbServerInitMsg *scrInfo);
	void CaptureScreen(const rfb::Rect &UpdateArea, BYTE *scrBuff, UINT scrBuffSize);
	int ScreenBuffSize();
	HWND Window() {return m_hwnd;};

	// Mouse related
	void CaptureMouse(BYTE *scrBuff, UINT scrBuffSize);
	rfb::Rect MouseRect();
	void SetCursor(HCURSOR cursor);
	// CURSOR HANDLING
	BOOL GetRichCursorData(BYTE *databuf, HCURSOR hcursor, int width, int height);
	HCURSOR GetCursor() { return m_hcursor; }

	// Clipboard manipulation
	void SetClipText(LPSTR text);

	// Method to obtain the DIBsection buffer if fast blits are enabled
	// If they're disabled, it'll return NULL
	inline VOID *OptimisedBlitBuffer() {return m_DIBbits;};

	BOOL	m_initialClipBoardSeen;

	// Handler for pixel data grabbing and region change checking
	vncBuffer		m_buffer;
		//SINGLE WINDOW
	vncServer		*GetServerPointer() {return m_server;};
	HWND			m_Single_hWnd;
	HWND			m_Single_hWnd_backup;
	BOOL			CalculateSWrect(RECT &rect);
	rfb::Rect		GetSize();
	rfb::Rect		GetQuarterSize();

	// Modif rdv@2002 - v1.1.x - videodriver
	//BOOL IsVideoDriverEnabled();
	BOOL VideoBuffer();
	int m_ScreenOffsetx;
	int m_ScreenOffsety;
	int DriverType;
	DWORD color[10];
	// Modif rdv@2002 Dis/enable input
	void SetDisableInput(bool enabled);
	void SetSW(int x,int y);
	void SetSW(HWND window);

	//hook selection
	BOOL m_hookdriver;
	void SethookMechanism(BOOL hookall,BOOL hookdriver);
	bool m_UltraEncoder_used;
	rfb::Rect		m_Cliprect;//the region to check
	bool StopDriverWatches;

	PCHANGES_BUF pchanges_buf;
	CHANGES_BUF changes_buf;

	int GetNrMonitors();
	bool GetDevice(bool primary, int index);
	void Checkmonitors();

	HMODULE GetHookDll() { return hModule; }
	void SearchSingleWindowByName();
	bool m_stop_input_while_sw;
	// Implementation
protected:

	// Routines to hook and unhook us
	BOOL Startup(BOOL silent = FALSE);
	BOOL Shutdown();
	
	// Init routines called by the child thread
	BOOL InitDesktop(BOOL silent = FALSE);
	void KillScreenSaver();
	void KillWallpaper();
	void RestoreWallpaper();
	BOOL InitBitmap();
	BOOL InitWindow();
	BOOL ThunkBitmapInfo();
	BOOL SetPixFormat();
	BOOL SetPixShifts();
	BOOL InitHooks();
	BOOL SetPalette();
	int m_timer;

	//see BlockInput for more information
	private: static bool bBlockStatus;

	/*
	BlockInput tries to block input of a windows desktop system.
	The functions creates a log entry containing actual block status (blocked or opened).
	If an error occurs, it also creates an error log item.

	This function allows only one call to BlockInput either with true or false.
	If BlockInput was called with true, all other calls with true will be dismissed. The same way with false.

	This function uses the static var bBlockStatus. Therefore the function is NOT thread safe!
	That does not matter, because only the thread which blocked the input can open it again.

	@param(doBlock [in] contains a bool value that defines the blocking state of desktop.
				Set to true if you wish to block user input; otherwise false.)
	@return(BlockInput returns true if the call to pbi (a pointer to BlockInput defined in user32.dll)
			was successfull; otherwise false.
			The return of true does not mean the input is blocked. See GetLastError() for more information.
			
			On Windows Vista the function will fail if the process does not have enough rights. At the moment
			there is no more information available (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/userinput/keyboardinput/keyboardinputreference/keyboardinputfunctions/blockinput.asp)

			On Win9x systems the variable pbi is always NULL and so the return value is always false.)
	@precond(The instance variable pbi must be initialised with a pointer directing to function BlockInput.
			 Otherwise the return value is always false.)
    @postcond(The class variable bBlockStatus is set to doBlock if a successfull call to BlockInput (dpi) with parameter doBlock
				was achieved; otherwise set to false. It will not be touched if doBlock equals bBlockStatus or
				 dpi is NULL.)
              
	          
    
	*/
	public: bool BlockInput(bool doBlock);
protected:
	// Fetching pixel data to a buffer, and handling copyrects
	void CopyToBuffer(const rfb::Rect &rect, BYTE *scrBuff, UINT scrBuffSize);
	bool CalcCopyRects(rfb::UpdateTracker &tracker);

	// Routine to attempt enabling optimised DIBsection blits
	void EnableOptimisedBlits();

	// Convert a bit mask eg. 00111000 to max=7, shift=3
	static void MaskToMaxAndShift(DWORD mask, CARD16 &max, CARD8 &shift);
	
	// Enabling & disabling clipboard handling
	void SetClipboardActive(BOOL active) {m_clipboard_active = active;};

	// Modif sf@2002 - v1.1.0 - FastDetectChanges stuff
	void FastDetectChanges(rfb::Region2D &rgn, rfb::Rect &rect, int nZone, bool fTurbo);
	GridsList    m_lGridsList;   // List of changes detection grids
	WindowsList  m_lWList;		 // List of Windows handles  
	// HDC	         m_hDC;			 // Local Screen Device context to capture our Grid of pixels 
	int          m_nGridCycle;   // Cycle index for grid shifting

	// Modif sf@2002 - v1.1.0
	DWORD         m_lLastMouseUpdateTime;
	DWORD        m_lLastSlowClientTestTime;
	// long			m_lLastTempo;

	// sf@2002 - TextChat - No more used for now
	// bool m_fTextChatRunning;
	// TextChat* m_pCurrentTextChat;

	// Generally useful stuff
	vncServer 		*m_server;
	omni_thread 	*m_thread;
	HWND			m_hwnd;
	UINT			m_timerid;
	HWND			m_hnextviewer;
	BOOL			m_clipboard_active;

	// device contexts for memory and the screen
	HDC				m_hmemdc;
	HDC				m_hrootdc;

	// New and old bitmaps
	HBITMAP			m_membitmap;
	omni_mutex		m_update_lock;

	rfb::Rect		m_bmrect;
	struct _BMInfo {
		BOOL			truecolour;
		BITMAPINFO		bmi;
		// Colormap info - comes straight after BITMAPINFO - **HACK**
		RGBQUAD			cmap[256];
	} m_bminfo;

	// Screen info
	rfbServerInitMsg	m_scrinfo;

	// These are the red, green & blue masks for a pixel
	DWORD			m_rMask, m_gMask, m_bMask;

	// This is always handy to have
	int				m_bytesPerRow;

	// Handle of the default cursor
	HCURSOR			m_hcursor;
	HCURSOR			m_hOldcursor; // sf@2002

	// Handle of the basic arrow cursor
	HCURSOR			m_hdefcursor;
	// The current mouse position
	rfb::Rect		m_cursorpos;

	// Boolean flag to indicate when the display resolution has changed
	BOOL			m_displaychanged;

	// Boolean flag to indicate whether or not an update trigger message
	// is already in the desktop thread message queue
	BOOL			m_update_triggered;

	// Extra vars used for the DIBsection optimisation
	VOID			*m_DIBbits;
	BOOL			m_formatmunged;

	// Info used for polling modes
	UINT			m_pollingcycle;
	// rfb::Rect		m_fullscreen; // sf@2002 - v1.1.0

	// Handling of the foreground window, to produce CopyRects
	HWND			m_foreground_window;
	rfb::Rect		m_foreground_window_rect;

	//SINGLE WINDOW
	void SWinit();
	int m_SWHeight;
	int m_SWWidth;
	BOOL m_SWSizeChanged;
	BOOL m_SWmoved;
	BOOL m_SWtoDesktop;
	int m_SWOffsetx;
	int m_SWOffsety;

	//DDIHOOK
	PCOPYDATASTRUCT pMyCDS;

	// Modif rdv@2002 - v1.1.x - videodriver
	vncVideoDriver *m_videodriver;
	BOOL InitVideoDriver();
 	void ShutdownVideoDriver();
	omni_mutex		m_videodriver_lock;

	// Modif input dis/enabke
	DWORD m_thread_hooks;
	BOOL ddihook;
	UINT OldPowerOffTimeout;
	bool OldCaptureBlending;
	//hook selection
	BOOL m_hookdll;
	BOOL On_Off_hookdll;
	BOOL m_hookswitch;
	BOOL Hookdll_Changed;
	BOOL m_hookinited;
	HANDLE m_hddihook;
	void StartStopddihook(BOOL enabled);
	void StartStophookdll(BOOL enabled);
	void InitHookSettings();
	HMODULE hModule;
	SetHooksFn SetHooks;
	UnSetHooksFn  UnSetHooks;
	SetKeyboardFilterHookFn SetKeyboardFilterHook;
	SetMouseFilterHookFn SetMouseFilterHook;
	pBlockInput pbi;
	HMODULE hUser32;
	BOOL Temp_Resolution;
	BOOL m_OrigpollingSet;
	BOOL m_Origpolling;
/*	BOOL Check24bit();*/

	
BOOL DriverWanted;
BOOL HookWanted;
BOOL DriverWantedSet;

//Multi monitor
monitor mymonitor[3];
int nr_monitors;
int current_monitor;
int asked_display;



};

#endif // _WINVNC_VNCDESKTOP

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -