?? server.c
字號:
mouse_event(MOUSEEVENTF_ABSOLUTE|MOUSEEVENTF_MIDDLEUP,dwX,dwY,0,0);
mouse_event(MOUSEEVENTF_ABSOLUTE|MOUSEEVENTF_MIDDLEDOWN,dwX,dwY,0,0);
mouse_event(MOUSEEVENTF_ABSOLUTE|MOUSEEVENTF_MIDDLEUP,dwX,dwY,0,0);
}
else if (iMessage == 8)
{
mouse_event(MOUSEEVENTF_ABSOLUTE|MOUSEEVENTF_RIGHTDOWN,dwX,dwY,0,0);
}
else if (iMessage == 9)
{
mouse_event(MOUSEEVENTF_ABSOLUTE|MOUSEEVENTF_RIGHTUP,dwX,dwY,0,0);
}
else if (iMessage == 10)
{
mouse_event(MOUSEEVENTF_ABSOLUTE|MOUSEEVENTF_RIGHTDOWN,dwX,dwY,0,0);
mouse_event(MOUSEEVENTF_ABSOLUTE|MOUSEEVENTF_RIGHTUP,dwX,dwY,0,0);
mouse_event(MOUSEEVENTF_ABSOLUTE|MOUSEEVENTF_RIGHTDOWN,dwX,dwY,0,0);
mouse_event(MOUSEEVENTF_ABSOLUTE|MOUSEEVENTF_RIGHTUP,dwX,dwY,0,0);
}
}
else
{
// 沒有鼠標(biāo)消息則判斷是否有鍵盤消息
fWMKeyBdMsg = FALSE;
for (iLoop = 0;iLoop < nWMKeyBdMsg;iLoop++)
{
if (strcmp(pCommandNode->Command.szElement,WMKeyBdMsg[iLoop].szWMKeyBdMsg) == 0)
{
// 設(shè)置鍵盤消息標(biāo)志
fWMKeyBdMsg = TRUE;
if (strcmp(WMKeyBdMsg[iLoop].szWMKeyBdMsg,"WM_KD\0") == 0)
iMessage = 1;//按下鍵
else if (strcmp(WMKeyBdMsg[iLoop].szWMKeyBdMsg,"WM_KU\0") == 0)
iMessage = 2;//松開鍵
// 移動到參數(shù)鏈表的下一個(gè)節(jié)點(diǎn),Virtural 鍵碼
pCommandNode = pCommandNode->pNext;
vk = atoi(pCommandNode->Command.szElement);
//移動到參數(shù)鏈表的下一個(gè)節(jié)點(diǎn),按下鍵標(biāo)志
pCommandNode = pCommandNode->pNext;
fDown = atoi(pCommandNode->Command.szElement);
// 移動到參數(shù)鏈表的下一個(gè)節(jié)點(diǎn),按鍵重復(fù)數(shù)
pCommandNode = pCommandNode->pNext;
cRepeat = atoi(pCommandNode->Command.szElement);
// 移動到參數(shù)鏈表的下一個(gè)節(jié)點(diǎn),標(biāo)志位
pCommandNode = pCommandNode->pNext;
flags = atoi(pCommandNode->Command.szElement);
break;
}
}
// 如果有鍵盤消息,則處理鍵盤消息
if (fWMKeyBdMsg)
{
if (iMessage == 1) //模擬按鍵消息
{
keybd_event((BYTE)vk,(BYTE)vk,0,0);
}
else if (iMessage == 2) //模擬松開鍵的消息
{
keybd_event((BYTE)vk,(BYTE)vk,KEYEVENTF_KEYUP,0);
}
}
else // 通用消息
{
for (iLoop = 0;iLoop < nMsg;iLoop++)
{
if (strcmp(pCommandNode->Command.szElement,Msg[iLoop].szMsg) == 0)
{
if (strcmp(Msg[iLoop].szMsg,"WM_COMP\0") == 0)
{
// 移動到參數(shù)鏈表的下一個(gè)節(jié)點(diǎn),壓縮級數(shù)
pCommandNode = pCommandNode->pNext;
iCompressionLevel = atoi(pCommandNode->Command.szElement);
}
else if (strcmp(Msg[iLoop].szMsg,"WM_GRID\0") == 0)
{
// 移動到參數(shù)鏈表的下一個(gè)節(jié)點(diǎn),x網(wǎng)格數(shù)
pCommandNode = pCommandNode->pNext;
nGridX = atoi(pCommandNode->Command.szElement);
// 移動到參數(shù)鏈表的下一個(gè)節(jié)點(diǎn),y網(wǎng)格數(shù)
pCommandNode = pCommandNode->pNext;
nGridY = atoi(pCommandNode->Command.szElement);
// 清除當(dāng)前的顯示設(shè)置
ClearDisplay(hServerWnd);
// 初始化新的顯示設(shè)置
InitDisplay(hServerWnd);
}
else if (strcmp(Msg[iLoop].szMsg,"WM_CMOD\0") == 0)
{
// 移動到參數(shù)鏈表的下一個(gè)節(jié)點(diǎn),每個(gè)屏幕點(diǎn)的字節(jié)數(shù)
pCommandNode = pCommandNode->pNext;
bmBitsPixel = atoi(pCommandNode->Command.szElement);
ClearDisplay(hServerWnd);
InitDisplay(hServerWnd);
}
}
}
}
}
}
// 清除命令隊(duì)列
Clear_Command(&CommandStart);
}
// 初始化顯示變量
void InitDisplay(HWND hWnd)
{
struct GdiDS Gdi;
int iWidthX,iHeightY,nGrid;
int iXGrid,iYGrid,iLoop;
GdiStart.pNext = NULL;
pGdiNode = &GdiStart;
hDDC = CreateDC("DISPLAY",NULL,NULL,NULL);
// 得到屏幕的寬度和高度
iWidth = GetDeviceCaps(hDDC,HORZRES);
iHeight = GetDeviceCaps(hDDC,VERTRES);
// 分割屏幕成X網(wǎng)格區(qū)域
if (nGridX > 0)
iWidthX = iWidth/nGridX;
else
iWidthX = iWidth;
// 分割屏幕成Y網(wǎng)格區(qū)域
if (nGridY > 0)
iHeightY = iHeight/nGridY;
else
iHeightY = iHeight;
// 為網(wǎng)格創(chuàng)建區(qū)域的位圖和Memory DC
if ((nGridX > 0) && (nGridY > 0))
{
for (iXGrid = 0;iXGrid < nGridX;iXGrid++)
{
for (iYGrid = 0;iYGrid < nGridY;iYGrid++)
{
Gdi.fChange = FALSE;
Gdi.fDIBitmap = FALSE;
Gdi.iGridX = iXGrid;
Gdi.iGridY = iYGrid;
Gdi.iWidth1 = iXGrid * iWidthX;
Gdi.iWidth2 = iXGrid * iWidthX + iWidthX;
Gdi.iHeight1 = iYGrid * iHeightY;
Gdi.iHeight2 = iYGrid * iHeightY + iHeightY;
Gdi.hMemDC = CreateCompatibleDC(hDDC);
Gdi.hDIBitmap = CreateCompatibleBitmap(hDDC,iWidthX,iHeightY);
SelectObject(Gdi.hMemDC,Gdi.hDIBitmap);
// 往隊(duì)列中添加GDI信息
pGdiNode = Add_Gdi(pGdiNode,Gdi);
}
}
}
else
{
nGrid = max(nGridX,nGridY);
for (iLoop = 0;iLoop < nGrid;iLoop++)
{
Gdi.fChange = FALSE;
Gdi.fDIBitmap = FALSE;
if (nGridX > 0)
{
Gdi.iGridX = iLoop;
Gdi.iWidth1 = iLoop * iWidthX;
Gdi.iWidth2 = iLoop * iWidthX + iWidthX;
}
else
{
Gdi.iGridX = 0;
Gdi.iWidth1 = 0;
Gdi.iWidth2 = iWidthX;
}
if (nGridY > 0)
{
Gdi.iGridY = iLoop;
Gdi.iHeight1 = iLoop * iHeightY;
Gdi.iHeight2 = iLoop * iHeightY + iHeightY;
}
else
{
Gdi.iGridY = 0;
Gdi.iHeight1 = 0;
Gdi.iHeight2 = iHeightY;
}
Gdi.hMemDC = CreateCompatibleDC(hDDC);
Gdi.hDIBitmap = CreateCompatibleBitmap(hDDC,iWidthX,iHeightY);
SelectObject(Gdi.hMemDC,Gdi.hDIBitmap);
pGdiNode = Add_Gdi(pGdiNode,Gdi);
}
}
hNullDC = GetDC(NULL);
}
// 清除顯示變量
void ClearDisplay(HWND hWnd)
{
DeleteDC(hDDC);
DeleteDC(hNullDC);
Clear_Gdi(&GdiStart);
}
//得到區(qū)域的顯示位圖
int GetRegionDisplay(HWND hWnd)
{
int iWidth1,iWidth2,iHeight1,iHeight2;
BOOL bGotBits;
DWORD iLength;
char *pStartDIB;
DWORD dwLen1;
DWORD dwBitMapHeader1;
char *pDIBitmap1;
char *pDIB1;
int fChange1;
char *pDIBChange1;
// 得到區(qū)域的矩形坐標(biāo)
iWidth1 = pGdiNode->Gdi.iWidth1;
iWidth2 = pGdiNode->Gdi.iWidth2;
iHeight1 = pGdiNode->Gdi.iHeight1;
iHeight2 = pGdiNode->Gdi.iHeight2;
BitBlt(pGdiNode->Gdi.hMemDC,0,0,iWidth2,iHeight2,hDDC,iWidth1,iHeight1,SRCCOPY);
//將DDB轉(zhuǎn)化成DIB
// 得到區(qū)域位圖信息
GetObject(pGdiNode->Gdi.hDIBitmap,sizeof(BITMAP),&(pGdiNode->Gdi.DIBitmap));
// 設(shè)置顏色模式
pGdiNode->Gdi.DIBitmap.bmBitsPixel = bmBitsPixel;
// 初始化位圖信息頭
pGdiNode->Gdi.BMIH.biSize = sizeof(BITMAPINFOHEADER);
pGdiNode->Gdi.BMIH.biWidth = pGdiNode->Gdi.DIBitmap.bmWidth;
pGdiNode->Gdi.BMIH.biHeight = pGdiNode->Gdi.DIBitmap.bmHeight;
pGdiNode->Gdi.BMIH.biPlanes = 1;
pGdiNode->Gdi.BMIH.biBitCount = (WORD)pGdiNode->Gdi.DIBitmap.bmPlanes * (WORD)pGdiNode->Gdi.DIBitmap.bmBitsPixel;
pGdiNode->Gdi.BMIH.biCompression = BI_RGB;
pGdiNode->Gdi.BMIH.biSizeImage = 0;
pGdiNode->Gdi.BMIH.biXPelsPerMeter = 0;
pGdiNode->Gdi.BMIH.biYPelsPerMeter = 0;
pGdiNode->Gdi.BMIH.biClrUsed = 0;
pGdiNode->Gdi.BMIH.biClrImportant = 0;
//設(shè)置區(qū)域的顏色數(shù)
pGdiNode->Gdi.nColors = 1 << pGdiNode->Gdi.BMIH.biBitCount;
if (pGdiNode->Gdi.nColors > 256)
pGdiNode->Gdi.nColors = 0;
// 計(jì)算為位圖信息頭和彩色表分配內(nèi)存所需的尺寸
pGdiNode->Gdi.dwLen = (DWORD)(sizeof(BITMAPINFOHEADER) + pGdiNode->Gdi.nColors * sizeof(RGBQUAD));
if (!pGdiNode->Gdi.fDIBitmap)
{
pGdiNode->Gdi.pDIB = (char *)malloc(pGdiNode->Gdi.dwLen);
pStartDIB = pGdiNode->Gdi.pDIB;
}
pGdiNode->Gdi.lpBMIH = (LPBMIH)pGdiNode->Gdi.pDIB;
*(pGdiNode->Gdi.lpBMIH) = pGdiNode->Gdi.BMIH;
GetDIBits(hNullDC,pGdiNode->Gdi.hDIBitmap,0L,(DWORD)pGdiNode->Gdi.BMIH.biHeight,(LPBYTE)NULL,(LPBITMAPINFO)pGdiNode->Gdi.lpBMIH,DIB_RGB_COLORS);
// 以計(jì)算的尺寸設(shè)置區(qū)域位圖信息頭
pGdiNode->Gdi.BMIH = *(pGdiNode->Gdi.lpBMIH);
// 保存位圖信息頭的大小
pGdiNode->Gdi.dwBitMapHeader = pGdiNode->Gdi.dwLen;
pGdiNode->Gdi.dwLen += (DWORD)(pGdiNode->Gdi.BMIH.biSizeImage);
if (!pGdiNode->Gdi.fDIBitmap)
{
pGdiNode->Gdi.pDIB = pStartDIB;
pGdiNode->Gdi.pDIB = (char *)realloc(pGdiNode->Gdi.pDIB,pGdiNode->Gdi.dwLen);
}
pGdiNode->Gdi.lpBMIH = (LPBMIH)pGdiNode->Gdi.pDIB;
bGotBits = GetDIBits(hNullDC,pGdiNode->Gdi.hDIBitmap,0L,(DWORD)pGdiNode->Gdi.BMIH.biHeight,(LPBYTE)pGdiNode->Gdi.lpBMIH + (pGdiNode->Gdi.BMIH.biSize + pGdiNode->Gdi.nColors * sizeof(RGBQUAD)),(LPBITMAPINFO)pGdiNode->Gdi.lpBMIH,DIB_RGB_COLORS);
// 比較區(qū)域DIBS之前和之后的變化
if (pGdiNode->Gdi.fDIBitmap)
{
dwLen1 = pGdiNode->Gdi.dwLen;
dwBitMapHeader1 = pGdiNode->Gdi.dwBitMapHeader;
pDIBitmap1 = pGdiNode->Gdi.pDIBitmap;
pDIB1 = pGdiNode->Gdi.pDIB;
fChange1 = pGdiNode->Gdi.fChange;
// 每次4個(gè)字節(jié)的比較兩副位圖,注意要跳過位圖的頭部
__asm
{
MOV ECX,dwLen1
SUB ECX,dwBitMapHeader1
SHR ECX,2
MOV EDX,dwBitMapHeader1
MOV ESI,pDIBitmap1
ADD ESI,EDX
MOV EDI,pDIB1
ADD EDI,EDX
REP CMPSD
JNZ SetFlagRegion1
MOV fChange1,FALSE
JMP ExitRegion1
SetFlagRegion1:
MOV fChange1,TRUE
ExitRegion1:
}
//設(shè)置變化狀態(tài)
pGdiNode->Gdi.fChange = fChange1;
// 為兩副區(qū)域DIB的差別建立一個(gè)新的DIB
if (pGdiNode->Gdi.fChange)
{
DWORD iZeros = 0;
iLength = (pGdiNode->Gdi.dwLen - pGdiNode->Gdi.dwBitMapHeader);
pGdiNode->Gdi.pDIBChange = pGdiNode->Gdi.pDIBChangeStart;
pDIBChange1 = pGdiNode->Gdi.pDIBChange;
__asm
{
MOV ECX,iLength
SHR ECX,2
MOV EDI,pDIBChange1
MOV ESI,pDIB1
ADD ESI,dwBitMapHeader1
MOV EDX,pDIBitmap1
ADD EDX,dwBitMapHeader1
SubtractRegion:
LODSD
SUB EAX,[EDX]
ADD EDX,4
STOSD
DEC ECX
JNZ SubtractRegion
}
//拷貝到全局區(qū)域的DIB
memblast(pGdiNode->Gdi.pDIBitmap,pGdiNode->Gdi.pDIB,pGdiNode->Gdi.dwLen);
// 設(shè)置壓縮長度
pGdiNode->Gdi.dwCompress = pGdiNode->Gdi.dwLen - pGdiNode->Gdi.dwBitMapHeader;
// 設(shè)置數(shù)據(jù)的起始位
pGdiNode->Gdi.iStartPos = pGdiNode->Gdi.dwBitMapHeader;
}
}
else
{
iLength = (pGdiNode->Gdi.dwLen);
pGdiNode->Gdi.pDIBitmap = (char *)malloc(iLength);
pGdiNode->Gdi.pDIBChange = (char *)malloc(iLength);
pGdiNode->Gdi.pDIBChangeStart = pGdiNode->Gdi.pDIBChange;
memblast(pGdiNode->Gdi.pDIBitmap,pGdiNode->Gdi.pDIB,pGdiNode->Gdi.dwLen);
memblast(pGdiNode->Gdi.pDIBChange,pGdiNode->Gdi.pDIB,pGdiNode->Gdi.dwLen);
// 不需要再分配內(nèi)存
pGdiNode->Gdi.fDIBitmap = TRUE;
pGdiNode->Gdi.fChange = TRUE;
pGdiNode->Gdi.dwCompress = pGdiNode->Gdi.dwLen;
pGdiNode->Gdi.iStartPos = 0;
}
return pGdiNode->Gdi.fChange;
}
// 發(fā)送Resolution到客戶端
void SendResolution(SOCKET MySocket)
{
char szMessage[81];
DWORD iSent,iRecv;
// 建立屏幕寬度
memset(szMessage,'\0',sizeof(szMessage));
sprintf(szMessage,"%d",iWidth);
iSent = Transmit(MySocket,szMessage,strlen(szMessage));
// 接收確認(rèn)
memset(szMessage,'\0',sizeof(szMessage));
iRecv = recv(MySocket,szMessage,81,0);
szMessage[iRecv] = '\0';
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -