注册 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

BCB-DG's Blog

...

 
 
 

日志

 
 

Use UltraVNC Mirror Driver  

2011-12-16 15:35:06|  分类: VNC |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |
#ifndef _VIDEOD_H
#define _VIDEOD_H

#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <windows.h>
#include <tchar.h>
#include <winbase.h>
#include <winreg.h>

#define MAXCHANGES_BUF 2000
#define OSVISTA 6
#define OSWINXP 5
#define OSWIN2000 5
#define OSWIN2003 5
#define OSOLD 4
#define OSWINXP64 7
#define SCREEN_SCREEN 11
#define BLIT 12
#define SOLIDFILL 13
#define BLEND 14
#define TRANS 15
#define PLG 17
#define TEXTOUT 18

typedef BOOL (WINAPI* pEnumDisplayDevices)(PVOID,DWORD,PVOID,DWORD);
typedef LONG (WINAPI* pChangeDisplaySettingsExA)(LPCSTR,LPDEVMODEA,HWND,DWORD,LPVOID);
typedef void (WINAPI *PGNSI)(LPSYSTEM_INFO);

typedef struct _CHANGES_RECORD
{
    ULONG type;  //screen_to_screen, blit, newcache,oldcache
    RECT rect;   
    POINT point;
}CHANGES_RECORD;
typedef CHANGES_RECORD *PCHANGES_RECORD;

typedef struct _CHANGES_BUF
{
  ULONG counter;
  CHANGES_RECORD pointrect[MAXCHANGES_BUF];
}CHANGES_BUF;
typedef CHANGES_BUF *PCHANGES_BUF;

class VIDEODRIVER
{
public:
    VIDEODRIVER();
    void VIDEODRIVER_start(int x,int y,int w,int h,int depth);
    void VIDEODRIVER_Stop();
    virtual ~VIDEODRIVER();
    BOOL HardwareCursor();
    BOOL NoHardwareCursor();
    ULONG oldaantal;
    PCHAR mypVideoMemory;
    PCHAR myframebuffer;
    PCHANGES_BUF mypchangebuf;
    BOOL blocked;
    int shared_buffer_size;
protected:
    int OSVersion();
    bool Mirror_driver_attach_XP(int x,int y,int w,int h,int depth);
    void Mirror_driver_detach_XP();
    bool Mirror_driver_Vista(DWORD dwAttach,int x,int y,int w,int h,int depth);
    PCHAR VideoMemory_GetSharedMemory(void);
    void VideoMemory_ReleaseSharedMemory(PCHAR pVideoMemory);
    HDC GetDcMirror();
    int OSVER;   
};
#endif

#include "stdafx.h"
#include "videodriver.h"
#include <StrSafe.h>

#define MAP1 1030
#define UNMAP1 1031
#define CURSOREN 1060
#define CURSORDIS 1061
LPSTR driverName = "mv video hook driver2";

VIDEODRIVER::VIDEODRIVER()
{
    mypVideoMemory=NULL;
    mypchangebuf=NULL;
    myframebuffer=NULL;
    shared_buffer_size=0;
}

void VIDEODRIVER::VIDEODRIVER_start(int x,int y,int w,int h,int depth)
{
    blocked=true;
    oldaantal=1;
    mypVideoMemory=NULL;
    OSVER=OSVersion();
    if (OSVER==OSWIN2000||OSVER==OSWIN2003||OSVER==OSWINXP)
    {
        if (Mirror_driver_attach_XP(x,y,w,h,depth))
        {
            if (GetDcMirror()!=NULL)
            {
        mypVideoMemory=VideoMemory_GetSharedMemory();
        mypchangebuf=(PCHANGES_BUF)mypVideoMemory;
        myframebuffer=mypVideoMemory+sizeof(CHANGES_BUF);
            }
            else
            {
                mypVideoMemory=NULL;
            }
        }
        else
        {
            mypVideoMemory=NULL;
        }
    }
    if (OSVER==OSVISTA)
    {
        if (Mirror_driver_Vista(1,x,y,w,h,depth))
        {
            if (GetDcMirror()!=NULL)
            {
        mypVideoMemory=VideoMemory_GetSharedMemory();
        mypchangebuf=(PCHANGES_BUF)mypVideoMemory;
        myframebuffer=mypVideoMemory+sizeof(CHANGES_BUF);
            }
            else
            {
                if (Mirror_driver_attach_XP(x,y,w,h,depth))
        {
          if (GetDcMirror()!=NULL)
          {
            mypVideoMemory=VideoMemory_GetSharedMemory();
            mypchangebuf=(PCHANGES_BUF)mypVideoMemory;
            myframebuffer=mypVideoMemory+sizeof(CHANGES_BUF);
          }
          else
          {
            mypVideoMemory=NULL;
          }
        }
        else
        {
          mypVideoMemory=NULL;
        }
            }
        }
        else
        {
            mypVideoMemory=NULL;
        }
    }
    blocked=false;
}

