当前位置: 首页>>代码示例>>C++>>正文


C++ GetTickCount函数代码示例

本文整理汇总了C++中GetTickCount函数的典型用法代码示例。如果您正苦于以下问题:C++ GetTickCount函数的具体用法?C++ GetTickCount怎么用?C++ GetTickCount使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了GetTickCount函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: tempzip_make

int tempzip_make(HWND hwndDlg, TCHAR *fn)
{
  TCHAR buf[MAX_PATH];
  GetTempPath(MAX_PATH,buf);
  GetTempFileName(buf,_T("z2e"),GetTickCount(),tempzip_path);
  if (!CreateDirectory(tempzip_path,NULL))
  {
    GetTempPath(MAX_PATH,tempzip_path);
    _tcscat(tempzip_path,_T("\\nsi"));
    if (!CreateDirectory(tempzip_path,NULL))
    {
      tempzip_path[0]=0;
      MessageBox(hwndDlg,_T("Error creating temporary directory"),g_errcaption,MB_OK|MB_ICONSTOP);
      return 1;
    }
  }
  FILE *fp=_tfopen(fn,_T("rb"));
  if (fp)
  {
    fseek(fp,0,SEEK_END);
    g_zipfile_size=ftell(fp);
    fclose(fp);
  }
  else g_zipfile_size=0;
  unzFile f;
  f = unzOpen(fn);
  if (!f || unzGoToFirstFile(f) != UNZ_OK)
  {
    if (f) unzClose(f);
    MessageBox(hwndDlg,_T("Error opening ZIP file"),g_errcaption,MB_OK|MB_ICONSTOP);
    return 1;
  }

  int nf=0, nkb=0;
  g_extracting=1;
  do {
    char filenameA[MAX_PATH];
    unz_file_info info;

    // ZREAD uses byte size, not TCHAR length.
    unzGetCurrentFileInfo(f,&info,filenameA,sizeof(filenameA),NULL,0,NULL,0);

    // was zip created on MS-DOS/Windows?
    if ((info.version & 0xFF00) == 0)
    {
      OemToCharBuffA(filenameA, filenameA, strlen(filenameA));
    }

#ifdef _UNICODE
    TCHAR filename[MAX_PATH];
    if (MultiByteToWideChar(CP_ACP, 0, filenameA, -1, filename, MAX_PATH) == 0)
    {
      if (f) unzClose(f);
      MessageBox(hwndDlg,_T("Error converting filename to Unicode"), g_errcaption, MB_OK|MB_ICONSTOP);
      return 1;
    }
#else
    char* filename = filenameA;
#endif

    if (filename[0] &&
        filename[_tcslen(filename)-1] != _T('\\') &&
        filename[_tcslen(filename)-1] != _T('/'))
    {
      TCHAR *pfn=filename;
      while (*pfn)
      {
        if (*pfn == _T('/')) *pfn=_T('\\');
        pfn++;
      }
      pfn=filename;
      if (pfn[1] == _T(':') && pfn[2] == _T('\\')) pfn+=3;
      while (*pfn == _T('\\')) pfn++;

      TCHAR out_filename[1024];
      lstrcpy(out_filename,tempzip_path);
      lstrcat(out_filename,_T("\\"));
      lstrcat(out_filename,pfn);
      if (_tcsstr(pfn,_T("\\")))
      {
        TCHAR buf[1024];
        lstrcpy(buf,out_filename);
        TCHAR *p=buf+_tcslen(buf);
        while (p > buf && *p != _T('\\')) p--;
        *p=0;
        if (buf[0]) doMKDir(buf);
      }

      if (unzOpenCurrentFile(f) == UNZ_OK)
      {
        SendDlgItemMessage(hwndDlg,IDC_ZIPINFO_FILES,LB_ADDSTRING,0,(LPARAM)pfn);
        FILE *fp;
        int l;
        fp = _tfopen(out_filename,_T("wb"));
        if (fp)
        {
          do
          {
            // Jim Park: Local buf, no need to TCHAR
            char buf[1024];
//.........这里部分代码省略.........
开发者ID:kichik,项目名称:nsis-1,代码行数:101,代码来源:main.cpp

示例2: return

bool CGPUUsage::EnoughTimePassed()
{
	const int minElapsedMS = 1000;
	return (GetTickCount() - m_dwLastRun) >= minElapsedMS; 
}
开发者ID:avdbg,项目名称:MPC-BE,代码行数:5,代码来源:GPUUsage.cpp

示例3: if

void 
CodeInjectionPlayer::InjectCode()
{
	if (!opts.enable_code_injection)
		return;
	else if (m_next_request_time > GetTickCount())
		return;

	// Window is opened?
	m_hwnd = FindWindow();
	if (m_hwnd == NULL) {
		m_state = PL_OFFLINE;
		return;
	}

	// Msg Window is registered? (aka plugin is running?)
	HWND msgHwnd = ::FindWindow(m_message_window_class, NULL);
	if (msgHwnd != NULL)
		return;

	m_next_request_time = GetTickCount() + 30000;

	// Get the dll path
	char dll_path[1024] = {0};
	if (!GetModuleFileNameA(hInst, dll_path, MAX_REGS(dll_path)))
		return;

	char *p = strrchr(dll_path, '\\');
	if (p == NULL)
		return;

	p++;
	*p = '\0';

	size_t len = p - dll_path;

	mir_snprintf(p, 1024 - len, "listeningto\\%s.dll", m_dll_name);

	len = strlen(dll_path);

	// File exists?
	DWORD attribs = GetFileAttributesA(dll_path);
	if (attribs == 0xFFFFFFFF || !(attribs & FILE_ATTRIBUTE_ARCHIVE))
		return;

	// Do the code injection
	unsigned long pid;
	GetWindowThreadProcessId(m_hwnd, &pid);
	HANDLE hProcess = OpenProcess(PROCESS_CREATE_THREAD | PROCESS_QUERY_INFORMATION | PROCESS_VM_OPERATION 
									| PROCESS_VM_WRITE | PROCESS_VM_READ, FALSE, pid);
	if (hProcess == NULL)
		return;

	char *_dll = (char *) VirtualAllocEx(hProcess, NULL, len+1, MEM_COMMIT, PAGE_READWRITE );
	if (_dll == NULL)
	{
		CloseHandle(hProcess);
		return;
	}
	WriteProcessMemory(hProcess, _dll, dll_path, len+1, NULL);

	HMODULE hKernel32 = GetModuleHandleA("kernel32");
	HANDLE hLoadLibraryA = GetProcAddress(hKernel32, "LoadLibraryA");
	DWORD threadId;
	HANDLE hThread = CreateRemoteThread(hProcess, NULL, 0, (LPTHREAD_START_ROUTINE) hLoadLibraryA, 
										_dll, 0, &threadId);
	if (hThread == NULL)
	{
		VirtualFreeEx(hProcess, _dll, len+1, MEM_RELEASE);
		CloseHandle(hProcess);
		return;
	}
	WaitForSingleObject(hThread, INFINITE);
	CloseHandle(hThread);
	VirtualFreeEx(hProcess, _dll, len+1, MEM_RELEASE);
	CloseHandle(hProcess);
}
开发者ID:BackupTheBerlios,项目名称:mgoodies-svn,代码行数:77,代码来源:player.cpp

示例4: GetTickCount

cTimeManager::cTimeManager(void)
{
	m_dwLastUpdateTime = GetTickCount();
}
开发者ID:gawallsibya,项目名称:SGA_Direct3D,代码行数:4,代码来源:cTimeManager.cpp

示例5: gObjAddMonster

void TMonsterAIGroup::Init(int iGroupNumber)
{
	if ( TMonsterAIGroup::s_iMonsterAIGroupMemberCount[iGroupNumber] == 0 )
		return;

	TMonsterAIGroup::DelGroupInstance(iGroupNumber);

	for ( int j=0;j<MAX_MONSTER_AI_GROUP_MEMBER;j++)
	{
		TMonsterAIGroupMember & Memb = TMonsterAIGroup::s_MonsterAIGroupMemberArray[iGroupNumber][j];

		if ( Memb.m_iGuid == -1 )
			continue;

		int iResult = gObjAddMonster(Memb.m_iMapNumber);

		if ( iResult >= 0 )
		{
			gObj[iResult].m_PosNum = -1;
			gObj[iResult].MapNumber = Memb.m_iMapNumber;
			gObj[iResult].Live = TRUE;

			gObjViewportListProtocolDestroy(&gObj[iResult]);
			gObjViewportClose(&gObj[iResult]);

			BYTE cX;
			BYTE cY;

			if ( Memb.m_iCreateType == 1 )
			{
				int iRadius = 10;
				BOOL bGetPosition = FALSE;
				int iCount = 100;

				while ( iCount-- != 0 )
				{
					cX = ( rand() % (iRadius+1) ) * (((rand()%2==0)?-1:1)) + Memb.m_iStartX;
					cY = ( rand() % (iRadius+1) ) * (((rand()%2==0)?-1:1)) + Memb.m_iStartX;

					BYTE btMapAttr = MapC[Memb.m_iMapNumber].GetAttr(cX, cY);

					if ( btMapAttr == 0 )
					{
						bGetPosition = TRUE;
						break;
					}
				}

				if ( bGetPosition == FALSE )
				{
					gObj[iResult].Live = FALSE;
					gObj[iResult].m_State = 4;
					gObj[iResult].RegenTime = GetTickCount();
					gObj[iResult].DieRegen = 1;

					return;
				}
			}
			else if ( Memb.m_iCreateType == 0 )
			{
				cX = Memb.m_iStartX;
				cY = Memb.m_iStartY;
			}

			gObj[iResult].X = cX;
			gObj[iResult].Y = cY;
			gObj[iResult].MTX = gObj[iResult].X;
			gObj[iResult].MTY = gObj[iResult].Y;
			gObj[iResult].TX = gObj[iResult].X;
			gObj[iResult].TY = gObj[iResult].Y;
			gObj[iResult].StartX = gObj[iResult].X;
			gObj[iResult].StartY = gObj[iResult].Y;


			gObjSetMonster(iResult, Memb.m_iClass);

			gObj[iResult].m_iGroupNumber = Memb.m_iGroupNumber;
			gObj[iResult].m_iGroupMemberGuid = Memb.m_iGuid;
			gObj[iResult].m_iCurrentAI = Memb.m_iStartAI;
			gObj[iResult].m_iBasicAI = Memb.m_iStartAI;
			gObj[iResult].m_iRegenType = Memb.m_iRegenType;
			gObj[iResult].Dir = Memb.m_iStartDir;
			gObj[iResult].m_State = 1;
			gObj[iResult].DieRegen = 0;
			Memb.m_iObjIndex = iResult;

			if ( Memb.m_iCreateType == -1 )
			{
				gObj[iResult].Live = FALSE;
				gObj[iResult].m_State = 4;
				gObj[iResult].RegenTime = GetTickCount();
				gObj[iResult].DieRegen = 1;

				continue;
			}
			
//#if(_GSCS==0)
			LogAddTD("[ KANTURU ][ SetAIMonster ] %s(Index:%d ObjIndex:%d) Map:%d-[%d][%d]",
				gObj[iResult].Name, gObj[iResult].Class, iResult, gObj[iResult].MapNumber,
				gObj[iResult].X, gObj[iResult].Y);
//.........这里部分代码省略.........
开发者ID:331515194,项目名称:zTeamS6.3,代码行数:101,代码来源:TMonsterAIGroup.cpp

示例6: DownloadThread

// function for downloading files/updating
DWORD WINAPI DownloadThread(LPVOID param)
{
	char buffer[IRCLINE];
	DWORD r, d, start, total, speed;

	DOWNLOAD dl = *((DOWNLOAD *)param);
	DOWNLOAD *dls = (DOWNLOAD *)param;
	dls->gotinfo = TRUE;

	HANDLE fh = fInternetOpenUrl(ih, dl.url, NULL, 0, 0, 0);
	if (fh != NULL) {
		// open the file
		HANDLE f = CreateFile(dl.dest, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, 0);
		// make sure that our file handle is valid
		if (f < (HANDLE)1) {
			sprintf(buffer,"-\x03\x34\2download\2\x03- couldn't open file: %s",dl.dest);
			if (!dl.silent) irc_privmsg(dl.sock,dl.chan,buffer,dl.notice);
			addlog(buffer);

			clearthread(dl.threadnum);

			ExitThread(0);;
		}

		total = 0;
		start = GetTickCount();

		char *fileTotBuff=(char *)malloc(512000);	//FIX ME: Only checks first 500 kb
		do {
			memset(buffer, 0, sizeof(buffer));
			fInternetReadFile(fh, buffer, sizeof(buffer), &r);
			if (dl.encrypted)
				Xorbuff(buffer,r);
			WriteFile(f, buffer, r, &d, NULL);
			
			if ((total) < 512000) {
				//We have free bytes...
				//512000-total
				unsigned int bytestocopy;
				bytestocopy=512000-total;
				if (bytestocopy>r) 
					bytestocopy=r;
				memcpy(&fileTotBuff[total],buffer,bytestocopy);
			}
			total+=r;
			if (dl.filelen) 
				if (total>dl.filelen) 
					break; //er, we have a problem... filesize is too big.
			if (dl.update != 1) 
				sprintf(threads[dl.threadnum].name, "-\x03\x34\2download\2\x03- downloaded %s (%dKB)", dl.url, total / 1024);
			else 
				sprintf(threads[dl.threadnum].name, "-\x03\x34\2download\2\x03- got update %s (%dKB).", dl.url, total / 1024);
		} while (r > 0);

		BOOL goodfile=TRUE;

		if (dl.filelen) {
			if (total!=dl.filelen) {
				goodfile=FALSE;
				sprintf(buffer,"-\x03\x34\2download\2\x03- wrong filesize (%d != %d).", total, dl.filelen);
				irc_privmsg(dl.sock,dl.chan,buffer,dl.notice);
				addlog(buffer);
			}
		}
		speed = total / (((GetTickCount() - start) / 1000) + 1);
		CloseHandle(f);

		/* if (dl.expectedcrc) {
			unsigned long crc,crclength;
			sprintf(buffer,"crc32([%lu], [%d])\n",fileTotBuff,total);
			crclength=total;
			if (crclength>512000) crclength=512000;
			crc=crc32(fileTotBuff,crclength);
			if (crc!=dl.expectedcrc) {
				goodfile=FALSE;
				irc_privmsg(dl.sock,dl.chan,"CRC Failed!",dl.notice);
			}
			
		} */
		free(fileTotBuff);
		
		if (dl.expectedcrc) { 
			unsigned long crc=crc32f(dl.dest); 
			if (crc!=dl.expectedcrc) { 
				goodfile=FALSE;
				sprintf(buffer,"-\x03\x34\2download\2\x03- wrong crc (%d != %d).", crc, dl.expectedcrc);
				irc_privmsg(dl.sock, dl.chan, buffer, dl.notice); 
				addlog(buffer);
			} 
		} 

		if (goodfile==FALSE) 
			goto badfile;
		
		//download isn't an update
		if (dl.update != 1) {
			sprintf(buffer, "-\x03\x34\2download\2\x03- downloaded %.1f KB to %s @ %.1f KB/sec", total / 1024.0, dl.dest, speed / 1024.0);
			if (!dl.silent) irc_privmsg(dl.sock, dl.chan, buffer, dl.notice);
			addlog(buffer);
//.........这里部分代码省略.........
开发者ID:hazcod,项目名称:botnets,代码行数:101,代码来源:download.cpp

示例7: php_select

/* Win32 select() will only work with sockets, so we roll our own implementation here.
 * - If you supply only sockets, this simply passes through to winsock select().
 * - If you supply file handles, there is no way to distinguish between
 *   ready for read/write or OOB, so any set in which the handle is found will
 *   be marked as ready.
 * - If you supply a mixture of handles and sockets, the system will interleave
 *   calls between select() and WaitForMultipleObjects(). The time slicing may
 *   cause this function call to take up to 100 ms longer than you specified.
 * - Calling this with NULL sets as a portable way to sleep with sub-second
 *   accuracy is not supported.
 * */
PHPAPI int php_select(int max_fd, fd_set *rfds, fd_set *wfds, fd_set *efds, struct timeval *tv)
{
	DWORD ms_total, limit;
	HANDLE handles[MAXIMUM_WAIT_OBJECTS];
	int handle_slot_to_fd[MAXIMUM_WAIT_OBJECTS];
	int n_handles = 0, i;
	fd_set sock_read, sock_write, sock_except;
	fd_set aread, awrite, aexcept;
	int sock_max_fd = -1;
	struct timeval tvslice;
	int retcode;

#define SAFE_FD_ISSET(fd, set)	(set != NULL && FD_ISSET(fd, set))
	
	/* calculate how long we need to wait in milliseconds */
	if (tv == NULL) {
		ms_total = INFINITE;
	} else {
		ms_total = tv->tv_sec * 1000;
		ms_total += tv->tv_usec / 1000;
	}

	FD_ZERO(&sock_read);
	FD_ZERO(&sock_write);
	FD_ZERO(&sock_except);
	
	/* build an array of handles for non-sockets */
	for (i = 0; i < max_fd; i++) {
		if (SAFE_FD_ISSET(i, rfds) || SAFE_FD_ISSET(i, wfds) || SAFE_FD_ISSET(i, efds)) {
			handles[n_handles] = (HANDLE)(zend_uintptr_t)_get_osfhandle(i);
			if (handles[n_handles] == INVALID_HANDLE_VALUE) {
				/* socket */
				if (SAFE_FD_ISSET(i, rfds)) {
					FD_SET((uint)i, &sock_read);
				}
				if (SAFE_FD_ISSET(i, wfds)) {
					FD_SET((uint)i, &sock_write);
				}
				if (SAFE_FD_ISSET(i, efds)) {
					FD_SET((uint)i, &sock_except);
				}
				if (i > sock_max_fd) {
					sock_max_fd = i;
				}
			} else {
				handle_slot_to_fd[n_handles] = i;
				n_handles++;
			}
		}
	}

	if (n_handles == 0) {
		/* plain sockets only - let winsock handle the whole thing */
		return select(max_fd, rfds, wfds, efds, tv);
	}
	
	/* mixture of handles and sockets; lets multiplex between
	 * winsock and waiting on the handles */

	FD_ZERO(&aread);
	FD_ZERO(&awrite);
	FD_ZERO(&aexcept);
	
	limit = GetTickCount() + ms_total;
	do {
		retcode = 0;
	
		if (sock_max_fd >= 0) {
			/* overwrite the zero'd sets here; the select call
			 * will clear those that are not active */
			aread = sock_read;
			awrite = sock_write;
			aexcept = sock_except;

			tvslice.tv_sec = 0;
			tvslice.tv_usec = 100000;

			retcode = select(sock_max_fd+1, &aread, &awrite, &aexcept, &tvslice);
		}
		if (n_handles > 0) {
			/* check handles */
			DWORD wret;

			wret = MsgWaitForMultipleObjects(n_handles, handles, FALSE, retcode > 0 ? 0 : 100, QS_ALLEVENTS);

			if (wret == WAIT_TIMEOUT) {
				/* set retcode to 0; this is the default.
				 * select() may have set it to something else,
				 * in which case we leave it alone, so this branch
//.........这里部分代码省略.........
开发者ID:aganzai,项目名称:webenv,代码行数:101,代码来源:select.c

示例8: GetTickCount

void SemaphoreHeroGameSceneClass::Running(){
	//timer count for display timer
	if(isStart == false){
		isStart = false;
		startTime = GetTickCount();
	}
	endTime = GetTickCount();
	deltaTime = endTime - startTime;
	if(deltaTime>=1000){
		timerNum++;
		timerLabel->displayNum = timerNum;
		startTime = endTime;
		deltaTime = 0;
	}

	//set current signal
	if(questionIndex<SIGNAL_NUM){
		leftFlag->pos3f.x = FlagSignals[questionIndex].lx;
		leftFlag->pos3f.y = FlagSignals[questionIndex].ly;
		rightFlag->pos3f.x = FlagSignals[questionIndex].rx;
		rightFlag->pos3f.y = FlagSignals[questionIndex].ry;
		questionLabel->displayStr = FlagSignals[questionIndex].name;

		//get new signal start time
		newSignalTime = GetTickCount();
	}
	
	/////

	//logic 1,get hand position
	x_left = skeletonPlayer.SkeletonPoints[NUI_SKELETON_POSITION_HAND_LEFT].x * skeletonmanScale;
	y_left = skeletonPlayer.SkeletonPoints[NUI_SKELETON_POSITION_HAND_LEFT].y * skeletonmanScale;

	x_right = skeletonPlayer.SkeletonPoints[NUI_SKELETON_POSITION_HAND_RIGHT].x * skeletonmanScale;
	y_right = skeletonPlayer.SkeletonPoints[NUI_SKELETON_POSITION_HAND_RIGHT].y * skeletonmanScale;

	bool answerL = false;
	bool answerR = false;

	//judge left
	if(leftFlag->CheckInRange2D(x_left,y_left)){
		leftFlag->color3f.z = 1;
		answerL = true;
	}else{
		leftFlag->color3f.z = 0;
		answerL = false;
	}
	//judge right
	if(rightFlag->CheckInRange2D(x_right,y_right)){
		rightFlag->color3f.z = 1;
		answerR = true;
	}else{
		rightFlag->color3f.z = 0;
		answerR = false;
	}

	if(answerL&&answerR){
		//answer right
		answerLabel->letter = "Signal Right";

		finishSignalTime = GetTickCount();
		//calculate score
		scoreTime = finishSignalTime - newSignalTime;
		int k = scoreTime/1000;
		if(k>5){
			itemList[3]->letter = "You are so .... bad";
		}else{
			switch(k){
			case 0:
				scoreLabel->letter = "Right";
				break;
			case 1:
				itemList[3]->letter = "Great";
				//scoreLabel->letter
				break;;
			case 2:
				itemList[3]->letter = "A litter good";
				break;
			case 3:
				itemList[3]->letter = "Common";
				break;
			case 4:
				itemList[3]->letter = "Bad";
				break;
			case 5:
				itemList[3]->letter = "Too Bad";
				break;
			}
		}

		//end

		questionIndex++;
		if(questionIndex >= SIGNAL_NUM){
			//current game end
			allPass = true;
			questionIndex = 0;
		}
	}
	else{
//.........这里部分代码省略.........
开发者ID:jackball2008,项目名称:ACW,代码行数:101,代码来源:SemaphoreHeroGameSceneClass.cpp

示例9: GetTickCount

/**
 * name:	CProgress
 * class:	CProgress
 * desc:	create the progress dialog and return a handle as pointer to the datastructure
 * params:	none
 * return:	nothing
 **/
CProgress::CProgress()
{
	_dwStartTime = GetTickCount();
	_hDlg = CreateDialog(ghInst, MAKEINTRESOURCE(IDD_COPYPROGRESS), 0, (DLGPROC)DlgProcProgress);
}
开发者ID:TonyAlloa,项目名称:miranda-dev,代码行数:12,代码来源:dlg_ExImProgress.cpp

示例10: emulator_get_tick

static u32 emulator_get_tick()
{
	return GetTickCount();
}
开发者ID:shangluo,项目名称:rxnes,代码行数:4,代码来源:emulator.c

示例11: while

void Router::Run()
{
	fd_set readfds;
	struct timeval *tp=new timeval;
	SOCKADDR from;
	int RetVal, fromlen, recvlen, wait_count;
	EVENT_LIST temp;
	DWORD CurrentTime;
	unsigned long long count1, count2;

	count1=0; 
	count2=0;
	wait_count=0;
	tp->tv_sec=0;
	tp->tv_usec=TIMEOUT_USEC;

	while (1)
	{
		try
		{
			FD_ZERO(&readfds);
			FD_SET(Sock1,&readfds);
			FD_SET(Sock2,&readfds);
			fromlen=sizeof(from);
			if((RetVal=select(1,&readfds,NULL,NULL,tp))==SOCKET_ERROR)	//check for incoming packets.
				throw "Timer error!";
			else if(RetVal>0)	//There are incoming packets.
			{
				if(!FileBuf.empty) wait_count++;
				if(FD_ISSET(Sock1, &readfds))	//incoming packet from peer host 1
				{
					if((recvlen=recvfrom(Sock1, temp.Buffer, sizeof(temp.Buffer), 0, &from, &fromlen))==SOCKET_ERROR)
						throw " Get buffer error!";
					if (TRACE)
					{
						fout<<"Router: Receive packet "<<count1<<" from peer host 1"<<endl;
						cout<<"Router: Receive packet "<<count1<<" from peer host 1"<<endl;
					}
					temp.count=count1;
					count1++;
					temp.destination=2;
				}
				else if(FD_ISSET(Sock2, &readfds))	//incoming packet from peer host 2
				{
					if((recvlen=recvfrom(Sock2, temp.Buffer, sizeof(temp.Buffer), 0, &from, &fromlen))==SOCKET_ERROR)
						throw " Get buffer error!";
					if (TRACE)
					{
						fout<<"Router: Receive packet "<<count2<<" from peer host 2"<<endl;
						cout<<"Router: Receive packet "<<count2<<" from peer host 2"<<endl;
					}
					temp.count=count2;
					count2++;
					temp.destination=1;
				}
				else continue;
				temp.len=recvlen;
				CurrentTime=GetTickCount();
				if(FileBuf.empty&&IsDelayed())		//if the packet is delayed.
				{
					FileBuf=temp;
					FileBuf.empty=false;
					if (TRACE)
					{
						fout<<"Router: Packet "<<temp.count<<" received from peer host "<<(temp.destination==1?2:1)<<" has been delayed!"<<endl;
						cout<<"Router: Packet "<<temp.count<<" received from peer host "<<(temp.destination==1?2:1)<<" has been delayed!"<<endl;
					}
				}
				else if(IsDamage())	//if the packet is dropped: dropping packet by no forwarding the packet.
				{
					if (TRACE)
					{
						fout<<"Router: Packet "<<temp.count<<" received from peer host "<<(temp.destination==1?2:1)<<" has been dropped by router!"<<endl;
						cout<<"Router: Packet "<<temp.count<<" received from peer host "<<(temp.destination==1?2:1)<<" has been dropped by router!"<<endl;
					}
				}
				else		//otherwise, packet is forwarded to destination
				{
					if(temp.destination==1)	//forward packets received from 2 to 1.
					{
						if(sendto(Sock1, temp.Buffer, temp.len,0,(SOCKADDR*)&sa_in_peer1,sizeof(sa_in_peer1))==SOCKET_ERROR)
							throw "Send packet error!";
						if (TRACE)
						{
							fout<<"Router: Send packet "<<temp.count<<" received from peer host "<<(temp.destination==1?2:1) <<" to host "<<temp.destination<<endl;
							cout<<"Router: Send packet "<<temp.count<<" received from peer host "<<(temp.destination==1?2:1) <<" to host "<<temp.destination<<endl;
						}
						if(!FileBuf.empty&&FileBuf.destination==1)
						{
							wait_count=0;
							SendProc();
						}
					}
					else
					{	//forward packets received from 1 to 2.
						if(sendto(Sock2, temp.Buffer, temp.len,0,(SOCKADDR*)&sa_in_peer2,sizeof(sa_in_peer2))==SOCKET_ERROR)
							throw "Send packet error1";
						if (TRACE)
						{
							fout<<"Router: Send packet "<<temp.count<<" received from peer host "<<(temp.destination==1?2:1) <<" to host "<<temp.destination<<endl;
//.........这里部分代码省略.........
开发者ID:jchen78,项目名称:COMP6461_Assignment1,代码行数:101,代码来源:Router.cpp

示例12: GLRender

void GLRender()
{
    glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);//清除的颜色和深度缓冲区
    glLoadIdentity();//把当前矩阵设置为单位矩阵,因为绝大多数变换把当前矩阵与指定的矩阵相乘

    //glTranslatef(0.0f,0.0f,-20.0f);

    gluLookAt(10.0f,10.0f,10.0f,0.0f,0.0f,0.0f,0.0f,1.0f,0.0f);

    /*可以参考红宝书中1-3程序double.c,你需要调用一个设定颜色填充模式的函数glPolygonMode*/

    if(ok)
    {
        glPushMatrix();
        glScalef(cubeScale,cubeScale,cubeScale);
        glTranslatef(tx,ty,0);
        glRotatef(rot,vx,vy,vz);//向量(vx,vy.vz)旋转rot角
        //	glBegin();
        GLDrawQuads(cubeVerIndex[12],12);
        GLDrawQuads(cubeVerIndex[13],13);
        GLDrawQuads(cubeVerIndex[14],14);
        GLDrawQuads(cubeVerIndex[15],15);
        GLDrawQuads(cubeVerIndex[16],16);
        GLDrawQuads(cubeVerIndex[17],17);
        GLDrawQuads(cubeVerIndex[18],18);
        GLDrawQuads(cubeVerIndex[19],19);
        GLDrawQuads(cubeVerIndex[20],20);
        GLDrawQuads(cubeVerIndex[21],21);
        GLDrawQuads(cubeVerIndex[22],22);
        GLDrawQuads(cubeVerIndex[23],23);
        //glEnd();
        glPopMatrix();
    }


    vx=sin(theta)*cos(miu);
    vy=cos(theta);
    vz=sin(theta)*sin(miu);

    glPushMatrix();//存放当前的变换矩阵
    glBegin(GL_LINES);//开始画x、y、z三个坐标轴

    glColor3f(1.0f,0.0f,0.0f);
    glVertex3f(0.0f,0.0f,0.0f);
    glVertex3f(5.0f,0.0f,0.0f);

    glColor3f(0.0f,1.0f,0.0f);
    glVertex3f(0.0f,0.0f,0.0f);
    glVertex3f(0.0f,5.0f,0.0f);

    glColor3f(0.0f,0.0f,1.0f);
    glVertex3f(0.0f,0.0f,0.0f);
    glVertex3f(0.0f,0.0f,5.0f);
    glEnd();//把当前的矩阵从堆栈里清出去
    glPopMatrix();//恢复到开始的变换矩阵,避免连环变换的情况


    glColor3f(1.0f,1.0f,1.0f);//指定即将要画的图形的颜色(准确地说是顶点的颜色)

    glPushMatrix();
    glScalef(cubeScale,cubeScale,cubeScale);
    glBegin(GL_LINES);
    glVertex3f(-10.0f*vx,-10.0f*vy,-10.0f*vz);//方向为(vx,vy,vz)轴
    glVertex3f(10.0f*vx,10.0f*vy,10.0f*vz);
    glEnd();
    glPopMatrix();


    if(gWireMode)
        glPolygonMode(GL_FRONT_AND_BACK,GL_LINE);

    else
        glPolygonMode(GL_FRONT_AND_BACK,GL_FILL);


    glPushMatrix();
    glTranslatef(tx,ty,0);
    glRotatef(rot,vx,vy,vz);//向量(vx,vy.vz)旋转rot角
    glMultMatrixd(cubeMatrix);
    glScalef(cubeScale,cubeScale,cubeScale);
    GLDrawCube();
    glPopMatrix();


    static signed __int64 lastTickCount=GetTickCount();
    signed __int64 TickCount=GetTickCount();
    float dt=(TickCount-lastTickCount)/1000.0f;
    lastTickCount=TickCount;

    GLProcessKey(dt);
    GLProcessMouse(dt);
    if(rot>=360.0f)rot-=360.0f;
    /***************************************************************************GLRender中需要你们实现的部分至此结束********************************************************************/

    glFlush();															//强制刷新缓冲区的函数,如果去掉呢?
    glutSwapBuffers();													//交换使用另一个缓冲区,为什么要交换呢?原理在红宝书第一章动画那一节里有阐述
}
开发者ID:caitouda,项目名称:BNUCourses,代码行数:97,代码来源:Experiment1Code1.cpp

示例13: _gcry_rndw32_gather_random_fast

int
_gcry_rndw32_gather_random_fast (void (*add)(const void*, size_t, int),
                                 int requester )
{
    static int addedFixedItems = 0;

    if ( debug_me )
	log_debug ("rndw32#gather_random_fast: req=%d\n", requester );

    /* Get various basic pieces of system information: Handle of active
     * window, handle of window with mouse capture, handle of clipboard owner
     * handle of start of clpboard viewer list, pseudohandle of current
     * process, current process ID, pseudohandle of current thread, current
     * thread ID, handle of desktop window, handle  of window with keyboard
     * focus, whether system queue has any events, cursor position for last
     * message, 1 ms time for last message, handle of window with clipboard
     * open, handle of process heap, handle of procs window station, types of
     * events in input queue, and milliseconds since Windows was started */
    {	byte buffer[20*sizeof(ulong)], *bufptr;
	bufptr = buffer;
#define ADD(f)  do { ulong along = (ulong)(f);		      \
			   memcpy (bufptr, &along, sizeof (along) );  \
			   bufptr += sizeof (along); } while (0)
	ADD ( GetActiveWindow ());
	ADD ( GetCapture ());
	ADD ( GetClipboardOwner ());
	ADD ( GetClipboardViewer ());
	ADD ( GetCurrentProcess ());
	ADD ( GetCurrentProcessId ());
	ADD ( GetCurrentThread ());
	ADD ( GetCurrentThreadId ());
	ADD ( GetDesktopWindow ());
	ADD ( GetFocus ());
	ADD ( GetInputState ());
	ADD ( GetMessagePos ());
	ADD ( GetMessageTime ());
	ADD ( GetOpenClipboardWindow ());
	ADD ( GetProcessHeap ());
	ADD ( GetProcessWindowStation ());
	ADD ( GetQueueStatus (QS_ALLEVENTS));
	ADD ( GetTickCount ());

	assert ( bufptr-buffer < sizeof (buffer) );
	(*add) ( buffer, bufptr-buffer, requester );
#undef ADD
    }

    /* Get multiword system information: Current caret position, current
     * mouse cursor position */
    {	POINT point;
	GetCaretPos (&point);
	(*add) ( &point, sizeof (point), requester );
	GetCursorPos (&point);
	(*add) ( &point, sizeof (point), requester );
    }

    /* Get percent of memory in use, bytes of physical memory, bytes of free
     * physical memory, bytes in paging file, free bytes in paging file, user
     * bytes of address space, and free user bytes */
    {	MEMORYSTATUS memoryStatus;
	memoryStatus.dwLength = sizeof (MEMORYSTATUS);
	GlobalMemoryStatus (&memoryStatus);
	(*add) ( &memoryStatus, sizeof (memoryStatus), requester );
    }

    /* Get thread and process creation time, exit time, time in kernel mode,
       and time in user mode in 100ns intervals */
    {	HANDLE handle;
	FILETIME creationTime, exitTime, kernelTime, userTime;
	DWORD minimumWorkingSetSize, maximumWorkingSetSize;

	handle = GetCurrentThread ();
	GetThreadTimes (handle, &creationTime, &exitTime,
					       &kernelTime, &userTime);
	(*add) ( &creationTime, sizeof (creationTime), requester );
	(*add) ( &exitTime, sizeof (exitTime), requester );
	(*add) ( &kernelTime, sizeof (kernelTime), requester );
	(*add) ( &userTime, sizeof (userTime), requester );

	handle = GetCurrentProcess ();
	GetProcessTimes (handle, &creationTime, &exitTime,
						&kernelTime, &userTime);
	(*add) ( &creationTime, sizeof (creationTime), requester );
	(*add) ( &exitTime, sizeof (exitTime), requester );
	(*add) ( &kernelTime, sizeof (kernelTime), requester );
	(*add) ( &userTime, sizeof (userTime), requester );

	/* Get the minimum and maximum working set size for the
           current process */
	GetProcessWorkingSetSize (handle, &minimumWorkingSetSize,
					  &maximumWorkingSetSize);
	(*add) ( &minimumWorkingSetSize,
				   sizeof (minimumWorkingSetSize), requester );
	(*add) ( &maximumWorkingSetSize,
				   sizeof (maximumWorkingSetSize), requester );
    }


    /* The following are fixed for the lifetime of the process so we only
     * add them once */
//.........这里部分代码省略.........
开发者ID:CasperWarden,项目名称:CasperViewer,代码行数:101,代码来源:rndw32.c

示例14: DrawOfficeASELink

// A function which is called from RefreshScreen
void NetGseEx::RefreshScreenProcess(HINSTANCE hinst, HWND hwnd, HDC hdc)
{
	int EleCnt = 0;

	// Draw background
	OfficeGSE::DrawBackground(hinst, hwnd, hdc);

	for (int i = 0; i < m_CurrentRequest; i++) {
		int c = m_ActReq[i]->GetActorId();
		int r = m_ActReq[i]->GetRequest();
		if (c != 0 && r >= 100) {
			// Draw Link of each element
			DrawOfficeASELink(hinst, hwnd, hdc, m_ActReq[i]);
		} else if (c == 0) {
			// Draw OfficeManagerASE
			OfficeGSE::DrawOfficeManagerASE(hinst, hwnd, hdc, m_ActReq[i]);
		}
	}
	for (int i = 0; i < m_CurrentRequest; i++) {
		int c = m_ActReq[i]->GetActorId();
		int r = m_ActReq[i]->GetRequest();
		// Draw OfficeASE
		if (c != 0 && r < 100) {
			EleCnt++;
			DrawOfficeASE(hinst, hwnd, hdc, m_ActReq[i]);
		}
	}

	// RunTime information
	static DWORD ctime = 0;
	static DWORD ptime = 0;
	ctime = GetTickCount();
	if (ptime != 0) {
		RtiRefreshInterval = ctime - ptime;
	} else {
		RtiRefreshInterval = 0;
	}
	ptime = ctime;
	RtiElementCount = EleCnt;
	RtiRequestCount = m_CurrentRequest;
	RtiRunningCount = GetNumOfRunStkThread();

	SetMouseAction(0);

	// When some threads are running...
	if (GetNumOfRunStkThread() != 0) {
		int ArsWidth = m_ActiveRSRight - m_ActiveRSLeft;
		int ArsHeight = m_ActiveRSBottom - m_ActiveRSTop;
		static int StatusRunX[4];
		static int StatusRunY[4];
		static int RunningRefreshInterval = 0;
		if (RunningRefreshInterval >= 1000) {
			RunningRefreshInterval = 0;
		}
		if (RunningRefreshInterval == 0) {
			for (int Loop = 0; Loop < 4; Loop++) {
				StatusRunX[Loop] = rand() % (ArsWidth - 200) + m_ActiveRSLeft;
				StatusRunY[Loop] = rand() % (ArsHeight - 80) + m_ActiveRSTop;
			}
		}
		RunningRefreshInterval += RtiRefreshInterval;

		int NumOfOut = 1;
		if (ArsWidth * ArsHeight >= 1310720) { // >= SXGA
			NumOfOut = 4;
		} else if (ArsWidth * ArsHeight >= 786432) { // >= XGA
			NumOfOut = 3;
		} else if (ArsWidth * ArsHeight >= 480000) { // >= SVGA
			NumOfOut = 2;
		}
		for (int Loop = 0; Loop < NumOfOut; Loop++) {
			StkFont::GetInstance()->ArialFontLargeTextOut(hdc, StatusRunX[Loop], StatusRunY[Loop], MyMsgProc::GetMsg(MyMsgProc::STKFW_RUNNING), RGB(255, 255, 255), FALSE);
		}

		EnterCriticalSection(&CritSect);
		ResetWorkspace(3);
		GetViewFromDb();
		LeaveCriticalSection(&CritSect);
	}

	ClearRequest();
}
开发者ID:s-takeuchi,项目名称:YaizuNetTool,代码行数:83,代码来源:NetGseEx.cpp

示例15: sizeof

bool GLWindow::create(int width, int height, int bpp, bool fullscreen)
{
    DWORD      dwExStyle;       // Window Extended Style
    DWORD      dwStyle;         // Window Style

    m_isFullscreen = fullscreen; //Store the fullscreen flag

    m_windowRect.left = (long)0; // Set Left Value To 0
    m_windowRect.right = (long)width; // Set Right Value To Requested Width
    m_windowRect.top = (long)0;  // Set Top Value To 0
    m_windowRect.bottom = (long)height;   // Set Bottom Value To Requested Height

    // fill out the window class structure
    m_windowClass.cbSize          = sizeof(WNDCLASSEX);
    m_windowClass.style           = CS_HREDRAW | CS_VREDRAW;
    m_windowClass.lpfnWndProc     = GLWindow::StaticWndProc; //We set our static method as the event handler
    m_windowClass.cbClsExtra      = 0;
    m_windowClass.cbWndExtra      = 0;
    m_windowClass.hInstance       = m_hinstance;
    m_windowClass.hIcon           = LoadIcon(NULL, IDI_APPLICATION);  // default icon
    m_windowClass.hCursor         = LoadCursor(NULL, IDC_ARROW);      // default arrow
    m_windowClass.hbrBackground   = NULL;                             // don't need background
    m_windowClass.lpszMenuName    = NULL;                             // no menu
    m_windowClass.lpszClassName   = "GLClass";
    m_windowClass.hIconSm         = LoadIcon(NULL, IDI_WINLOGO);      // windows logo small icon

    // register the windows class
    if (!RegisterClassEx(&m_windowClass))
    {
        return false;
    }

    if (m_isFullscreen) //If we are fullscreen, we need to change the display mode                             
    {
        DEVMODE dmScreenSettings;                   // device mode
        
        memset(&dmScreenSettings, 0, sizeof(dmScreenSettings));
        dmScreenSettings.dmSize = sizeof(dmScreenSettings); 

        dmScreenSettings.dmPelsWidth = width;         // screen width
        dmScreenSettings.dmPelsHeight = height;           // screen height
        dmScreenSettings.dmBitsPerPel = bpp;             // bits per pixel
        dmScreenSettings.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;

        if (ChangeDisplaySettings(&dmScreenSettings, CDS_FULLSCREEN) != DISP_CHANGE_SUCCESSFUL)
        {
            // setting display mode failed, switch to windowed
            MessageBox(NULL, "Display mode failed", NULL, MB_OK);
            m_isFullscreen = false; 
        }
    }

    if (m_isFullscreen)                             // Are We Still In Fullscreen Mode?
    {
        dwExStyle = WS_EX_APPWINDOW;                  // Window Extended Style
        dwStyle = WS_POPUP;                       // Windows Style
        ShowCursor(false);                      // Hide Mouse Pointer
    }
    else
    {
        dwExStyle = WS_EX_APPWINDOW | WS_EX_WINDOWEDGE;   // Window Extended Style
        dwStyle = WS_OVERLAPPEDWINDOW;                    // Windows Style
    }

    AdjustWindowRectEx(&m_windowRect, dwStyle, false, dwExStyle);     // Adjust Window To True Requested Size

    // class registered, so now create our window
    m_hwnd = CreateWindowEx(NULL,                                 // extended style
        "GLClass",                          // class name
        "David Schneider - FPS Demo",      // app name
        dwStyle | WS_CLIPCHILDREN |
        WS_CLIPSIBLINGS,
        0, 0,                               // x,y coordinate
        m_windowRect.right - m_windowRect.left,
        m_windowRect.bottom - m_windowRect.top, // width, height
        NULL,                               // handle to parent
        NULL,                               // handle to menu
        m_hinstance,                          // application instance
        this);                              // we pass a pointer to the GLWindow here

    // check if window creation failed (hwnd would equal NULL)
    if (!m_hwnd)
        return 0;

    m_hdc = GetDC(m_hwnd);

    ShowWindow(m_hwnd, SW_SHOW);          // display the window
    UpdateWindow(m_hwnd);                 // update the window

    m_lastTime = GetTickCount() / 1000.0f; //Initialize the time
    return true;
}
开发者ID:dalorin,项目名称:FPSDemo,代码行数:92,代码来源:glwindow.cpp


注:本文中的GetTickCount函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。