RCAClient.cpp
上传用户:hyz2004817
上传日期:2022-03-30
资源大小:226k
文件大小:19k
- // RCAClient.cpp : 定义控制台应用程序的入口点。
- //
- #include "stdafx.h"
- #include "resource.h"
- typedef enum _ThreadWorkState
- {
- UNINIT =0,
- WAIT_CONNECT,
- WAIT_REQUEST,
- CONNECTING,
- REQUESTING,
- } THREAD_WORK_STATE;
- typedef struct _ThreadCommun {
- HANDLE hExitEvent;
- HANDLE hBeginConnectEvent;
- HANDLE hBeginRequest;
- HWND hwnd;
- UINT msg;
- } THREAD_COMMUN, *PTHREAD_COMMUN;
- HWND g_hWnd;
- HINSTANCE g_hInstance;
- HIMAGELIST g_hImageList;
- SOCKET g_hSocket1 = NULL;
- SOCKET g_hSocket2 = NULL;
- sockaddr_in g_addr;
- sockaddr_in g_addr2;
- HANDLE g_hThread1 = NULL;
- HANDLE g_hThread2 = NULL;
- HANDLE g_hEvent1;
- HANDLE g_hEvent2;
- HBITMAP g_hRemoteBitmap = NULL;
- THREAD_COMMUN g_tc;
- THREAD_WORK_STATE g_ThreadState = UNINIT;
- RCAGETIMAGEDATA g_gm;
- BOOL g_bMustExit = FALSE;
- DWORD g_dwServerIP = 0;
- u_short g_usPort = 0;
- INT g_hWidth;
- INT g_hHeight;
- // 主窗口的子窗口标识符
- #define ID_TOOLBAR 1 // 工具栏窗口
- #define WM_THREADWORKSTATE (WM_USER+100)
- #define CANNOT_WAIT 0
- #define CANNOT_CREATESOCKET 1
- #define CANNOT_CONNECT 2
- #define CANNOT_REQUEST 3
- #define RESPONSE_ERROR 4
- #define WORK_SUCCEEDED 5
- #define CONNECTED 6
- INT WINAPI AddToolbarString( HWND tb, char * string )
- {
- char tmp[256];
- lstrcpy( tmp, string );
- tmp[ lstrlen(string) +1 ] = 0;
- return (INT)SendMessage( tb, TB_ADDSTRING, 0, (LPARAM)(LPSTR)tmp );
- }
- /////////////////////////////////////////////////////
- ///
- // 获取远程计算机图象函数, 由 创建的一个工作线程运行
- //
- DWORD WINAPI ThreadFunc1( PVOID p )
- {
-
- DWORD dwret;
- RCAREQUESTHEADER rreqh;
- RCAGETIMAGEDATA gm;
- RECT rect;
- PTHREAD_COMMUN ptc = (PTHREAD_COMMUN)p;
- HANDLE hEventArray[2] = { NULL, ptc->hExitEvent };
- HANDLE hWaitConnectArray[2] = { ptc->hBeginConnectEvent, ptc->hExitEvent };
- HANDLE hWaitRequestArray[3] = { ptc->hBeginRequest, ptc->hExitEvent, ptc->hBeginConnectEvent };
-
- InitRCARequestHead( &rreqh, 1, 0, 0X20, sizeof(rreqh) + sizeof(gm) );
- rreqh.wMajorVersion = 1;
- rreqh.wMinorVersion = 0;
- gm.x = 0;
- gm.y = 0;
- gm.w = 0;
- gm.h = 0;
- gm.zh = 0;
- gm.zw = 0;
- gm.iBitCount = 8;
- gm.dwFlagEx1 = 50; // 图象质量
- gm.dwImageFormat = IMAGE_FORMAT_JPEG;
-
- g_gm.dwImageFormat = IMAGE_FORMAT_JPEG;
- g_gm.iBitCount = 8;
- g_gm.dwFlagEx1 = 50;
-
- while(1)
- {
- // 线程进入等待, 准备连接服务器
- g_ThreadState = WAIT_CONNECT;
- dwret = WaitForMultipleObjects( 2, hWaitConnectArray, FALSE, INFINITE );
- g_ThreadState = CONNECTING;
-
- if( dwret == (WAIT_OBJECT_0 +1))
- {
- return 0;
- }
- if( dwret == WAIT_FAILED)
- {
- PostMessage( ptc->hwnd, ptc->msg, CANNOT_WAIT, 0 );
- g_ThreadState = UNINIT;
- return 0;
- }
- ///////////////////////////////////////////////////////////
- if( !CreateEventSelectSocket( &g_hSocket1, &(hEventArray[0]),
- FD_CONNECT | FD_WRITE | FD_READ | FD_CLOSE ) )
- {
- PostMessage( ptc->hwnd, ptc->msg, CANNOT_CREATESOCKET, 0 );
- continue;
- }
-
- g_addr.sin_addr.S_un.S_addr = g_dwServerIP;
- g_addr.sin_family = AF_INET;
- g_addr.sin_port = g_usPort;
- if( TRUE != RCAConnect_EventSelectIO( g_hSocket1, hEventArray,
- (sockaddr*)&g_addr, sizeof(sockaddr) ) )
- {
- CloseHandle( g_hEvent1 );
- closesocket( g_hSocket1 );
- PostMessage( ptc->hwnd, ptc->msg, CANNOT_CONNECT, 0 );
- continue;
- }
-
- PostMessage( ptc->hwnd, ptc->msg, CONNECTED , 0 );
- ////////////////////////////
- // 请求开始
- while(1)
- {
- g_ThreadState = WAIT_REQUEST;
- dwret = WaitForMultipleObjects( 3, hWaitRequestArray, FALSE, INFINITE );
- g_ThreadState = REQUESTING;
- if( dwret != (WAIT_OBJECT_0 ) )
- {
- if( dwret == (WAIT_OBJECT_0 +1) )
- {
- break;
- } else if( dwret == (WAIT_OBJECT_0 +2 ))
- {
- break;
- } else if( dwret == WAIT_FAILED )
- {
- PostMessage(ptc->hwnd, ptc->msg, CANNOT_WAIT, 0 );
- break;
- }
- // never run to here
- }
- GetClientRect( ptc->hwnd, &rect );
- gm.zw = rect.right;
- gm.zh = rect.bottom;
-
- gm.dwFlagEx1 = g_gm.dwFlagEx1;
- gm.dwImageFormat = g_gm.dwImageFormat;
- gm.iBitCount = g_gm.iBitCount;
- // now dwret==WAIT_OBJECT, start request server
- if( TRUE != RCASendRequest_0X20_EventSelectIO( g_hSocket1, hEventArray,
- &gm ) )
- {
- PostMessage(ptc->hwnd, ptc->msg, CANNOT_REQUEST, 0 );
- break;
- }
-
- HBITMAP bm = RCARecvImageData( g_hSocket1, hEventArray, gm.dwImageFormat );
- if( bm == NULL )
- {
- PostMessage( ptc->hwnd, ptc->msg, CANNOT_REQUEST, 0 );
- break;
- }
-
- PostMessage( ptc->hwnd, ptc->msg, WORK_SUCCEEDED, (LPARAM)bm );
- }
- if( g_bMustExit )
- break;
- else
- {
- closesocket( g_hSocket1 );
- CloseHandle( hEventArray[0] );
- }
- }
- closesocket( g_hSocket1 );
- CloseHandle( hEventArray[0] );
- return 0;
- }
- DWORD WINAPI ThreadFunc2( PVOID p )
- {
- while(1)
- {
- SuspendThread( GetCurrentThread());
- }
- return 0;
- }
- VOID WINAPI OnPaint( HWND hwnd, HDC hdc )
- {
-
- if( g_hRemoteBitmap )
- {
-
- DIBSECTION ds;
- RECT rect;
- GetClientRect( hwnd, &rect );
- GetObject( g_hRemoteBitmap, sizeof(ds), (LPVOID)&ds );
-
- HDC hdcmem = CreateCompatibleDC(hdc);
- SelectObject( hdcmem, g_hRemoteBitmap );
- StretchBlt( hdc, 0, 0, rect.right, rect.bottom,
- hdcmem, 0, 0, ds.dsBm.bmWidth, ds.dsBm.bmHeight, SRCCOPY );
- SelectObject( hdcmem, (HBITMAP)NULL );
- DeleteDC( hdcmem );
- }
- }
- VOID WINAPI OnThreadWorkState( HWND hwnd, WPARAM w, LPARAM l )
- {
- switch( w )
- {
- case WORK_SUCCEEDED:
-
- if(g_hRemoteBitmap != NULL )
- DeleteObject( g_hRemoteBitmap );
- g_hRemoteBitmap = (HBITMAP)l;
-
- InvalidateRect( hwnd, NULL, FALSE );
- break;
- }
- return;
- }
- BOOL WINAPI InitWorkThread( HWND hwnd )
- {
- // 确保 WIN98 的支持
- DWORD tmp;
- g_tc.hBeginConnectEvent = CreateEvent( NULL, FALSE, FALSE, NULL );
- g_tc.hBeginRequest = CreateEvent( NULL, FALSE, FALSE, NULL );
- g_tc.hExitEvent = CreateEvent( NULL, FALSE, FALSE, NULL );
- g_tc.hwnd = hwnd;
- g_tc.msg = WM_THREADWORKSTATE;
- g_hRemoteBitmap = NULL;
- g_hThread1 = CreateThread( NULL, 0, ThreadFunc1, (LPVOID)&g_tc, 0, &tmp );
-
- if( g_hThread1 != NULL )
- return TRUE;
- return TRUE;
- }
- VOID WINAPI DestroyWorkThreadResource()
- {
- if( g_ThreadState == UNINIT )
- return;
- // 通知线程退出;
- SetEvent( g_tc.hExitEvent );
- if( g_hSocket2 != NULL )
- closesocket( g_hSocket2 );
- if( g_hThread1 )
- {
-
- if ( WAIT_TIMEOUT == WaitForSingleObject( g_hThread1, 3000 ) )
- TerminateThread( g_hThread1, 0);
- CloseHandle( g_hThread1 );
- g_hThread1 = NULL;
- }
- // 关闭用于通信的所有事件句柄
- CloseHandle( g_tc.hBeginConnectEvent );
- CloseHandle( g_tc.hBeginRequest );
- CloseHandle( g_tc.hExitEvent );
- if( g_hRemoteBitmap )
- {
- DeleteObject( g_hRemoteBitmap );
- g_hRemoteBitmap = NULL;
- }
- }
- BOOL WINAPI OnCreate( HWND hwnd, PAINTSTRUCT * pps )
- {
- WSADATA data;
- if( SOCKET_ERROR == WSAStartup( MAKEWORD(2,2), &data ) )
- return FALSE;
- INITCOMMONCONTROLSEX icex;
- icex.dwSize = sizeof(icex);
- icex.dwICC = ICC_WIN95_CLASSES;
- if( !InitWorkThread( hwnd) )
- return FALSE;
- return TRUE;
- }
- VOID WINAPI OnDestroy()
- {
- WSACleanup();
- DestroyWorkThreadResource();
- }
- BOOL CALLBACK ConnectDialogProc( HWND dlg, UINT msg, WPARAM w, LPARAM l )
- {
- char str[256];
- int ret;
- switch( msg )
- {
- case WM_INITDIALOG:
- SetFocus( GetDlgItem( dlg, IDC_SERVERNAME ) );
- return TRUE;
- case WM_COMMAND:
- switch( w )
- {
- case IDOK:
- GetWindowText( GetDlgItem(dlg, IDC_SERVERNAME), str, 255 );
- g_dwServerIP = inet_addr( str );
-
- GetWindowText( GetDlgItem( dlg, IDC_PORT), str, 255 );
- g_usPort = htons( atoi(str));
- if( g_ThreadState == WAIT_CONNECT )
- {
- g_addr2.sin_addr.S_un.S_addr = g_dwServerIP;
- g_addr2.sin_family = AF_INET;
- g_addr2.sin_port = g_usPort;
- g_hSocket2 = socket( AF_INET, SOCK_STREAM, 0 );
- if( g_hSocket2 == INVALID_SOCKET )
- {
- MessageBox( dlg, "资源不足, 无法创建套接字", "RCA Client Error" , MB_ICONERROR );
- g_hSocket2 = NULL;
- return TRUE;
- }
- if( g_ThreadState == WAIT_CONNECT )
- SetEvent( g_tc.hBeginConnectEvent );
- ret = connect( g_hSocket2, (sockaddr*)&g_addr2, sizeof(sockaddr) );
- if( ret == SOCKET_ERROR )
- {
- MessageBox( dlg, WSAERRORSTRING, "RCA Client Error", MB_ICONERROR );
- closesocket( g_hSocket2 );
- g_hSocket2 = NULL;
- return TRUE;
- }
-
- MSG msg;
- while(1)
- {
- GetMessage( &msg, NULL, NULL, NULL );
- if( (msg.hwnd == g_hWnd) && (msg.message==WM_THREADWORKSTATE))
- {
- if( msg.wParam != CONNECTED )
- {
- MessageBox( dlg, WSAERRORSTRING, "RCA Client Error", MB_ICONERROR );
- return FALSE;
- }
- {
- EndDialog( dlg, TRUE );
- return TRUE;
- }
- }
- else
- {
- TranslateMessage( &msg );
- DispatchMessage( &msg );
- }
- }
- if( g_ThreadState == WAIT_REQUEST )
- {
- EndDialog( dlg, TRUE );
- }
- }
- return TRUE;
- break;
- case IDCANCEL:
- EndDialog( dlg, FALSE );
- return TRUE;
- default:
- break;
- }
- default:
- return FALSE;
- }
- return FALSE;
- }
- VOID WINAPI OnCommand( HWND hwnd, WPARAM w, LPARAM l )
- {
- // 筛选命令 ID
- switch( w )
- {
- case ID_EXIT:
- if ( g_ThreadState == CONNECTING)
- {
- if( IDOK == MessageBox( hwnd, "正在获取远程计算机屏幕信息, 是否要中断连接 ?"
- , "RCA Client", MB_ICONQUESTION | MB_OKCANCEL ) )
- DestroyWindow( hwnd );
- }
- else
- {
- g_bMustExit = TRUE;
- DestroyWindow( hwnd );
- }
- break;
- case ID_CONNECT:
- //if( false )
- if( FALSE == DialogBox( g_hInstance, MAKEINTRESOURCE(IDD_CONNECTDIALOG),
- g_hWnd, ConnectDialogProc ) )
- {
- return;
- } else {
-
- // 设置 UI
-
- EnableMenuItem( GetMenu(hwnd), ID_DISCONNECT, MF_ENABLED);
- EnableMenuItem( GetMenu(hwnd), ID_CONNECT, MF_GRAYED | MF_DISABLED);
- EnableMenuItem( GetMenu(hwnd), ID_REFRUSH, MF_ENABLED );
-
- }
- break;
-
- case ID_IMAGE_FORMAT_BMP:
- CheckMenuItem( GetMenu(hwnd), ID_IMAGE_FORMAT_BMP , MF_CHECKED );
- CheckMenuItem( GetMenu(hwnd), ID_IMAGE_FORMAT_JPEG, MF_UNCHECKED );
- g_gm.dwImageFormat = IMAGE_FORMAT_BMP;
- return;
- case ID_IMAGE_FORMAT_JPEG:
- CheckMenuItem( GetMenu(hwnd), ID_IMAGE_FORMAT_JPEG , MF_CHECKED );
- CheckMenuItem( GetMenu(hwnd), ID_IMAGE_FORMAT_BMP, MF_UNCHECKED );
- g_gm.dwImageFormat = IMAGE_FORMAT_JPEG;
- return;
- case ID_BIT_8:
- CheckMenuItem( GetMenu(hwnd), ID_BIT_8, MF_CHECKED );
- CheckMenuItem( GetMenu(hwnd), ID_BIT_16, MF_UNCHECKED );
- CheckMenuItem( GetMenu(hwnd), ID_BIT_24, MF_UNCHECKED );
- g_gm.iBitCount = 8;
- return;
- case ID_BIT_16:
- CheckMenuItem( GetMenu(hwnd), ID_BIT_8, MF_UNCHECKED );
- CheckMenuItem( GetMenu(hwnd), ID_BIT_16, MF_CHECKED );
- CheckMenuItem( GetMenu(hwnd), ID_BIT_24, MF_UNCHECKED );
- g_gm.iBitCount = 16;
- return;
- case ID_BIT_24:
- CheckMenuItem( GetMenu(hwnd), ID_BIT_8, MF_UNCHECKED );
- CheckMenuItem( GetMenu(hwnd), ID_BIT_16, MF_UNCHECKED );
- CheckMenuItem( GetMenu(hwnd), ID_BIT_24, MF_CHECKED );
- g_gm.iBitCount = 24;
- return;
- case ID_JPEG_QUALITY_10:
- CheckMenuItem( GetMenu(hwnd), ID_JPEG_QUALITY_10, MF_CHECKED );
- CheckMenuItem( GetMenu(hwnd), ID_JPEG_QUALITY_30, MF_UNCHECKED );
- CheckMenuItem( GetMenu(hwnd), ID_JPEG_QUALITY_50, MF_UNCHECKED );
- CheckMenuItem( GetMenu(hwnd), ID_JPEG_QUALITY_70, MF_UNCHECKED );
- CheckMenuItem( GetMenu(hwnd), ID_JPEG_QUALITY_90, MF_UNCHECKED );
- g_gm.dwFlagEx1 = 10;
- return;
- case ID_JPEG_QUALITY_30:
- CheckMenuItem( GetMenu(hwnd), ID_JPEG_QUALITY_10, MF_UNCHECKED );
- CheckMenuItem( GetMenu(hwnd), ID_JPEG_QUALITY_30, MF_CHECKED );
- CheckMenuItem( GetMenu(hwnd), ID_JPEG_QUALITY_50, MF_UNCHECKED );
- CheckMenuItem( GetMenu(hwnd), ID_JPEG_QUALITY_70, MF_UNCHECKED );
- CheckMenuItem( GetMenu(hwnd), ID_JPEG_QUALITY_90, MF_UNCHECKED );
- g_gm.dwFlagEx1 = 30;
- return;
- case ID_JPEG_QUALITY_50:
- CheckMenuItem( GetMenu(hwnd), ID_JPEG_QUALITY_10, MF_UNCHECKED );
- CheckMenuItem( GetMenu(hwnd), ID_JPEG_QUALITY_30, MF_UNCHECKED );
- CheckMenuItem( GetMenu(hwnd), ID_JPEG_QUALITY_50, MF_CHECKED );
- CheckMenuItem( GetMenu(hwnd), ID_JPEG_QUALITY_70, MF_UNCHECKED );
- CheckMenuItem( GetMenu(hwnd), ID_JPEG_QUALITY_90, MF_UNCHECKED );
- g_gm.dwFlagEx1 = 50;
- return;
- case ID_JPEG_QUALITY_70:
- CheckMenuItem( GetMenu(hwnd), ID_JPEG_QUALITY_10, MF_UNCHECKED );
- CheckMenuItem( GetMenu(hwnd), ID_JPEG_QUALITY_30, MF_UNCHECKED );
- CheckMenuItem( GetMenu(hwnd), ID_JPEG_QUALITY_50, MF_UNCHECKED );
- CheckMenuItem( GetMenu(hwnd), ID_JPEG_QUALITY_70, MF_CHECKED );
- CheckMenuItem( GetMenu(hwnd), ID_JPEG_QUALITY_90, MF_UNCHECKED );
- g_gm.dwFlagEx1 = 70;
- return;
- case ID_JPEG_QUALITY_90:
- CheckMenuItem( GetMenu(hwnd), ID_JPEG_QUALITY_10, MF_UNCHECKED );
- CheckMenuItem( GetMenu(hwnd), ID_JPEG_QUALITY_30, MF_UNCHECKED );
- CheckMenuItem( GetMenu(hwnd), ID_JPEG_QUALITY_50, MF_UNCHECKED );
- CheckMenuItem( GetMenu(hwnd), ID_JPEG_QUALITY_70, MF_UNCHECKED );
- CheckMenuItem( GetMenu(hwnd), ID_JPEG_QUALITY_90, MF_CHECKED );
- g_gm.dwFlagEx1 = 90;
- return;
- case ID_REFRUSH:
- if( g_ThreadState == WAIT_REQUEST )
- SetEvent( g_tc.hBeginRequest );
- break;
- case ID_DISCONNECT:
- EnableMenuItem( GetMenu(hwnd), ID_CONNECT, MF_ENABLED );
- EnableMenuItem( GetMenu(hwnd), ID_DISCONNECT, MF_DISABLED | MF_GRAYED );
- EnableMenuItem( GetMenu(hwnd), ID_REFRUSH, MF_DISABLED | MF_GRAYED );
- if( g_ThreadState == WAIT_REQUEST )
- {
- SetEvent( g_tc.hBeginConnectEvent );
- }
- if( g_ThreadState == REQUESTING )
- {
- SetEvent( g_tc.hExitEvent );
- }
- closesocket( g_hSocket2 );
- g_hSocket2 = NULL;
-
- break;
- default:
- break;
- }
- return;
- }
- RCAMOUSEINPUT mi;
- RCAKEYBDINPUT ki;
- RCAREQUESTHEADER rreqh;
- LRESULT CALLBACK MainWindowProc( HWND hwnd, UINT msg, WPARAM w, LPARAM l )
- {
- PAINTSTRUCT ps;
- HDC hdc;
- RECT rect;
- INT ret;
- GetClientRect( hwnd, &rect );
-
- static UINT_PTR timer;
-
- switch( msg )
- {
- case WM_RBUTTONDOWN:
- if( g_hSocket2 )
- {
- mi.dwExtraInfo =0;
- mi.dwFlags = MOUSEEVENTF_RIGHTDOWN;
- //mi.dx = (lParam&0x0000ffff) * (65535 / 1024);
- //mi.dy = (lParam>>16) * (65535 / 768);
- mi.mouseData = 0;
- mi.time = 0;
- rreqh.dwRequestID = 0x40;
- rreqh.requestBytes = sizeof(RCAREQUESTHEADER) + sizeof(RCAMOUSEINPUT);
- ret = send(g_hSocket2, (char*)&rreqh, sizeof(rreqh), 0 );
- if( ret == SOCKET_ERROR )
- return FALSE;
- ret = send(g_hSocket2, (char*)&mi, sizeof(mi), 0 );
- if( ret == SOCKET_ERROR )
- return FALSE;
- }
- return TRUE;
- case WM_RBUTTONUP:
- if( g_hSocket2 )
- {
- mi.dwExtraInfo =0;
- mi.dwFlags = MOUSEEVENTF_RIGHTUP;
- //mi.dx = (lParam&0x0000ffff) * (65535 / 1024);
- //mi.dy = (lParam>>16) * (65535 / 768);
- mi.mouseData = 0;
- mi.time = 0;
- rreqh.dwRequestID = 0x40;
- rreqh.requestBytes = sizeof(RCAREQUESTHEADER) + sizeof(RCAMOUSEINPUT);
- ret = send(g_hSocket2, (char*)&rreqh, sizeof(rreqh), 0 );
- if( ret == SOCKET_ERROR )
- return FALSE;
- ret = send(g_hSocket2, (char*)&mi, sizeof(mi), 0 );
- if( ret == SOCKET_ERROR )
- return FALSE;
- }
- return TRUE;
- case WM_LBUTTONUP:
- if( g_hSocket2 )
- {
- mi.dwExtraInfo =0;
- mi.dwFlags = MOUSEEVENTF_LEFTUP;
- // mi.dx = (lParam&0x0000ffff) * (65535 / 1024);
- // mi.dy = (lParam>>16) * (65535 / 768);
- mi.mouseData = 0;
- mi.time = 0;
- rreqh.dwRequestID = 0x40;
- rreqh.requestBytes = sizeof(RCAREQUESTHEADER) + sizeof(RCAMOUSEINPUT);
- ret = send(g_hSocket2, (char*)&rreqh, sizeof(rreqh), 0 );
- if( ret == SOCKET_ERROR )
- return FALSE;
- ret = send(g_hSocket2, (char*)&mi, sizeof(mi), 0 );
- if( ret == SOCKET_ERROR )
- return FALSE;
- }
- return TRUE;
- case WM_LBUTTONDOWN:
- if( g_hSocket2 )
- {
- mi.dwExtraInfo =0;
- mi.dwFlags = MOUSEEVENTF_LEFTDOWN;
- // mi.dx = (lParam&0x0000ffff) * (65535 / 1024);
- // mi.dy = (lParam>>16) * (65535 / 768);
- mi.mouseData = 0;
- mi.time = 0;
- rreqh.dwRequestID = 0x40;
- rreqh.requestBytes = sizeof(RCAREQUESTHEADER) + sizeof(RCAMOUSEINPUT);
- ret = send(g_hSocket2, (char*)&rreqh, sizeof(rreqh), 0 );
- if( ret == SOCKET_ERROR )
- return FALSE;
- ret = send(g_hSocket2, (char*)&mi, sizeof(mi), 0 );
- if( ret == SOCKET_ERROR )
- return FALSE;
-
- }
- return TRUE;
- case WM_MOUSEMOVE:
- if( g_hSocket2 )
- {
- mi.dwFlags = MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_MOVE;
- mi.dx = (LONG)(l & 0x0000ffff) * 65535 / rect.right;
- mi.dy = (LONG)(l >> 16) * 65535 / rect.bottom;
- rreqh.dwRequestID = 0x40;
- rreqh.requestBytes = 64;
- ret = send(g_hSocket2, (char*)&rreqh, sizeof(rreqh), 0 );
- if( ret == SOCKET_ERROR )
- {
- MessageBox( hwnd, "网络连接出现问题或 RCA 服务器已经被关闭", "RCA Client Information", MB_ICONINFORMATION );
- PostMessage( hwnd, WM_COMMAND, ID_DISCONNECT, 0 );
- return FALSE;
- }
- ret = send(g_hSocket2, (char*)&mi, sizeof(mi), 0 );
- if( ret == SOCKET_ERROR )
- return FALSE;
- }
- break;
- case WM_KEYDOWN:
- if( (w==VK_F5) && (g_ThreadState==WAIT_REQUEST) )
- SetEvent( g_tc.hBeginRequest );
-
- if( (w==VK_RWIN) || (w==VK_LWIN) )
- break;
-
- break;
- case WM_THREADWORKSTATE:
- OnThreadWorkState( hwnd, w, l );
- return 0;
- case WM_COMMAND:
- OnCommand( hwnd, w, l );
- return 0;
- case WM_TIMER:
- if( g_ThreadState != WAIT_CONNECT )
- PostMessage(hwnd, WM_COMMAND, ID_DISCONNECT , NULL );
- DestroyWindow( hwnd );
- KillTimer( hwnd, timer );
- return TRUE;
- case WM_CREATE:
- mi.dwExtraInfo =0;
- mi.mouseData = 0;
- mi.time = 0;
- lstrcpy(rreqh.rcaID, "RCA" );
- rreqh.wMajorVersion =1;
- rreqh.wMinorVersion =0;
- timer = SetTimer(hwnd, 1, 10 * 60 * 1000, NULL );
- return OnCreate( hwnd, (PAINTSTRUCT*)l );
-
-
- g_gm.dwImageFormat = IMAGE_FORMAT_JPEG;
- g_gm.iBitCount = 8;
- g_gm.dwFlagEx1 = 50;
- break;
- case WM_SIZE:
- SendMessage( GetDlgItem( hwnd, ID_TOOLBAR ), TB_AUTOSIZE, 0, 0 );
- break;
- case WM_PAINT:
- hdc = BeginPaint( hwnd, &ps );
- OnPaint( hwnd, hdc );
- EndPaint( hwnd, &ps );
- break;
- case WM_DESTROY:
- g_bMustExit = TRUE;
- OnDestroy();
- PostQuitMessage(0);
- break;
- default:
- break;
- }
- return DefWindowProc( hwnd, msg, w, l );
- }
- INT WINAPI WinMain( HINSTANCE, HINSTANCE, PSTR, INT )
- //int main(int argc, char* argv[])
- {
- g_hInstance = GetModuleHandle( NULL );
- WNDCLASSEX wcex;
- wcex.cbClsExtra = 0;
- wcex.cbSize = sizeof(wcex);
- wcex.cbWndExtra = 0;
- wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW +1);
- wcex.hCursor = LoadCursor( NULL, IDC_ARROW );
- wcex.hIcon = LoadIcon( g_hInstance, MAKEINTRESOURCE(IDI_CLIENTICON) );
- wcex.hIconSm = LoadIcon( g_hInstance, MAKEINTRESOURCE(IDI_CLIENTICON) );
- wcex.hInstance = g_hInstance;
- wcex.lpfnWndProc = MainWindowProc;
- wcex.lpszMenuName = NULL;
- wcex.lpszClassName = "RCAClient_Window";
- wcex.style = CS_VREDRAW | CS_HREDRAW;
- if( !RegisterClassEx( &wcex ) )
- return FALSE;
- g_hWnd = CreateWindowEx( 0, "RCAClient_Window", "RCA Client", WS_OVERLAPPEDWINDOW,
- CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
- NULL, LoadMenu( g_hInstance, MAKEINTRESOURCE(IDR_MENU1) ),
- g_hInstance, NULL );
- if( !g_hWnd )
- return 0;
- ShowWindow( g_hWnd, SW_SHOWNORMAL );
- UpdateWindow( g_hWnd );
- MSG msg;
- while( GetMessage( &msg, NULL, 0, 0 ) )
- {
- TranslateMessage( &msg );
- DispatchMessage( &msg );
- }
- return 0;
- }