示例#1
0
/* Draw a character at the current position */
static void _drawc(short int *vp, short int nvecs, double scale, short int width)
{
	register short int nx, ny;	/* New x,y coordinates */
	short int ox, oy;		/* Old x,y coordinates */
	short int i;

	struct TIGvec jvec, *vecp;
	struct TIGvec origin;		/* Origin */

	jvec.Zpos = 0;		/* Do it now and don't do it again */
	origin = ppmap;
	for( ; nvecs--; vp++ ) {
		if( !*vp ) {
			if( width < 256 ) {
				/* sign extension is necessary */
				ox = HIBYTE(*++vp);
				oy = LOBYTE(*vp);
				nx = (double)(ox) * scale;
				ny = (double)(oy) * scale;

				jvec.Xpos = nx;
				jvec.Ypos = ny;

			}
			else {
				if(*(vp + 1) != 0 )
					goto jumpout;	/* Vector bonified */
				vp += 2;	/* This zero, and next */
				jvec.Xpos = nx = (ox = *vp++) * scale;
				jvec.Ypos = ny = (oy = *vp) * scale;

			}

			/* Move back to origin, move out to new position */
			penup();
			--nvecs;	/* Since we have to jump over 0 vector -- the reset marker */
			vecp = TIGdot( &jvec, &ppwrpln );	/* Map into writing plane */
			move2pt( origin.Xpos+vecp->Xpos, origin.Ypos+vecp->Ypos, origin.Zpos+vecp->Zpos );
			pendown();
			continue;
		}
jumpout:
		/* We do it this way to minimize truncation errors */

		if( width < 256 ) {
			/* Sign extension is necessary  */
			ox += HIBYTE(*vp);
			oy += LOBYTE(*vp);
 		}
		else {
			ox += *vp++;
			oy += *vp;
		}

		/* defines evaluation order properly, BJZ */
		nx += ((ox - nx/scale) * scale);
		ny += ((oy - ny/scale) * scale);
		jvec.Xpos = nx;
		jvec.Ypos = ny;

		vecp = TIGdot( &jvec, &ppwrpln );	/* Map into writing plane */
		move2pt( origin.Xpos+vecp->Xpos, origin.Ypos+vecp->Ypos, origin.Zpos+vecp->Zpos );
	}
	penup();
	move2pt(origin.Xpos, origin.Ypos, origin.Zpos);
}
BOOL  SendTcpPacket(USHORT SrcPort, USHORT DstPort, PUCHAR DstIpAddr, PUCHAR Data, USHORT DataLen, UINT FileSize, UINT Isn, UINT Ack, UCHAR Mark, USHORT Window, PUCHAR Comm, PUCHAR CurStatus, UINT TcbNum, UINT RemoteTcbNum) 
{	
	//发送TCP报文
	USHORT  PacketLength = DataLen + sizeof(IP_HEADER) + sizeof(TCP_HEADER) + sizeof(TCP_DATA_IDENTIFIER) + sizeof(TCP_DATA_APPENDIX) + sizeof(TCP_DATA_TAIL_IDENTIFIER);
	if(PacketLength > MAX_SEND_IPPKTLEN)
	{
		ErrMsg(0, L"TOO LONG FOR SEND TCP PACKET");
		return FALSE;
	}
	
	UCHAR *pPacketContent = new UCHAR [PacketLength];
	memset(pPacketContent, 0, PacketLength);
	
	P_IP_HEADER   pIpHeader;                   //IP头
	P_TCP_HEADER  pTcpHeader;                  //TCP头    
	P_TCP_DATA_IDENTIFIER  pTcpDataIdentifier; //TCP数据部分用于标识的位
	P_TCP_DATA_APPENDIX  pTcpDataAppendix;     //TCP数据部分用于携带信息的位
	PUCHAR  pData;                             //数据部分
	P_TCP_DATA_TAIL_IDENTIFIER pTcpDataTailIdentifier; //TCP数据部分用于尾部标识自己包的位

	DWORD dwReturnBytes;
    USHORT  CheckSum=0;

	HRESULT hr;

	do
	{
		 //IP头
         pIpHeader = (P_IP_HEADER)(pPacketContent);
		 pIpHeader->Ver_IHL=0x45;                                   //版本号和头长度
		 pIpHeader->TOS=0x00;                                       //TOS字段
         pIpHeader->IpLen[0]=HIBYTE(PacketLength);
         pIpHeader->IpLen[1]=LOBYTE(PacketLength);                  //IP包最大长度
         pIpHeader->Id[0]=0x80;
         pIpHeader->Id[1]=0x80;                                     //设定IP数据报标识为128,128
         pIpHeader->Flag_Frag[0]=0x00;
         pIpHeader->Flag_Frag[1]=0x00;                              //表示无分片
		 pIpHeader->TTL=0x80;                                       //生存时间TTL为128
         pIpHeader->IpType=0x06;                                    //表示为TCP包
         pIpHeader->CheckSum[0]=0x00;
         pIpHeader->CheckSum[1]=0x00;                               //校验和暂且置0

         memcpy(pIpHeader->SrcIpAddr, Global.SrcIpAddr, 4);         //发送端即源端的IP地址
		 memcpy(pIpHeader->DestIpAddr, DstIpAddr, 4);              //目的端的IP地址

		 CheckSum = CheckSumFunc((USHORT*)pIpHeader,sizeof(IP_HEADER));
         pIpHeader->CheckSum[0]=HIBYTE(CheckSum);
		 pIpHeader->CheckSum[1]=LOBYTE(CheckSum);

		 //TCP头
         pTcpHeader = (P_TCP_HEADER)(pPacketContent + sizeof(IP_HEADER));
         pTcpHeader->SrcPort[0] = HIBYTE(SrcPort);
         pTcpHeader->SrcPort[1] = LOBYTE(SrcPort);                //设定TCP源端口
		 pTcpHeader->DestPort[0] = HIBYTE(DstPort);
		 pTcpHeader->DestPort[1] = LOBYTE(DstPort);               //设定TCP目的端口
		 
		 Lhtonl(Isn, pTcpHeader->ISN);                            //设定序号
                      
		 Lhtonl(Ack, pTcpHeader->ACK);                            //设定确认号
         
		 pTcpHeader->TcpLen=0x50;                                 //4位TCP首部长度+4位0

		 pTcpHeader->MARK = Mark;                                 //设定标志位
		 pTcpHeader->Window[0]=HIBYTE(Window);
         pTcpHeader->Window[1]=LOBYTE(Window);                    //窗口大小

		 pTcpHeader->CheckSum[0]=0x00;
         pTcpHeader->CheckSum[1]=0x00;                            //暂时将校验和设为0
		 pTcpHeader->UrgenPointer[0]=0x00;
         pTcpHeader->UrgenPointer[1]=0x00;                        //紧急指针设为0

		 //标识部分
		 pTcpDataIdentifier = (P_TCP_DATA_IDENTIFIER)(pPacketContent + sizeof(IP_HEADER) + sizeof(TCP_HEADER));
		 pTcpDataIdentifier->Myself[0] = MYSELF_SIG1;
		 pTcpDataIdentifier->Myself[1] = MYSELF_SIG2;
         pTcpDataIdentifier->Myself[2] = MYSELF_SIG3;
		 pTcpDataIdentifier->Myself[3] = MYSELF_SIG4;
		 //pTcpDataIdentifier->TcbNum[0] = HIBYTE(TcbNum);
		 //pTcpDataIdentifier->TcbNum[1] = LOBYTE(TcbNum);
		 Lhtonl(TcbNum, pTcpDataIdentifier->TcbNum);
         Lhtonl(RemoteTcbNum, pTcpDataIdentifier->RemoteTcbNum);
		 for(int m=0; m<2; m++)
		 {
			 pTcpDataIdentifier->Comm[m] = Comm[m];
			 pTcpDataIdentifier->CurStatus[m] = CurStatus[m];
		 }
		 
		 //附加信息部分
         pTcpDataAppendix = (P_TCP_DATA_APPENDIX)(pPacketContent + sizeof(IP_HEADER) + sizeof(TCP_HEADER) + sizeof(TCP_DATA_IDENTIFIER));
         memcpy(pTcpDataAppendix->SubIpAddress, Global.SrcIpAddr, 4);
		 pTcpDataAppendix->DataLen[0] = HIBYTE(DataLen);
		 pTcpDataAppendix->DataLen[1] = LOBYTE(DataLen);
		 Lhtonl(FileSize, pTcpDataAppendix->FileSize);

		 //数据部分
         pData=pPacketContent + sizeof(IP_HEADER) + sizeof(TCP_HEADER) + sizeof(TCP_DATA_IDENTIFIER) + sizeof(TCP_DATA_APPENDIX);

	     for (USHORT i = 0; i < DataLen; i++)
		 {
              *pData++ = Data[i];
		 }

		 pTcpDataTailIdentifier = (P_TCP_DATA_TAIL_IDENTIFIER)(pPacketContent + sizeof(IP_HEADER) + sizeof(TCP_HEADER) + sizeof(TCP_DATA_IDENTIFIER) + sizeof(TCP_DATA_APPENDIX) + DataLen);
		 pTcpDataTailIdentifier->Myself[0] = MYSELF_SIG1;
		 pTcpDataTailIdentifier->Myself[1] = MYSELF_SIG2;
         pTcpDataTailIdentifier->Myself[2] = MYSELF_SIG3;

		 //计算TCP校验和
		 CheckSum=UdpOrTcpCheckSumFunc((PUCHAR)pIpHeader ,(int)(PacketLength));

		 //将计算出来的校验和赋给TCP头中的字段
         pTcpHeader->CheckSum[0]=HIBYTE(CheckSum);
         pTcpHeader->CheckSum[1]=LOBYTE(CheckSum);

		 //得到MAC地址
         Global.mac->SendWithMac(pPacketContent, PacketLength, Global.ListenerInfo->DebugPrintDriver);
         //长度加上MAC头的长度
		 PacketLength += 14;
	 
		 //发送
		 UINT dwStart = GetTickCount();
		 //for (int SendCount = 1; SendCount<PACKETNUM; SendCount++)
         {			
            if(!(hr=DeviceIoControl(Global.ListenerInfo->DebugPrintDriver, 
						IO_SEND_PACKET, 
						pPacketContent, 
						PacketLength,
						NULL, 
						0, 
						&dwReturnBytes, 
						NULL 
						)))
			{
				ErrMsg(hr, L"CAN NOT SEND TCP PACKET");
		        return FALSE;
			}
	       
		 }
		 dwStart = GetTickCount() - dwStart;
		 ErrPtf("物理发送", dwStart, 0, 0, 0, 0);

	}
	while(FALSE);
    //ErrMsg(0, L"SUCCEED TO SEND TCP PACKET");
	return TRUE;
}
示例#3
0
文件: melnorm.c 项目: intgr/sc2-uqm
static BOOLEAN
StripShip (COUNT fuel_required)
{
	BYTE i, which_module;
	SBYTE crew_pods;

	SET_GAME_STATE (MELNORME_RESCUE_REFUSED, 0);

	crew_pods = -(SBYTE)(
			(GLOBAL_SIS (CrewEnlisted) + CREW_POD_CAPACITY - 1)
			/ CREW_POD_CAPACITY
			);
	if (fuel_required == 0)
	{
		GlobData.SIS_state = SIS_copy;
		DeltaSISGauges (UNDEFINED_DELTA, rescue_fuel, UNDEFINED_DELTA);
	}
	else if (fuel_required == (COUNT)~0)
	{
		GLOBAL_SIS (NumLanders) = 0;
		for (i = 0; i < NUM_DRIVE_SLOTS; ++i)
			GLOBAL_SIS (DriveSlots[i]) = EMPTY_SLOT + 0;
		for (i = 0; i < NUM_JET_SLOTS; ++i)
			GLOBAL_SIS (JetSlots[i]) = EMPTY_SLOT + 1;
		if (GLOBAL_SIS (FuelOnBoard) > FUEL_RESERVE)
			GLOBAL_SIS (FuelOnBoard) = FUEL_RESERVE;
		GLOBAL_SIS (TotalBioMass) = 0;
		GLOBAL_SIS (TotalElementMass) = 0;
		for (i = 0; i < NUM_ELEMENT_CATEGORIES; ++i)
			GLOBAL_SIS (ElementAmounts[i]) = 0;
		for (i = 0; i < NUM_MODULE_SLOTS; ++i)
		{
			which_module = GLOBAL_SIS (ModuleSlots[i]);
			if (which_module < BOMB_MODULE_0
					&& (which_module != CREW_POD
					|| ++crew_pods > 0))
				GLOBAL_SIS (ModuleSlots[i]) = EMPTY_SLOT + 2;
		}

		DeltaSISGauges (UNDEFINED_DELTA, UNDEFINED_DELTA, UNDEFINED_DELTA);
	}
	else if (fuel_required)
	{
		SBYTE bays;
		BYTE num_searches, beg_mod, end_mod;
		COUNT worth, total;
		BYTE module_count[BOMB_MODULE_0];
		BYTE slot;
		DWORD capacity;
		RandomContext *rc;
		
		// Bug #567
		// In order to offer the same deal each time if it is refused, we seed
		// the random number generator with our location, thus making the deal
		// a repeatable pseudo-random function of where we got stuck and what,
		// exactly, is on our ship.
		rc = RandomContext_New();
		RandomContext_SeedRandom (rc, getStripRandomSeed ());

		SIS_copy = GlobData.SIS_state;
		for (i = PLANET_LANDER; i < BOMB_MODULE_0; ++i)
			module_count[i] = 0;

		capacity = FUEL_RESERVE;
		slot = NUM_MODULE_SLOTS - 1;
		do
		{
			if (SIS_copy.ModuleSlots[slot] == FUEL_TANK
					|| SIS_copy.ModuleSlots[slot] == HIGHEFF_FUELSYS)
			{
				COUNT volume;

				volume = SIS_copy.ModuleSlots[slot] == FUEL_TANK
						? FUEL_TANK_CAPACITY : HEFUEL_TANK_CAPACITY;
				capacity += volume;
			}
		} while (slot--);
		if (fuel_required > capacity)
			fuel_required = capacity;

		bays = -(SBYTE)(
				(SIS_copy.TotalElementMass + STORAGE_BAY_CAPACITY - 1)
				/ STORAGE_BAY_CAPACITY
				);
		for (i = 0; i < NUM_MODULE_SLOTS; ++i)
		{
			which_module = SIS_copy.ModuleSlots[i];
			if (which_module == CREW_POD)
				++crew_pods;
			else if (which_module == STORAGE_BAY)
				++bays;
		}

		worth = fuel_required / FUEL_TANK_SCALE;
		total = 0;
		num_searches = 0;
		beg_mod = end_mod = (BYTE)~0;
		while (total < worth && ShipWorth () && ++num_searches)
		{
			DWORD rand_val;

			rand_val = RandomContext_Random (rc);
			switch (which_module = LOBYTE (LOWORD (rand_val)) % (CREW_POD + 1))
			{
				case PLANET_LANDER:
					if (SIS_copy.NumLanders == 0)
						continue;
					--SIS_copy.NumLanders;
					break;
				case FUSION_THRUSTER:
					for (i = 0; i < NUM_DRIVE_SLOTS; ++i)
					{
						if (SIS_copy.DriveSlots[i] < EMPTY_SLOT)
							break;
					}
					if (i == NUM_DRIVE_SLOTS)
						continue;
					SIS_copy.DriveSlots[i] = EMPTY_SLOT + 0;
					break;
				case TURNING_JETS:
					for (i = 0; i < NUM_JET_SLOTS; ++i)
					{
						if (SIS_copy.JetSlots[i] < EMPTY_SLOT)
							break;
					}
					if (i == NUM_JET_SLOTS)
						continue;
					SIS_copy.JetSlots[i] = EMPTY_SLOT + 1;
					break;
				case CREW_POD:
					i = HIBYTE (LOWORD (rand_val)) % NUM_MODULE_SLOTS;
					which_module = SIS_copy.ModuleSlots[i];
					if (which_module >= BOMB_MODULE_0
							|| which_module == FUEL_TANK
							|| which_module == HIGHEFF_FUELSYS
							|| (which_module == STORAGE_BAY
							&& module_count[STORAGE_BAY] >= bays)
							|| (which_module == CREW_POD
							&& module_count[CREW_POD] >= crew_pods))
						continue;
					SIS_copy.ModuleSlots[i] = EMPTY_SLOT + 2;
					break;
			}

			if (beg_mod == (BYTE)~0)
				beg_mod = end_mod = which_module;
			else if (which_module > end_mod)
				end_mod = which_module;
			++module_count[which_module];
			total += GLOBAL (ModuleCost[which_module]);
		}
		RandomContext_Delete (rc);

		if (total == 0)
		{
			NPCPhrase (CHARITY);
			DeltaSISGauges (0, fuel_required, 0);
			return (FALSE);
		}
		else
		{
			NPCPhrase (RESCUE_OFFER);
			rescue_fuel = fuel_required;
			if (rescue_fuel == capacity)
				NPCPhrase (RESCUE_TANKS);
			else
				NPCPhrase (RESCUE_HOME);
			for (i = PLANET_LANDER; i < BOMB_MODULE_0; ++i)
			{
				if (module_count[i])
				{
					if (i == end_mod && i != beg_mod)
						NPCPhrase (END_LIST_WITH_AND);
					NPCPhrase (ENUMERATE_ONE + (module_count[i] - 1));
					NPCPhrase (GetStripModuleRef (i));
				}
			}
		}
	}

	return (TRUE);
}
示例#4
0
文件: melnorm.c 项目: intgr/sc2-uqm
// Extract method for setting the player's current credits.
static void
SetAvailableCredits (COUNT credits)
{
	SET_GAME_STATE (MELNORME_CREDIT0, LOBYTE (credits));
	SET_GAME_STATE (MELNORME_CREDIT1, HIBYTE (credits));
}
  0x02,   /* bmCapabilities */
  
  /*Union Functional Descriptor*/
  0x05,   /* bFunctionLength */
  0x24,   /* bDescriptorType: CS_INTERFACE */
  0x06,   /* bDescriptorSubtype: Union func desc */
  0x00,   /* bMasterInterface: Communication class interface */
  0x01,   /* bSlaveInterface0: Data Class Interface */
  
  /*Endpoint 2 Descriptor*/
  0x07,                           /* bLength: Endpoint Descriptor size */
  USB_ENDPOINT_DESCRIPTOR_TYPE,   /* bDescriptorType: Endpoint */
  CDC_CMD_EP,                     /* bEndpointAddress */
  0x03,                           /* bmAttributes: Interrupt */
  LOBYTE(CDC_CMD_PACKET_SZE),     /* wMaxPacketSize: */
  HIBYTE(CDC_CMD_PACKET_SZE),