void VIDEODRIVER::VIDEODRIVER_Stop()
{
    OSVER=OSVersion();
    if (OSVER==OSWIN2000||OSVER==OSWIN2003||OSVER==OSWINXP)
    {
        Mirror_driver_detach_XP();
        if (mypVideoMemory!=NULL) VideoMemory_ReleaseSharedMemory(mypVideoMemory);
    }
    if (OSVER==OSVISTA)
    {
        Mirror_driver_Vista(0,0,0,0,0,0);
        if (mypVideoMemory!=NULL) VideoMemory_ReleaseSharedMemory(mypVideoMemory);
    }
    mypVideoMemory=NULL;
    mypchangebuf=NULL;
    myframebuffer=NULL;
}

VIDEODRIVER::~VIDEODRIVER()
{
    OSVER=OSVersion();
    if (OSVER==OSWIN2000||OSVER==OSWIN2003||OSVER==OSWINXP)
    {
        Mirror_driver_detach_XP();
        if (mypVideoMemory!=NULL) VideoMemory_ReleaseSharedMemory(mypVideoMemory);
    }
    if (OSVER==OSVISTA)
    {
        Mirror_driver_Vista(0,0,0,0,0,0);
        if (mypVideoMemory!=NULL) VideoMemory_ReleaseSharedMemory(mypVideoMemory);
    }
}

void VIDEODRIVER::VideoMemory_ReleaseSharedMemory(PCHAR pVideoMemory)
{
  UnmapViewOfFile(pVideoMemory);
}

PCHAR VIDEODRIVER::VideoMemory_GetSharedMemory(void)
{
  PCHAR pVideoMemory=NULL;
  HANDLE hMapFile, hFile, hFile0,hFile1;
  hFile=NULL;  
  hFile0 = CreateFile("c:\\video0.dat", GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL);
  hFile1 = CreateFile("c:\\video1.dat", GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL);
  if ((hFile0 && hFile0 != INVALID_HANDLE_VALUE) && !(hFile1 && hFile1 != INVALID_HANDLE_VALUE)) hFile=hFile0;
  if ((hFile1 && hFile1 != INVALID_HANDLE_VALUE) && !(hFile0 && hFile0 != INVALID_HANDLE_VALUE)) hFile=hFile1;
  if ((hFile0 && hFile0 != INVALID_HANDLE_VALUE) && (hFile1 && hFile1 != INVALID_HANDLE_VALUE))
  {
    DWORD size0=GetFileSize(hFile0,NULL);
    DWORD size1=GetFileSize(hFile1,NULL);
    if (size0==shared_buffer_size) hFile=hFile0;
    if (size1==shared_buffer_size) hFile=hFile1;
  }
  if(hFile && hFile != INVALID_HANDLE_VALUE)
  {
    hMapFile = CreateFileMapping(hFile, NULL, PAGE_READWRITE, 0, 0, NULL);
    if(hMapFile && hMapFile != INVALID_HANDLE_VALUE)
    {
      pVideoMemory = (char *) MapViewOfFile(hMapFile, FILE_MAP_READ, 0, 0, 0);
      CloseHandle(hMapFile);
    }
    CloseHandle(hFile);
  }  
  return pVideoMemory;
}

bool VIDEODRIVER::Mirror_driver_Vista(DWORD dwAttach,int x,int y,int w,int h,int depth)
{
  HDESK   hdeskInput;
  HDESK   hdeskCurrent;
  pEnumDisplayDevices pd;
  HMODULE hUser32=LoadLibrary("USER32");
  pd = (pEnumDisplayDevices)GetProcAddress( hUser32, "EnumDisplayDevicesA");
  BOOL  bED   = TRUE;
  DEVMODE devmode;
  FillMemory(&devmode, sizeof(DEVMODE), 0);
  devmode.dmSize = sizeof(DEVMODE);
  devmode.dmDriverExtra = 0;
  // Make sure we have a display on this thread.
  BOOL change = EnumDisplaySettings(NULL, ENUM_CURRENT_SETTINGS, &devmode);
  devmode.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT | DM_POSITION ;
  if (change)
  {
    // query all display devices in the system until we hit a primary display device. Using it get the width and height of the primary
    // so we can use that for the mirror driver. Also enumerate the display devices installed on this machine untill we hit our favourate mirrored driver, then extract the device name string of the format '\\.\DISPLAY#'
    DISPLAY_DEVICE dispDevice;
    FillMemory(&dispDevice, sizeof(DISPLAY_DEVICE), 0);
    dispDevice.cb = sizeof(DISPLAY_DEVICE);
    LPSTR deviceName = NULL;
    devmode.dmDeviceName[0] = '\0';
    INT devNum = 0;
    BOOL result;
    DWORD cxPrimary = 0xFFFFFFFF;
    DWORD cyPrimary = 0xFFFFFFFF;
    // First enumerate for Primary display device:
    while (result = (*pd)(NULL, devNum, &dispDevice, 0))
    {
      if (dispDevice.StateFlags & DISPLAY_DEVICE_PRIMARY_DEVICE)
      {
        // Primary device. Find out its dmPelsWidht and dmPelsHeight.
        EnumDisplaySettings(dispDevice.DeviceName, ENUM_CURRENT_SETTINGS, &devmode);
        cxPrimary = devmode.dmPelsWidth;
        cyPrimary = devmode.dmPelsHeight;
        break;
      }
      devNum++;
    }
        if (depth!=0) devmode.dmBitsPerPel=depth;
        else
        {
            if (devmode.dmBitsPerPel!=8 && devmode.dmBitsPerPel!=16 && devmode.dmBitsPerPel!=32)
            {
                if (hUser32) FreeLibrary(hUser32);
                return false;
            }
        }
        shared_buffer_size=devmode.dmBitsPerPel/8*w*h+sizeof(CHANGES_BUF);
    if (!result)
    {
      if (hUser32) FreeLibrary(hUser32);
      return false;
    }
    if (cxPrimary == 0xffffffff || cyPrimary == 0xffffffff)
    {
      if (hUser32) FreeLibrary(hUser32);
      return false;
    }
    // Enumerate again for the mirror driver:
    devNum = 0;
    while (result = (*pd)(NULL, devNum, &dispDevice, 0))
    {
      if (strcmp(&dispDevice.DeviceString[0], driverName) == 0) break;
      devNum++;
    }
    if (!result)
    {
      if (hUser32) FreeLibrary(hUser32);
      return false;
    }
    CHAR deviceNum[MAX_PATH];
    LPSTR deviceSub;
    // Simply extract 'DEVICE#' from registry key.  This will depend on how many mirrored devices your driver has and which ones you intend to use.
    _strupr(&dispDevice.DeviceKey[0]);
    deviceSub = strstr(&dispDevice.DeviceKey[0], "\\DEVICE");
    if (!deviceSub)
      StringCbCopy(&deviceNum[0], sizeof(deviceNum), "DEVICE0");
    else
      StringCbCopy(&deviceNum[0], sizeof(deviceNum), ++deviceSub);
    // Reset the devmode for mirror driver use:
    FillMemory(&devmode, sizeof(DEVMODE), 0);
    devmode.dmSize = sizeof(DEVMODE);
    devmode.dmDriverExtra = 0;
    devmode.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT | DM_POSITION;
    StringCbCopy((LPSTR)&devmode.dmDeviceName[0], sizeof(devmode.dmDeviceName), "mv2");
    deviceName = (LPSTR)&dispDevice.DeviceName[0];
    if (bED)
    {
      // Attach and detach information is sent via the dmPelsWidth/Height of the devmode.
      if (dwAttach == 0)
      {
        devmode.dmPelsWidth = 0;
        devmode.dmPelsHeight = 0;
      }
      else
      {
        devmode.dmPelsWidth=w;
        devmode.dmPelsHeight=h;
        devmode.dmPosition.x=x;
        devmode.dmPosition.y=y;
      }
      // Update the mirror device's registry data with the devmode. Dont do a mode change.
            hdeskCurrent = GetThreadDesktop(GetCurrentThreadId());
      if (hdeskCurrent != NULL)
      {
        hdeskInput = OpenInputDesktop(0, FALSE, MAXIMUM_ALLOWED);
        if (hdeskInput != NULL) SetThreadDesktop(hdeskInput);
      }
      INT code = ChangeDisplaySettingsEx(deviceName, &devmode, NULL, (CDS_UPDATEREGISTRY | CDS_RESET|CDS_GLOBAL), NULL);
            if (code!=0)
            {
                if (hUser32) FreeLibrary(hUser32);
                return false;
            }
      // Now do the real mode change to take mirror driver changes into effect.
      code = ChangeDisplaySettingsEx(NULL, NULL, NULL, 0, NULL);
            SetThreadDesktop(hdeskCurrent);
            CloseDesktop(hdeskInput);
            if (code!=0)
            {
                if (hUser32) FreeLibrary(hUser32);
                return false;
            }
            if (hUser32) FreeLibrary(hUser32);
            return true;
    }
        if (hUser32) FreeLibrary(hUser32);
        return false;
    }
    if (hUser32) FreeLibrary(hUser32);
    return false;
}

