Ejemplo n.º 1
0
//-------------------------------------------------------------------------------
void TresholdsViewBtn(HWND h)
{
	zprint("");
	DetailedWindow::Open();
	thicknessViewer.openDetailedWindow = true;
	RepaintWindow(DetailedWindow::Instance().hWnd);
}
void CloseSocket(HWND hWnd, SOCKET clientSocket) {
	shutdown(clientSocket, SD_BOTH);
	closesocket(clientSocket);
	connectionStatus = statusNotConnected;
	RepaintWindow(hWnd);
	Shell_NotifyIcon(NIM_MODIFY, &trayIcon[trayIconNotConnected]);
	EnableMenuItem(GetMenu(hWnd), IDM_DISCONNECT, MF_BYCOMMAND | MF_GRAYED);
	return;
}
SOCKET AcceptSocket(HWND hWnd, SOCKET serverSocket) {
	SOCKET clientSocket;
	SOCKADDR clientSockAddr;
	int clientSockLen;

	clientSockLen = sizeof(clientSockAddr);
	clientSocket = accept(serverSocket, &clientSockAddr, &clientSockLen);
	WSAAsyncSelect(clientSocket, hWnd, 0, 0);
	ULONG nonBlocking = 0;
	ioctlsocket(clientSocket, FIONBIO, &nonBlocking);

	connectionStatus = statusConnected;
	RepaintWindow(hWnd);
	Shell_NotifyIcon(NIM_MODIFY, &trayIcon[trayIconConnected]);
	EnableMenuItem(GetMenu(hWnd), IDM_DISCONNECT, MF_BYCOMMAND | MF_ENABLED);

	ArgList args;
	args.hWnd = hWnd;
	args.socket = clientSocket;
	_beginthread(StreamThread, 0, &args);

	return clientSocket;
}
void StreamThread(void *args) {
	HWND hWnd = ((ArgList *)args)->hWnd;
	SOCKET clientSocket = ((ArgList *)args)->socket;
	static MouseEvent event, prevevent;
	int button;

	int timeout = 5*1000; //ms
	setsockopt(clientSocket, SOL_SOCKET, SO_RCVTIMEO, (const char *)&timeout, sizeof(timeout));

	MouseEvent versionEvent = {htonl(EVENT_VERSION), htonl(kVersionWindowsCurrent), 0, 0};
	send(clientSocket, (const char *)&versionEvent, sizeof(versionEvent), 0);

	while (TRUE) {
		int recvsize = recv(clientSocket, (char *)&event, sizeof(event), 0);
		if (recvsize == sizeof(event)) {
			event.type = ntohl(event.type);
			event.value = ntohl(event.value);
			event.tv_sec = ntohl(event.tv_sec);
			event.tv_nsec = ntohl(event.tv_nsec);

			switch (event.type) {
			case EVENT_MOUSE_DELTA_X:
				break;
			case EVENT_MOUSE_DELTA_Y:
				if (prevevent.type == EVENT_MOUSE_DELTA_X)
					mouse_event(MOUSEEVENTF_MOVE, prevevent.value, event.value, 0, 0);
				break;
			case EVENT_MOUSE_DELTA_W:
				mouse_event( MOUSEEVENTF_HWHEEL, 0, 0, event.value, 0 );
				break;
			case EVENT_MOUSE_DELTA_Z:
				mouse_event( MOUSEEVENTF_WHEEL, 0, 0, -event.value, 0 );
				break;
			case EVENT_MOUSE_DOWN:
				button = MouseNumber(event.value);
				if (button < 0 || kNumButtons <= button)
					button = 0;
				mouse_event(flagButtonDown[button], 0, 0, dataXButton[button], 0 );
				break;
			case EVENT_MOUSE_UP:
				button = MouseNumber(event.value);
				if (button < 0 || kNumButtons <= button)
					button = 0;
				mouse_event(flagButtonUp[button], 0, 0, dataXButton[button], 0 );
				break;
			case EVENT_KEY_DOWN:
				HandleKeyEvent(event);
				break;
			case EVENT_KEY_UP:
				HandleKeyEvent(event);
				break;
			case EVENT_ASCII:
				SimulateKeyWithUnichar(event);
				break;
			default:
				break;
			}
			prevevent = event;

			//sending a ACK packet for the winsock 200ms problem
			MouseEvent nullEvent = {htonl(EVENT_NULL), 0, 0, 0};
			send(clientSocket, (const char *)&nullEvent, sizeof(nullEvent), 0);
		} else if (recvsize == 0) {
			connectionStatus = statusNotConnected;
			break;
		} else if (recvsize == SOCKET_ERROR) {
			int errorno = WSAGetLastError();
			if (errorno == WSAETIMEDOUT) {
				// sending a keep-alive packet
				MouseEvent nullEvent = {htonl(EVENT_NULL), 0, 0, 0};
				send(clientSocket, (const char *)&nullEvent, sizeof(nullEvent), 0);
			} else {
				connectionStatus = errorno;
				break;
			}
		}
	}

	RepaintWindow(hWnd);
	Shell_NotifyIcon(NIM_MODIFY, &trayIcon[trayIconNotConnected]);
	EnableMenuItem(GetMenu(hWnd), IDM_DISCONNECT, MF_BYCOMMAND | MF_GRAYED);

	shutdown(clientSocket, SD_BOTH);
	closesocket(clientSocket);

	_endthread();
	return;
}
Ejemplo n.º 5
0
void
TeamsWindow::UpdateMemoryImage(
     void
) {
     PaintRealWindow          prw(Handle());
     PaintCompatibleWindow    pcw_client(prw.DC());
     PaintCompatibleWindow    pcw_car(prw.DC());
     HPALETTE                 hOldPalette;
     HPALETTE                 hOldPalette2;
     Cursor                   cursor(IDC_WAIT);
     unsigned short           usX;
     unsigned short           usY;
     unsigned short           usTmpX;
     unsigned short           usTmpY;
     unsigned short           usTeamIndex;
     unsigned short           i;

     cursor.Select();
     {
          hOldPalette = SelectPalette(pcw_client.DC(), hPalette, FALSE);
          hOldPalette2 = SelectPalette(pcw_car.DC(), hPalette, FALSE);

          ASSERT(pClientBitmap != NULL);
          pcw_client.SelectBitmap(pClientBitmap);
          ASSERT(pF1CarSmallBitmap != NULL);
          pcw_car.SelectBitmap(pF1CarSmallBitmap);
          {
               RECT           rRect;
               SolidBrush     GrayBrush(RGB(192,192,192));

               rRect.left    = 0;
               rRect.right   = usClientWidth;
               rRect.top     = 0;
               rRect.bottom  = usClientHeight;
               pcw_client.FillRect(&rRect, &GrayBrush);

               usTeamIndex = 0;
               for (usY = 0; usY < TEAMS_NUM_Y; usY++) {
                    for (usX = 0; usX < TEAMS_NUM_X; usX++) {
                         usTmpX = (usX % TEAMS_NUM_X) * usMiniCarWidth;
                         usTmpY = (usY % TEAMS_NUM_Y) * usMiniCarHeight;

                         for (i = 0; i < NUM_ELEMENTS(car_regions); i++) {
                              (void) SelectObject(pcw_car.DC(), car_regions[i].hRgn);
                              SolidBrush  brush(PALETTEINDEX(team_colours[usTeamIndex].usRegionColour[i]));

                              (void) FillRgn(pcw_car.DC(), car_regions[i].hRgn, (HBRUSH) brush.Handle());
                         }

                         BitBlt(   pcw_client.DC(),
                                   usTmpX, usTmpY,
                                   pF1CarSmallBitmap->Width(), pF1CarSmallBitmap->Height(),
                                   pcw_car.DC(),
                                   0, 0,
                                   SRCCOPY
                              );

                         (void) FrameTeam(&pcw_client, usTeamIndex, usTeamIndex == usSelectedTeam);
                         ++usTeamIndex;
                    }
               }
          }
          pcw_client.DeselectBitmap();
          pcw_car.DeselectBitmap();
          (void) SelectPalette(pcw_client.DC(), hOldPalette, FALSE);
          (void) SelectPalette(pcw_car.DC(), hOldPalette2, FALSE);
     }
     cursor.Deselect();

     RepaintWindow();
}