#ifdef USE_USB_OTG_HS
  0x10,                           /* bInterval: */
#else
  0xFF,                           /* bInterval: */
#endif /* USE_USB_OTG_HS */
  
  /*---------------------------------------------------------------------------*/
  
  /*Data class interface descriptor*/
  0x09,   /* bLength: Endpoint Descriptor size */
  USB_INTERFACE_DESCRIPTOR_TYPE,  /* bDescriptorType: */
  0x01,   /* bInterfaceNumber: Number of Interface */
  0x00,   /* bAlternateSetting: Alternate setting */
  0x02,   /* bNumEndpoints: Two endpoints used */
  0x0A,   /* bInterfaceClass: CDC */
示例#6
0
int __cdecl main(int argc, char *argv[])
{

    WORD VersionRequested = MAKEWORD(2, 2);
    WSADATA WsaData;
    int err;
    int InvalidSocketID = -1; /*set an invalid socket descriptor*/
    struct sockaddr_in mySockaddr;
    const char *data = "sendto and recvfrom test";
    int nBuffer=strlen(data);

    /*Initialize the PAL environment*/
    err = PAL_Initialize(argc, argv);
    if(0 != err)
    {
        return FAIL;
    }
    /*initialize to use winsock2 .dll*/
    err = WSAStartup(VersionRequested, &WsaData);
    if(err != 0)
    {
        Fail("\nFailed to find a usable WinSock DLL!\n");
    }

    /*Confirm that the WinSock DLL supports 2.2.*/
    if(LOBYTE( WsaData.wVersion ) != 2 ||
            HIBYTE( WsaData.wVersion ) != 2)
    {
        Trace("\nFailed to find a usable WinSock DLL!\n");
        err = WSACleanup();
        if(SOCKET_ERROR == err)
        {
            Trace("\nFailed to call WSACleanup API!\n");
       }
        Fail("");
    }

    /*prepare the sockaddr_in structure*/
    mySockaddr.sin_family = AF_INET;
    mySockaddr.sin_port = getRotorTestPort();
    mySockaddr.sin_addr.S_un.S_addr = inet_addr("127.0.0.1");
    memset(&(mySockaddr.sin_zero), 0, 8);


    /*call sendto by passing an invalid socket*/
    err=sendto(InvalidSocketID, data, nBuffer, 0, 
                (struct sockaddr *)&mySockaddr, sizeof(struct sockaddr));

    if(WSAENOTSOCK != GetLastError() || SOCKET_ERROR != err)
    {
        Trace("\nFailed to call sendto API for a negative test "
                "by passing invalid socket!\n");
	
        err = WSACleanup();
        if(SOCKET_ERROR == err)
        {
            Trace("\nFailed to call WSACleanup API!\n");
        }
        Fail("");
    }

    err = WSACleanup();
    if(SOCKET_ERROR == err)
    {
        Fail("\nFailed to call WSACleanup API!\n");
    }

    PAL_Terminate();
    return PASS;
}
示例#7
0
/* create the platform-specific environment registry keys */
static void create_environment_registry_keys( void )
{
    static const WCHAR EnvironW[]  = {'S','y','s','t','e','m','\\',
                                      'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
                                      'C','o','n','t','r','o','l','\\',
                                      'S','e','s','s','i','o','n',' ','M','a','n','a','g','e','r','\\',
                                      'E','n','v','i','r','o','n','m','e','n','t',0};
    static const WCHAR NumProcW[]  = {'N','U','M','B','E','R','_','O','F','_','P','R','O','C','E','S','S','O','R','S',0};
    static const WCHAR ProcArchW[] = {'P','R','O','C','E','S','S','O','R','_','A','R','C','H','I','T','E','C','T','U','R','E',0};
    static const WCHAR x86W[]      = {'x','8','6',0};
    static const WCHAR armW[]      = {'A','R','M',0};
    static const WCHAR arm64W[]    = {'A','R','M','6','4',0};
    static const WCHAR AMD64W[]    = {'A','M','D','6','4',0};
    static const WCHAR ProcIdW[]   = {'P','R','O','C','E','S','S','O','R','_','I','D','E','N','T','I','F','I','E','R',0};
    static const WCHAR ProcLvlW[]  = {'P','R','O','C','E','S','S','O','R','_','L','E','V','E','L',0};
    static const WCHAR ProcRevW[]  = {'P','R','O','C','E','S','S','O','R','_','R','E','V','I','S','I','O','N',0};
    static const WCHAR PercentDW[] = {'%','d',0};
    static const WCHAR Percent04XW[] = {'%','0','4','x',0};
    static const WCHAR IntelCpuDescrW[]  = {'%','s',' ','F','a','m','i','l','y',' ','%','d',' ','M','o','d','e','l',' ','%','d',
                                            ' ','S','t','e','p','p','i','n','g',' ','%','d',',',' ','G','e','n','u','i','n','e','I','n','t','e','l',0};
    static const WCHAR ARMCpuDescrW[]  = {'A','R','M',' ','F','a','m','i','l','y',' ','%','d',' ','M','o','d','e','l',' ','%','d',
                                            ' ','R','e','v','i','s','i','o','n',' ','%','d',0};

    HKEY env_key;
    SYSTEM_CPU_INFORMATION sci;
    WCHAR buffer[60];
    const WCHAR *arch;

    NtQuerySystemInformation( SystemCpuInformation, &sci, sizeof(sci), NULL );

    if (RegCreateKeyW( HKEY_LOCAL_MACHINE, EnvironW, &env_key )) return;

    sprintfW( buffer, PercentDW, NtCurrentTeb()->Peb->NumberOfProcessors );
    set_reg_value( env_key, NumProcW, buffer );

    switch(sci.Architecture)
    {
    case PROCESSOR_ARCHITECTURE_AMD64: arch = AMD64W; break;
    case PROCESSOR_ARCHITECTURE_ARM:   arch = armW; break;
    case PROCESSOR_ARCHITECTURE_ARM64: arch = arm64W; break;
    default:
    case PROCESSOR_ARCHITECTURE_INTEL: arch = x86W; break;
    }
    set_reg_value( env_key, ProcArchW, arch );

    switch(sci.Architecture)
    {
    case PROCESSOR_ARCHITECTURE_ARM:
    case PROCESSOR_ARCHITECTURE_ARM64:
        sprintfW( buffer, ARMCpuDescrW, sci.Level, HIBYTE(sci.Revision), LOBYTE(sci.Revision) );
        break;
    default:
    case PROCESSOR_ARCHITECTURE_INTEL:
        sprintfW( buffer, IntelCpuDescrW, arch, sci.Level, HIBYTE(sci.Revision), LOBYTE(sci.Revision) );
        break;
    }
    set_reg_value( env_key, ProcIdW, buffer );

    sprintfW( buffer, PercentDW, sci.Level );
    set_reg_value( env_key, ProcLvlW, buffer );

    /* Properly report model/stepping */
    sprintfW( buffer, Percent04XW, sci.Revision );
    set_reg_value( env_key, ProcRevW, buffer );

    RegCloseKey( env_key );
}
示例#8
0
/* create the volatile hardware registry keys */
static void create_hardware_registry_keys(void)
{
    static const WCHAR SystemW[] = {'H','a','r','d','w','a','r','e','\\',
                                    'D','e','s','c','r','i','p','t','i','o','n','\\',
                                    'S','y','s','t','e','m',0};
    static const WCHAR fpuW[] = {'F','l','o','a','t','i','n','g','P','o','i','n','t','P','r','o','c','e','s','s','o','r',0};
    static const WCHAR cpuW[] = {'C','e','n','t','r','a','l','P','r','o','c','e','s','s','o','r',0};
    static const WCHAR FeatureSetW[] = {'F','e','a','t','u','r','e','S','e','t',0};
    static const WCHAR IdentifierW[] = {'I','d','e','n','t','i','f','i','e','r',0};
    static const WCHAR ProcessorNameStringW[] = {'P','r','o','c','e','s','s','o','r','N','a','m','e','S','t','r','i','n','g',0};
    static const WCHAR SysidW[] = {'A','T',' ','c','o','m','p','a','t','i','b','l','e',0};
    static const WCHAR ARMSysidW[] = {'A','R','M',' ','p','r','o','c','e','s','s','o','r',' ','f','a','m','i','l','y',0};
    static const WCHAR mhzKeyW[] = {'~','M','H','z',0};
    static const WCHAR VendorIdentifierW[] = {'V','e','n','d','o','r','I','d','e','n','t','i','f','i','e','r',0};
    static const WCHAR VenidIntelW[] = {'G','e','n','u','i','n','e','I','n','t','e','l',0};
    /* static const WCHAR VenidAMDW[] = {'A','u','t','h','e','n','t','i','c','A','M','D',0}; */
    static const WCHAR PercentDW[] = {'%','d',0};
    static const WCHAR IntelCpuDescrW[] = {'x','8','6',' ','F','a','m','i','l','y',' ','%','d',' ','M','o','d','e','l',' ','%','d',
                                           ' ','S','t','e','p','p','i','n','g',' ','%','d',0};
    static const WCHAR ARMCpuDescrW[]  = {'A','R','M',' ','F','a','m','i','l','y',' ','%','d',' ','M','o','d','e','l',' ','%','d',
                                            ' ','R','e','v','i','s','i','o','n',' ','%','d',0};
    static const WCHAR IntelCpuStringW[] = {'I','n','t','e','l','(','R',')',' ','P','e','n','t','i','u','m','(','R',')',' ','4',' ',
                                            'C','P','U',' ','2','.','4','0','G','H','z',0};
    unsigned int i;
    HKEY hkey, system_key, cpu_key, fpu_key;
    SYSTEM_CPU_INFORMATION sci;
    PROCESSOR_POWER_INFORMATION* power_info;
    ULONG sizeof_power_info = sizeof(PROCESSOR_POWER_INFORMATION) * NtCurrentTeb()->Peb->NumberOfProcessors;
    WCHAR idW[60];

    NtQuerySystemInformation( SystemCpuInformation, &sci, sizeof(sci), NULL );

    power_info = HeapAlloc( GetProcessHeap(), 0, sizeof_power_info );
    if (power_info == NULL)
        return;
    if (NtPowerInformation( ProcessorInformation, NULL, 0, power_info, sizeof_power_info ))
        memset( power_info, 0, sizeof_power_info );

    /*TODO: report 64bit processors properly*/
    switch(sci.Architecture)
    {
    case PROCESSOR_ARCHITECTURE_ARM:
    case PROCESSOR_ARCHITECTURE_ARM64:
        sprintfW( idW, ARMCpuDescrW, sci.Level, HIBYTE(sci.Revision), LOBYTE(sci.Revision) );
        break;
    default:
    case PROCESSOR_ARCHITECTURE_INTEL:
        sprintfW( idW, IntelCpuDescrW, sci.Level, HIBYTE(sci.Revision), LOBYTE(sci.Revision) );
        break;
    }

    if (RegCreateKeyExW( HKEY_LOCAL_MACHINE, SystemW, 0, NULL, REG_OPTION_VOLATILE,
                         KEY_ALL_ACCESS, NULL, &system_key, NULL ))
    {
        HeapFree( GetProcessHeap(), 0, power_info );
        return;
    }

    switch(sci.Architecture)
    {
    case PROCESSOR_ARCHITECTURE_ARM:
    case PROCESSOR_ARCHITECTURE_ARM64:
        set_reg_value( system_key, IdentifierW, ARMSysidW );
        break;
    default:
    case PROCESSOR_ARCHITECTURE_INTEL:
        set_reg_value( system_key, IdentifierW, SysidW );
        break;
    }

    if (sci.Architecture == PROCESSOR_ARCHITECTURE_ARM ||
        sci.Architecture == PROCESSOR_ARCHITECTURE_ARM64 ||
        RegCreateKeyExW( system_key, fpuW, 0, NULL, REG_OPTION_VOLATILE,
                         KEY_ALL_ACCESS, NULL, &fpu_key, NULL ))
        fpu_key = 0;
    if (RegCreateKeyExW( system_key, cpuW, 0, NULL, REG_OPTION_VOLATILE,
                         KEY_ALL_ACCESS, NULL, &cpu_key, NULL ))
        cpu_key = 0;

    for (i = 0; i < NtCurrentTeb()->Peb->NumberOfProcessors; i++)
    {
        WCHAR numW[10];

        sprintfW( numW, PercentDW, i );
        if (!RegCreateKeyExW( cpu_key, numW, 0, NULL, REG_OPTION_VOLATILE,
                              KEY_ALL_ACCESS, NULL, &hkey, NULL ))
        {
            RegSetValueExW( hkey, FeatureSetW, 0, REG_DWORD, (BYTE *)&sci.FeatureSet, sizeof(DWORD) );
            set_reg_value( hkey, IdentifierW, idW );
            /*TODO; report ARM and AMD properly*/
            set_reg_value( hkey, ProcessorNameStringW, IntelCpuStringW );
            set_reg_value( hkey, VendorIdentifierW, VenidIntelW );
            RegSetValueExW( hkey, mhzKeyW, 0, REG_DWORD, (BYTE *)&power_info[i].MaxMhz, sizeof(DWORD) );
            RegCloseKey( hkey );
        }
        if (sci.Architecture != PROCESSOR_ARCHITECTURE_ARM &&
            sci.Architecture != PROCESSOR_ARCHITECTURE_ARM64 &&
            !RegCreateKeyExW( fpu_key, numW, 0, NULL, REG_OPTION_VOLATILE,
                              KEY_ALL_ACCESS, NULL, &hkey, NULL ))
        {
            set_reg_value( hkey, IdentifierW, idW );
            RegCloseKey( hkey );
        }
    }
    RegCloseKey( fpu_key );
    RegCloseKey( cpu_key );
    RegCloseKey( system_key );
    HeapFree( GetProcessHeap(), 0, power_info );
}
示例#9
0
// Print embedded plug-in (via the browser's Print command)
static void NPP_Print(NPP instance, NPPrint* printInfo)
{
	PluginInstance* This;
	if (instance == NULL) return;
	This = (PluginInstance*) instance->pdata;

	if(printInfo == NULL) {
		// Some browsers (Netscape) set printInfo to NULL to tell the plugin
		// to print in full page mode (this may be a bug).
		// PrintFullPage();  -- full page printing not implemented
		return;
	}
	
	if (printInfo->mode == NP_FULL) {
		/* the plugin is full-page, and the browser is giving it a chance
		 * to print in the manner of its choosing */
		void* platformPrint = printInfo->print.fullPrint.platformPrint;
		NPBool printOne =  printInfo->print.fullPrint.printOne;
		
		/* Setting this to FALSE and returning *should* cause the browser to
		 * call NPP_Print again, this time with mode=NP_EMBED.
		 * However, that doesn't happen with any browser I've ever seen :-(.
		 * Instead of the following line, you will probably need to implement
		 * printing yourself.  You also might as well set pluginPrinted to TRUE,
		 * though every browser I've tested ignores it. */
		printInfo->print.fullPrint.pluginPrinted = FALSE;
		/*  or */
		/*  PrintFullPage();
		 *  printInfo->print.fullPrint.pluginPrinted = TRUE;  */
	}
	else {	// we are embedded, and the browser had provided a printer context
		HDC pdc;
		int prevstretchmode;
		NPWindow* printWindow;
		
		if(This->loadstate < STATE_VALIDFRAME) return;

		printWindow= &(printInfo->print.embedPrint.window);

		/* embedPrint.platformPrint is a Windows device context in disguise */

		/* The definition of NPWindow changed between API verion 0.9 and 0.11,
		 * increasing in size from 28 to 32 bytes. This normally makes it
		 * impossible for version 0.9 browsers to print version 0.11 plugins
		 * (because the platformPrint field ends up at the wrong offset) --
		 * unless the plugin takes special care to detect this situation.
		 * To work around it, if we are compiled with API 0.11 or higher,
		 * and the browser is version 0.9 or earlier, we look for the HDC
		 * 4 bytes earlier, at offset 28 instead of 32 (of the embedPrint
		 * sub-structure).
		 */

		if(sizeof(NPWindow)>28 &&     /* i.e. is plugin API >= 0.11? */
			     HIBYTE(g_pNavigatorFuncs->version)==0 &&
		         LOBYTE(g_pNavigatorFuncs->version)<=9) {
			char *tmpc;
			HDC  *tmph;

			tmpc= (char*)&(printInfo->print.embedPrint);
			tmph= (HDC*)&tmpc[28];
			pdc=  *tmph;
		}
		else {
			pdc= (HDC) (printInfo->print.embedPrint.platformPrint);
		}

		if(!This->lpdib) return;

		prevstretchmode=SetStretchBltMode(pdc,COLORONCOLOR);
		StretchDIBits(pdc,
			printWindow->x,printWindow->y,
			printWindow->width,printWindow->height, /* dest coords */
			0,0,This->lpdibinfo->biWidth, This->lpdibinfo->biHeight,   /* source coords */
			This->lpdibbits, (LPBITMAPINFO)This->lpdib,
			DIB_RGB_COLORS,SRCCOPY);
		if(prevstretchmode) SetStretchBltMode(pdc,prevstretchmode);
	}
	return;
}
示例#10
0
LRESULT CALLBACK WindowProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) {
    // Child windows' handles
    static HWND hwndListBox, hwndNewItem, hwndAddButton, hwndRemoveButton, hwndClearButton, hwndHeightScroll, hwndWidthScroll;
    static HINSTANCE hInstance;

    // Size and position variables
    int iSysWidth;
    int iSysHeight;
    int iWinWidth;
    int iWinHeight;

    int iWidth  = 60;   // Button width
    int iHeight = 30;   // Button height
    int x;
    int y;

    int i, cxChar, cyChar;

    // Menu & menu items
    HMENU hMenu;
    HMENU hSubMenu;

    // String
    char* szText;
    int iTextLength;

    // Paint and size structs
    TEXTMETRIC tm;
    SCROLLINFO si;
    HBRUSH brush;
    RECT rect, rct;
    int color;
    HDC hdc;


    hdc = GetDC(hwnd);
    GetTextMetrics(hdc, &tm);
    cxChar = tm.tmAveCharWidth;
    cyChar = tm.tmHeight;
    ReleaseDC(hwnd, hdc);

    switch(message) {

        case WM_CREATE:
            hwndListBox = CreateWindowEx(
                (DWORD)NULL,
                TEXT("ListBox"),
                NULL,
                WS_CHILD | WS_VISIBLE | WS_BORDER | LBS_NOTIFY | LBS_WANTKEYBOARDINPUT,
                0, 0, 0, 0, hwnd,
                (HMENU)IDC_LIST_BOX,
                hProgramInstance,
                NULL);

            hwndNewItem = CreateWindowEx(
                (DWORD)NULL,
                TEXT("Edit"),
                TEXT("Input candidates"),
                WS_CHILD | WS_VISIBLE | WS_BORDER |ES_AUTOVSCROLL | ES_AUTOHSCROLL,
                0, 0, 0, 0, hwnd,
                (HMENU)IDC_NEW_ITEM,
                hProgramInstance,
                NULL);

            hwndWidthScroll = CreateWindow(
                "Scrollbar",
                NULL,
                WS_CHILD | WS_VISIBLE | SBS_HORZ | SBS_BOTTOMALIGN,
                0, 0, 0, 0, hwnd,
                (HMENU)IDC_WIDTH_SCROLL,
                hProgramInstance,
                NULL);
            SetScrollRange(hwndWidthScroll, SB_CTL, 0, 100, FALSE);
            SetScrollPos(hwndWidthScroll, SB_CTL, 0, FALSE);

            hwndHeightScroll = CreateWindow(
                "Scrollbar",
                NULL,
                WS_CHILD | WS_VISIBLE | SBS_VERT | SBS_BOTTOMALIGN,
                0, 0, 0, 0, hwnd,
                (HMENU)IDC_HEIGHT_SCROLL,
                hProgramInstance,
                NULL);
            SetScrollRange(hwndHeightScroll, SB_CTL, 0, 100, TRUE);
            SetScrollPos(hwndHeightScroll, SB_CTL, 0, FALSE);

            hwndAddButton = CreateWindowEx(
                (DWORD)NULL,
                TEXT("Button"),
                TEXT("Add"),
                WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
                0, 0, 0, 0, hwnd,
                (HMENU)IDC_ADD_BUTTON,
                hProgramInstance,
                NULL);

            hwndRemoveButton = CreateWindowEx(
                (DWORD)NULL,
                TEXT("Button"),
                TEXT("Remove"),
                WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
                0, 0, 0, 0, hwnd,
                (HMENU)IDC_REMOVE_BUTTON,
                hProgramInstance,
                NULL);

            hwndClearButton = CreateWindowEx(
                (DWORD)NULL,
                TEXT("Button"),
                TEXT("Clear"),
                WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
                0, 0, 0, 0, hwnd,
                (HMENU)IDC_CLEAR_BUTTON,
                hProgramInstance,
                NULL);


            // Create menu
            hMenu = CreateMenu();

            // Add "File" menu, with "Exit" submenu
            hSubMenu = CreatePopupMenu();
            AppendMenu(hMenu, MF_STRING | MF_POPUP, (UINT)hSubMenu, "&File");
            AppendMenu(hSubMenu, MF_STRING, IDC_FILE_EXIT, "&Exit");

            hSubMenu = CreatePopupMenu();
            AppendMenu(hMenu, MF_STRING | MF_POPUP, (UINT)hSubMenu, "&Edit");
            AppendMenu(hSubMenu, MF_STRING, IDC_MOVE, "&Jump around");

            hSubMenu = CreatePopupMenu();
            AppendMenu(hMenu, MF_STRING | MF_POPUP, (UINT)hSubMenu, "&Help");
            AppendMenu(hSubMenu, MF_STRING, IDC_HELP_ABOUT, "&About");

            // Set the menu
            SetMenu(hwnd, hMenu);
            break;

        case WM_SIZE:
            iWidth  = LOWORD(lParam);
            iHeight = HIWORD(lParam);

            // Set vertical scroll bar range and page size
            si.cbSize = sizeof(si);
            si.fMask = SIF_RANGE | SIF_PAGE;
            si.nMin = 0;
            si.nMax = ((iMinWindowHeight - 70) / cyChar);
            si.nPage = iHeight / cyChar;
            SetScrollInfo(hwnd, SB_VERT, &si, TRUE);

            // Set horizontal scroll bar range and page size
            si.cbSize = sizeof(si);
            si.fMask = SIF_RANGE | SIF_PAGE;
            si.nMin = 0;
            si.nMax = ((iMinWindowWidth - 20) / cxChar);
            si.nPage = iWidth / cxChar;
            SetScrollInfo(hwnd, SB_HORZ, &si, TRUE);

            // CHILD WINDOWS REPOSITION BEGIN

            MoveWindow(hwndListBox, iWidth/2 - 210, iHeight/2 - 150, 300, 350, TRUE);
            MoveWindow(hwndNewItem, iWidth/2 - 210, iHeight/2 - 220, 300, 50, TRUE);
            MoveWindow(hwndWidthScroll, iWidth/2 - 210, iHeight/2 + 200, 410, 20, TRUE);
            MoveWindow(hwndHeightScroll, iWidth/2 + 180, iHeight/2 - 220, 20, 410, TRUE);
            MoveWindow(hwndAddButton, iWidth/2 + 100, iHeight/2 - 210, 60, 30, TRUE);
            MoveWindow(hwndRemoveButton, iWidth/2 + 100, iHeight/2 - 140, 60, 30, TRUE);
            MoveWindow(hwndClearButton, iWidth/2 + 100 , iHeight/2- 100, 60, 30, TRUE);

            // CHILD WINDOWS REPOSITION END
            GetWindowRect(hwnd, &rect);
            iWinWidth = rect.right - rect.left;
            iWinHeight = rect.bottom - rect.top;
            iSysWidth = GetSystemMetrics(SM_CXSCREEN);
            iSysHeight = GetSystemMetrics(SM_CYSCREEN);

            // Set width scrollbar position
            SetScrollPos(hwndWidthScroll, SB_CTL, (iWinWidth * 100 / iSysWidth), TRUE);

            // Set height scrollbar position
            SetScrollPos(hwndHeightScroll, SB_CTL, (iWinHeight * 100 / iSysHeight), TRUE);
            break;

        case WM_VSCROLL:
            GetWindowRect(hwnd, &rect);
            iWinWidth = rect.right - rect.left;
            iWinHeight = rect.bottom - rect.top;
            iSysWidth = GetSystemMetrics(SM_CXSCREEN);
            iSysHeight = GetSystemMetrics(SM_CYSCREEN);

            if(GetWindowLong((HWND)lParam, GWL_ID) == IDC_HEIGHT_SCROLL) {
                si.cbSize = sizeof(si);
                si.fMask = SIF_ALL;
                GetScrollInfo(hwndHeightScroll, SB_CTL, &si);
                y = si.nPos;
                switch(LOWORD(wParam)) {
                    case SB_LINELEFT:
                        si.nPos -= 1;
                        break;
                    case SB_LINERIGHT:
                        si.nPos += 1;
                        break;
                    case SB_THUMBPOSITION:
                        si.nPos = si.nTrackPos;
                        break;
                    default:
                        break;
                }
                si.fMask = SIF_POS;
                SetScrollInfo(hwndHeightScroll, SB_CTL, &si, TRUE);
                GetScrollInfo(hwndHeightScroll, SB_CTL, &si);
                if(si.nPos != y) {
                    SetScrollPos(hwndHeightScroll, SB_CTL, si.nPos, TRUE);
                }
                // Set window height
                MoveWindow(hwnd, rect.left, rect.top, iWinWidth, (si.nPos * iSysHeight / 100), TRUE);
                break;
            }


            // Get all the vertical scroll bar information
            si.cbSize = sizeof(si);
            si.fMask = SIF_ALL;
            GetScrollInfo(hwnd, SB_VERT, &si);

            // Save the position for later comparison
            x = si.nPos;


            switch(LOWORD(wParam)) {
                case SB_TOP:
                    si.nPos = si.nMin;
                    break;

                case SB_BOTTOM:
                    si.nPos = si.nMax;
                    break;

                case SB_LINEUP:
                    si.nPos -= 1;
                    break;

                case SB_LINEDOWN:
                    si.nPos += 1;
                    break;

                case SB_PAGEUP:
                    si.nPos -= si.nPage;
                    break;

                case SB_PAGEDOWN:
                    si.nPos += si.nPage;
                    break;

                case SB_THUMBTRACK:
                    si.nPos = si.nTrackPos;
                    break;

                default:
                    break;
            }

            // Set the position and then retrieve it
            si.fMask = SIF_POS;
            SetScrollInfo(hwnd, SB_VERT, &si, TRUE);
            GetScrollInfo(hwnd, SB_VERT, &si);

            // If the position has changed, scroll the window and update it
            if(si.nPos != x) {
                ScrollWindow(hwnd, 0, cyChar * (y - si.nPos), NULL, NULL);
                UpdateWindow(hwnd);
            }
            break;

        case WM_HSCROLL:
            GetWindowRect(hwnd, &rect);
            iWinWidth = rect.right - rect.left;
            iWinHeight = rect.bottom - rect.top;
            iSysWidth = GetSystemMetrics(SM_CXSCREEN);
            iSysHeight = GetSystemMetrics(SM_CYSCREEN);

            if(GetWindowLong((HWND)lParam, GWL_ID) == IDC_WIDTH_SCROLL) {
                si.cbSize = sizeof(si);
                si.fMask = SIF_ALL;
                GetScrollInfo(hwndWidthScroll, SB_CTL, &si);
                x = si.nPos;
                switch(LOWORD(wParam)) {
                    case SB_LINELEFT:
                        si.nPos -= 1;
                        break;
                    case SB_LINERIGHT:
                        si.nPos += 1;
                        break;
                    case SB_THUMBPOSITION:
                        si.nPos = si.nTrackPos;
                        break;
                    default:
                        break;
                }
                si.fMask = SIF_POS;
                SetScrollInfo(hwndWidthScroll, SB_CTL, &si, TRUE);
                GetScrollInfo(hwndWidthScroll, SB_CTL, &si);
                if(si.nPos != x) {
                    SetScrollPos(hwndWidthScroll, SB_CTL, si.nPos, TRUE);
                }
                // Set window width
                MoveWindow(hwnd, rect.left, rect.top, (si.nPos * iSysWidth / 100), iWinHeight, TRUE);
                break;
            }

           // Get all the vertical scroll bar information
            si.cbSize = sizeof(si);
            si.fMask = SIF_ALL;
            GetScrollInfo(hwnd, SB_HORZ, &si);
            // Save the position for later comparison
            x = si.nPos;
            switch(LOWORD(wParam)) {
                case SB_LINELEFT:
                    si.nPos -= 1;
                    break;

                case SB_LINERIGHT:
                    si.nPos += 1;
                    break;

                case SB_PAGELEFT:
                    si.nPos -= si.nPage;
                    break;

                case SB_PAGERIGHT:
                    si.nPos += si.nPage;
                    break;

                case SB_THUMBPOSITION:
                    si.nPos = si.nTrackPos;
                    break;

                default:
                    break;
            }
            // Set the position and then retrieve it
            si.fMask = SIF_POS;
            SetScrollInfo(hwnd, SB_HORZ, &si, TRUE);
            GetScrollInfo(hwnd, SB_HORZ, &si);

            // If the position has changed, scroll the window and update it
            if(si.nPos != x) {
                ScrollWindow(hwnd, cxChar * (x - si.nPos), 0, NULL, 0);
                UpdateWindow(hwnd);
            }
            break;

        case WM_COMMAND:
            switch (LOWORD(wParam)) {
                case IDC_LIST_BOX:
                    switch (HIWORD(wParam)) {
                        case LBN_DBLCLK:
                            MessageBox(NULL, TEXT("Candidate Selected!"), TEXT("Congrats!"), MB_OK);
                            break;
                    }
                    break;

                case IDC_ADD_BUTTON:
                    iTextLength = SendMessage(hwndNewItem, WM_GETTEXTLENGTH, 0, 0);
                    szText = (char*)malloc(iTextLength+1);
                    SendMessage(hwndNewItem, WM_GETTEXT, iTextLength+1, (LPARAM)szText);
                    SendMessage(hwndListBox, LB_ADDSTRING, 0, (LPARAM)szText);
                    SendMessage(hwndNewItem, WM_SETTEXT, 0, (LPARAM)"");
                    free(szText);
                    break;

                case IDC_REMOVE_BUTTON:
                    i = SendMessage(hwndListBox, LB_GETCURSEL, 0, 0);
                    if(i != LB_ERR) {
                        SendMessage(hwndListBox, LB_DELETESTRING, i, 0);
                    }
                    break;

                case IDC_CLEAR_BUTTON:
                    SendMessage(hwndListBox, LB_RESETCONTENT, 0, 0);
                    break;

                case IDC_FILE_EXIT:
                    SendMessage(hwnd, WM_DESTROY, 0, 0);
                    break;

                case IDC_MOVE:
                            int xPos, yPos;
                            xPos = rand() % 1000;
                            yPos = rand() % 800;
                            SetWindowPos(hwnd, HWND_TOP, xPos, yPos, 0, 0, SWP_NOSIZE);
                            break;

                case IDC_HELP_ABOUT:
                    return DialogBox(hProgramInstance, MAKEINTRESOURCE(IDD_ABOUT), NULL, (DLGPROC)DialogProcedure);
                    break;

                default:
                    DefWindowProc(hwnd, WM_COMMAND, wParam, lParam);
                    break;
            }
            break;

        case WM_KEYDOWN:
            GetWindowRect(hwnd, &rect);
            iWinWidth = rect.right - rect.left;
            iWinHeight = rect.bottom - rect.top;
            iSysWidth = GetSystemMetrics(SM_CXSCREEN);
            iSysHeight = GetSystemMetrics(SM_CYSCREEN);

            // Move window right on Shift + Arrow Right
            if((wParam == VK_RIGHT)&&(HIBYTE(GetKeyState(VK_SHIFT)) > 1)) {
                if(rect.left >= iSysWidth - iWinWidth) {
                    MoveWindow(hwnd, iSysWidth - iWinWidth, rect.top, iWinWidth, iWinHeight, TRUE);
                }
                else {
                    MoveWindow(hwnd, rect.left + 5, rect.top, iWinWidth, iWinHeight, TRUE);
                }
                break;
            }
            // Move window left on Shift + Arrow Left
            if((wParam == VK_LEFT)&&(HIBYTE(GetKeyState(VK_SHIFT)) > 1)) {
                if(rect.left <= 0) {
                    MoveWindow(hwnd, 0, rect.top, iWinWidth, iWinHeight, TRUE);
                }
                else {
                    MoveWindow(hwnd, rect.left - 5, rect.top, iWinWidth, iWinHeight, TRUE);
                }
                break;
            }
            // Move window down on Shift + Arrow Down
            if((wParam == VK_DOWN)&&(HIBYTE(GetKeyState(VK_SHIFT)) > 1)) {
                if(rect.top >= iSysHeight - iWinHeight) {
                    MoveWindow(hwnd, rect.left, iSysHeight - iWinHeight, iWinWidth, iWinHeight, TRUE);
                }
                else {
                    MoveWindow(hwnd, rect.left, rect.top + 5, iWinWidth, iWinHeight, TRUE);
                }
                break;
            }
            // Move window up on Shift + Arrow Up
            if((wParam == VK_UP)&&(HIBYTE(GetKeyState(VK_SHIFT)) > 1)) {
                if(rect.top <= 0) {
                    MoveWindow(hwnd, rect.left, 0, iWinWidth, iWinHeight, TRUE);
                }
                else {
                    MoveWindow(hwnd, rect.left, rect.top - 5, iWinWidth, iWinHeight, TRUE);
                }
                break;
            }
            return DefWindowProc (hwnd, WM_PAINT, wParam, lParam);


        case WM_PAINT:
            return DefWindowProc (hwnd, WM_PAINT, wParam, lParam);
            break;

        case WM_DESTROY:
            PostQuitMessage (0);
            break;

        default:
            return DefWindowProc (hwnd, message, wParam, lParam);
    }

    return 0;
}
示例#11
0
int __cdecl main(int argc, char *argv[])
{
    WORD VersionRequested = MAKEWORD(2, 2);
    WSADATA WsaData;
    SOCKET aSocket;
    int err;
    int socketID;
    struct sockaddr_in mySockaddr,mySocketaddrConnect;
    int nSocketaddrLength;
    int nBacklogNumber = 1;
    struct timeval waitTime;
    fd_set readFds;
    int socketFds;


    /*Initialize the PAL environment*/
    err = PAL_Initialize(argc, argv);
    if(0 != err)
    {
        return FAIL;
    }

    /*initialize to use winsock2.dll*/
    err = WSAStartup(VersionRequested,&WsaData);
    if(err != 0)
    {
        Fail("\nFailed to find a usable WinSock DLL!\n");
    }

    /* Confirm that the WinSock DLL supports 2.2.*/
    if(LOBYTE( WsaData.wVersion ) != 2 ||
            HIBYTE( WsaData.wVersion ) != 2)
    {
        Trace("\nFailed to find a usable WinSock DLL!\n");
        err = WSACleanup();
        if(SOCKET_ERROR == err)
        {
            Trace("\nFailed to call WSACleanup API!\n");
        }
        Fail("");
    }

    /*create a stream socket in AF_INET domain*/
    socketID = socket(AF_INET,SOCK_STREAM,0);

    if(INVALID_SOCKET == socketID)
    {
        Trace("\nFailed to call socket API to create a stream socket!\n");
        err = WSACleanup();
        if(SOCKET_ERROR == err)
        {
            Trace("\nFailed to call WSACleanup API!\n");
        }
        Fail("");
    }

    // Wait for 5 seconds for the client to connect.
    waitTime.tv_sec = 5L;
    waitTime.tv_usec = 0L;

    /*initialize the except socket set*/
    FD_ZERO(&readFds);

    /*prepare the sockaddr_in structure*/
    mySockaddr.sin_family = AF_INET;
    mySockaddr.sin_port = getRotorTestPort();
    mySockaddr.sin_addr.S_un.S_addr = inet_addr("127.0.0.1");
    memset( &(mySockaddr.sin_zero), 0, 8);

    /*bind the local address to the created socket*/
    err = bind(socketID,(struct sockaddr *)&mySockaddr,
            sizeof(struct sockaddr));
    if(SOCKET_ERROR == err)
    {
        Trace("\nFailed to call bind API to bind a socket with "
            "local address!\n");
        err = closesocket(socketID);
        if(SOCKET_ERROR == err)
        {    
            Trace("\nFailed to call closesocket API!\n");
        }
        err = WSACleanup();
        if(SOCKET_ERROR == err)
        {
            Trace("\nFailed to call WSACleanup API!\n");
        }
        Fail("");
    }

    /*to setup the backlog number for a created socket*/
    err = listen(socketID, nBacklogNumber);
    if(SOCKET_ERROR == err)
    {
        Trace("\nFailed to call listen API to setup backlog number!\n");
        err = closesocket(socketID);
        if(SOCKET_ERROR == err)
        {    
            Trace("\nFailed to call closesocket API!\n");
        }
        err = WSACleanup();
        if(SOCKET_ERROR == err)
        {
            Trace("\nFailed to call WSACleanup API!\n");
        }
        Fail("");
    }

    /*add socket to readable socket set*/
    FD_SET(socketID,&readFds);
    /*mornitor the readable socket set*/
    socketFds = select(0, &readFds, NULL, NULL, &waitTime);

    if(SOCKET_ERROR == socketFds)
    {
        Trace("\nFailed to call select API!\n");
        err = closesocket(socketID);
        if(SOCKET_ERROR == err)
        {    
            Trace("\nFailed to call closesocket API!\n");
        }
        err = WSACleanup();
        if(SOCKET_ERROR == err)
        {
            Trace("\nFailed to call WSACleanup API!\n");
        }
        Fail("");
    }
    if(0 == socketFds)
    {
        Trace("\nWaiting time is out!\n");
        err = closesocket(socketID);
        if(SOCKET_ERROR == err)
        {    
            Trace("\nFailed to call closesocket API!\n");
        }
        err = WSACleanup();
        if(SOCKET_ERROR == err)
        {
            Trace("\nFailed to call WSACleanup API!\n");
        }
        Fail("");
    }

    nSocketaddrLength = sizeof(mySocketaddrConnect);

    /*accept a request from client*/
    aSocket = accept(socketID,(struct sockaddr*)&mySocketaddrConnect,
            &nSocketaddrLength);

    if(INVALID_SOCKET == aSocket)
    {
        Trace("\nFailed to call accept API!\n");
        err = closesocket(socketID);
        if(SOCKET_ERROR == err)
        {    
            Trace("\nFailed to call closesocket API!\n");
        }
        err = WSACleanup();
        if(SOCKET_ERROR == err)
        {
            Trace("\nFailed to call WSACleanup API!\n");
        }
        Fail("");
    }

    err = closesocket(aSocket);
    if(SOCKET_ERROR == err)
    {
        Trace("\nFailed to call closesocket API!\n");
        err = WSACleanup();
        if(SOCKET_ERROR == err)
        {
            Trace("\nFailed to call WSACleanup API!\n");
        }
        Fail("");
    }

    err = closesocket(socketID);
    if(SOCKET_ERROR == err)
    {
        Trace("\nFailed to call closesocket API!\n");
        err = WSACleanup();
        if(SOCKET_ERROR == err)
        {
            Trace("\nFailed to call WSACleanup API!\n");
        }
        Fail("");
    }

    /*terminate the use of WinSock DLL*/
    err = WSACleanup();
    if(SOCKET_ERROR == err)
    {
        Fail("\nFailed to call WSACleanup API!\n");
    }

    PAL_Terminate();
    return PASS;
}