void VIDEODRIVER::Mirror_driver_detach_XP()
{
    HDESK   hdeskInput;
  HDESK   hdeskCurrent;
    pEnumDisplayDevices pd;
    HMODULE hUser32=LoadLibrary("USER32");
    pd = (pEnumDisplayDevices)GetProcAddress( hUser32, "EnumDisplayDevicesA");
    DEVMODE devmode;
  FillMemory(&devmode, sizeof(DEVMODE), 0);
  devmode.dmSize = sizeof(DEVMODE);
  devmode.dmDriverExtra = 0;
  BOOL change = EnumDisplaySettings(NULL, ENUM_CURRENT_SETTINGS, &devmode);
  devmode.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;
  if (change)
  {
      // query all display devices in the system until we hit our favourate mirrored driver, then extract the device name string of the format '\\.\DISPLAY#'    
      DISPLAY_DEVICE dispDevice;    
      FillMemory(&dispDevice, sizeof(DISPLAY_DEVICE), 0);    
      dispDevice.cb = sizeof(DISPLAY_DEVICE);    
      LPSTR deviceName = NULL;
      devmode.dmDeviceName[0] = '\0';
      INT devNum = 0;
      BOOL result;
      while (result = (*pd)(NULL,devNum, &dispDevice, 0))
      {
        if (strcmp(&dispDevice.DeviceString[0], driverName) == 0) break;
        devNum++;
      }      
      if (!result)
      {
         if (hUser32) FreeLibrary(hUser32);
         return;
      }
      CHAR deviceNum[MAX_PATH];
      LPSTR deviceSub;
      // Simply extract 'DEVICE#' from registry key.  This will depend on how many mirrored devices your driver has and which ones you intend to use.
      _strupr(&dispDevice.DeviceKey[0]);
      deviceSub = strstr(&dispDevice.DeviceKey[0], "\\DEVICE");
      if (!deviceSub)
          StringCbCopy(&deviceNum[0], sizeof(deviceNum), "DEVICE0");
      else
          StringCbCopy(&deviceNum[0], sizeof(deviceNum), ++deviceSub);
    HKEY hKeyProfileMirror = (HKEY)0;
    if (RegCreateKey(HKEY_LOCAL_MACHINE, _T("SYSTEM\\CurrentControlSet\\Hardware Profiles\\Current\\System\\CurrentControlSet\\Services\\mv2"), &hKeyProfileMirror) != ERROR_SUCCESS)
    {
       if (hUser32) FreeLibrary(hUser32);
       return;
    }
    HKEY hKeyDevice = (HKEY)0;
    if (RegCreateKey(hKeyProfileMirror, _T(&deviceNum[0]), &hKeyDevice) != ERROR_SUCCESS)
    {
       if (hUser32) FreeLibrary(hUser32);
       return;
    }
    DWORD one = 0;
    if (RegSetValueEx(hKeyDevice, _T("Attach.ToDesktop"), 0, REG_DWORD, (unsigned char *)&one, 4) != ERROR_SUCCESS)
    {
       if (hUser32) FreeLibrary(hUser32);
       return;
    }
    RegCloseKey(hKeyProfileMirror);
    RegCloseKey(hKeyDevice);
    deviceSub = strstr(&dispDevice.DeviceKey[0], "SYSTEM");
    HKEY hKeyProfileMirror = (HKEY)0;
    if (RegCreateKey(HKEY_LOCAL_MACHINE, _T("SYSTEM\\CurrentControlSet\\Hardware Profiles\\Current"), &hKeyProfileMirror) != ERROR_SUCCESS)
    {
       if (hUser32) FreeLibrary(hUser32);
       return;
    }
    HKEY hKeyDevice = (HKEY)0;
    if (RegCreateKey(hKeyProfileMirror, _T(deviceSub), &hKeyDevice) != ERROR_SUCCESS)
    {
       if (hUser32) FreeLibrary(hUser32);
       return;
    }
    DWORD one = 0;
    if (RegSetValueEx(hKeyDevice, _T("Attach.ToDesktop"), 0, REG_DWORD, (unsigned char *)&one, 4) != ERROR_SUCCESS)
    {
       if (hUser32) FreeLibrary(hUser32);
       return;
    }
    RegCloseKey(hKeyProfileMirror);
    RegCloseKey(hKeyDevice);
    StringCbCopy((LPSTR)&devmode.dmDeviceName[0], sizeof(devmode.dmDeviceName), "mv2");
    deviceName = (LPSTR)&dispDevice.DeviceName[0];
        devmode.dmBitsPerPel=32;
    // add 'Default.*' settings to the registry under above hKeyProfile\mirror\device
        hdeskCurrent = GetThreadDesktop(GetCurrentThreadId());
    if (hdeskCurrent != NULL)
    {
      hdeskInput = OpenInputDesktop(0, FALSE, MAXIMUM_ALLOWED);
      if (hdeskInput != NULL) SetThreadDesktop(hdeskInput);
    }
    INT code = ChangeDisplaySettingsEx(deviceName, &devmode, NULL, CDS_UPDATEREGISTRY, NULL);
    code = ChangeDisplaySettingsEx(deviceName, &devmode, NULL, 0, NULL);  
        SetThreadDesktop(hdeskCurrent);
        CloseDesktop(hdeskInput);       
    }
  if (hUser32) FreeLibrary(hUser32);
}

bool VIDEODRIVER::Mirror_driver_attach_XP(int x,int y,int w,int h,int depth)
{
    HDESK   hdeskInput;
  HDESK   hdeskCurrent;
    pEnumDisplayDevices pd;
    HMODULE hUser32=LoadLibrary("USER32");
    pd = (pEnumDisplayDevices)GetProcAddress( hUser32, "EnumDisplayDevicesA");
    DEVMODE devmode;
  FillMemory(&devmode, sizeof(DEVMODE), 0);
  devmode.dmSize = sizeof(DEVMODE);
  devmode.dmDriverExtra = 0;
  BOOL change = EnumDisplaySettings(NULL, ENUM_CURRENT_SETTINGS, &devmode);
  devmode.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_POSITION | DM_PELSHEIGHT;
    if (depth!=0) devmode.dmBitsPerPel = depth;
    else
    {
        if (devmode.dmBitsPerPel!=8 && devmode.dmBitsPerPel!=16 && devmode.dmBitsPerPel!=32)
        {
            if (hUser32) FreeLibrary(hUser32);
      return false;
        }
    }
    shared_buffer_size=devmode.dmBitsPerPel/8*w*h+sizeof(CHANGES_BUF);
  if (change)
  {
    // query all display devices in the system until we hit our favourate mirrored driver, then extract the device name string of the format '\\.\DISPLAY#'
    DISPLAY_DEVICE dispDevice;
    FillMemory(&dispDevice, sizeof(DISPLAY_DEVICE), 0);
    dispDevice.cb = sizeof(DISPLAY_DEVICE);
    LPSTR deviceName = NULL;
    devmode.dmDeviceName[0] = '\0';
    INT devNum = 0;
    BOOL result;
    while (result = (*pd)(NULL, devNum, &dispDevice, 0))
    {
      if (strcmp(&dispDevice.DeviceString[0], driverName) == 0) break;
       devNum++;
    }  
    if (!result)
    {
      if (hUser32) FreeLibrary(hUser32); return false;
    }
    CHAR deviceNum[MAX_PATH];
    LPSTR deviceSub;
    // Simply extract 'DEVICE#' from registry key.  This will depend on how many mirrored devices your driver has and which ones you intend to use.
    _strupr(&dispDevice.DeviceKey[0]);
    deviceSub = strstr(&dispDevice.DeviceKey[0], "\\DEVICE");
    if (!deviceSub)
      StringCbCopy(&deviceNum[0], MAX_PATH, "DEVICE0");
    else
      StringCbCopy(&deviceNum[0], MAX_PATH, ++deviceSub);   
    // Add 'Attach.ToDesktop' setting.
    HKEY hKeyProfileMirror = (HKEY)0;
    if (RegCreateKey(HKEY_LOCAL_MACHINE, _T("SYSTEM\\CurrentControlSet\\Hardware Profiles\\Current\\System\\CurrentControlSet\\Services\\mv2"), &hKeyProfileMirror) != ERROR_SUCCESS)
    {
      if (hUser32) FreeLibrary(hUser32);
      return false;
    }
    HKEY hKeyDevice = (HKEY)0;
    if (RegCreateKey(hKeyProfileMirror, _T(&deviceNum[0]), &hKeyDevice) != ERROR_SUCCESS)
    {
      if (hUser32) FreeLibrary(hUser32);
      return false;
    }
    DWORD one = 1;
    if (RegSetValueEx(hKeyDevice, _T("Attach.ToDesktop"), 0, REG_DWORD, (unsigned char *)&one, 4) != ERROR_SUCCESS)
    {
      if (hUser32) FreeLibrary(hUser32);
      return false;
    }

    StringCbCopy((LPSTR)&devmode.dmDeviceName[0], 32, "mv2");
    deviceName = (LPSTR)&dispDevice.DeviceName[0];
        devmode.dmPelsWidth=w;
        devmode.dmPelsHeight=h;
        devmode.dmPosition.x=x;
        devmode.dmPosition.y=y;

        hdeskCurrent = GetThreadDesktop(GetCurrentThreadId());
    if (hdeskCurrent != NULL)
    {
      hdeskInput = OpenInputDesktop(0, FALSE, MAXIMUM_ALLOWED);
      if (hdeskInput != NULL) SetThreadDesktop(hdeskInput);
    }
    // add 'Default.*' settings to the registry under above hKeyProfile\mirror\device
    INT code = ChangeDisplaySettingsEx(deviceName, &devmode, NULL, CDS_UPDATEREGISTRY, NULL);
        if (code!=0)
        {
            if (hUser32) FreeLibrary(hUser32);
            return false;
        }
    code = ChangeDisplaySettingsEx(deviceName, &devmode, NULL, 0, NULL);  
        SetThreadDesktop(hdeskCurrent);
        CloseDesktop(hdeskInput);
        RegCloseKey(hKeyProfileMirror);
    RegCloseKey(hKeyDevice);
        if (code!=0)
        {
            if (hUser32) FreeLibrary(hUser32);
            return false;
        }
        if (hUser32) FreeLibrary(hUser32);
        return true;
    }
    if (hUser32) FreeLibrary(hUser32);
    return false;
}

int VIDEODRIVER::OSVersion()
{
   OSVERSIONINFOEX osvi;
   SYSTEM_INFO si;
   PGNSI pGNSI;
   BOOL bOsVersionInfoEx;
   ZeroMemory(&si, sizeof(SYSTEM_INFO));
   ZeroMemory(&osvi, sizeof(OSVERSIONINFOEX));
   osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
   if( !(bOsVersionInfoEx = GetVersionEx ((OSVERSIONINFO *) &osvi)) )
   {
      osvi.dwOSVersionInfoSize = sizeof (OSVERSIONINFO);
      if (! GetVersionEx ( (OSVERSIONINFO *) &osvi) ) return FALSE;
   }
   pGNSI = (PGNSI) GetProcAddress(GetModuleHandle(TEXT("kernel32.dll")), "GetNativeSystemInfo");
  if (NULL != pGNSI)
    pGNSI(&si);
  else
    GetSystemInfo(&si);
    switch (osvi.dwPlatformId)
  {
    case VER_PLATFORM_WIN32_NT:
    if ( osvi.dwMajorVersion == 6) return OSVISTA;
    if ( osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 2 )
    {
      if( osvi.wProductType == VER_NT_WORKSTATION && si.wProcessorArchitecture==PROCESSOR_ARCHITECTURE_AMD64)
        return OSWINXP64;
      else
        return OSWIN2003;
    }
    if ( osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 1 ) return OSWINXP;
    if ( osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 0 ) return OSWIN2000;
    if ( osvi.dwMajorVersion <= 4 ) return OSOLD;
    }
    return OSOLD;
}

HDC VIDEODRIVER::GetDcMirror()
{
    typedef BOOL (WINAPI* pEnumDisplayDevices)(PVOID,DWORD,PVOID,DWORD);
        HDC m_hrootdc=NULL;
        pEnumDisplayDevices pd;
        LPSTR driverName = "mv video hook driver2";
        BOOL DriverFound;
        DEVMODE devmode;
        FillMemory(&devmode, sizeof(DEVMODE), 0);
        devmode.dmSize = sizeof(DEVMODE);
        devmode.dmDriverExtra = 0;
        BOOL change = EnumDisplaySettings(NULL,ENUM_CURRENT_SETTINGS,&devmode);
        devmode.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;
        HMODULE hUser32=LoadLibrary("USER32");
        pd = (pEnumDisplayDevices)GetProcAddress( hUser32, "EnumDisplayDevicesA");
        if (pd)
    {
      LPSTR deviceName=NULL;
      DISPLAY_DEVICE dd;
      ZeroMemory(&dd, sizeof(dd));
      dd.cb = sizeof(dd);
      devmode.dmDeviceName[0] = '\0';
      INT devNum = 0;
      BOOL result;
      DriverFound=false;
      while (result = (*pd)(NULL,devNum, &dd,0))
      {
        if (strcmp((const char *)&dd.DeviceString[0], driverName) == 0)
        {
          DriverFound=true;
          break;
        }
        devNum++;
      }
      if (DriverFound)
      {
        deviceName = (LPSTR)&dd.DeviceName[0];
        m_hrootdc = CreateDC("DISPLAY",deviceName,NULL,NULL);   
        if (m_hrootdc) DeleteDC(m_hrootdc);
      }
    }
        if (hUser32) FreeLibrary(hUser32);
        return m_hrootdc;
}

BOOL VIDEODRIVER:: HardwareCursor()
{
    HDC gdc;
    int returnvalue;
    gdc = GetDC(NULL);
    returnvalue= ExtEscape(gdc, MAP1, 0, NULL, NULL, NULL);
    returnvalue= ExtEscape(gdc, CURSOREN, 0, NULL, NULL, NULL);
    ReleaseDC(NULL,gdc);
    return true;
}

BOOL VIDEODRIVER:: NoHardwareCursor()
{
    HDC gdc;
    int returnvalue;
    gdc = GetDC(NULL);
    returnvalue= ExtEscape(gdc, CURSORDIS, 0, NULL, NULL, NULL);
    ReleaseDC(NULL,gdc);
    return true;
}
  评论这张
 
阅读(3028)| 评论(0)
推荐 转载

历史上的今天

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2017