⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 hqdest.c

📁 站长96年写的一个Internet上用的股票行情、分析、交易、资讯程序源码
💻 C
📖 第 1 页 / 共 2 页
字号:
		if(!lpDestTmp) break;		if(!LockDest(lpDestTmp,10)) return ;		lpDestNext =lpDestTmp->lpNext;		if(!LockDest(lpDestNext,10)) return ;		if(lpDestTmp->isDead)		{			lpDestTmp->isDead =TRUE;			if(lpDestTmp ==dest_infos.lpDestHead)				dest_infos.lpDestHead =lpDestNext;			else lpDestPrev->lpNext =lpDestNext;			GlobalUnlock(GlobalHandle(lpDestTmp->params));			GlobalFree(GlobalHandle(lpDestTmp->params));			lpDestTmp->paramsCount =0;			if(lpDestTmp->lpCjss)			{                               				GlobalUnlock(GlobalHandle(lpDestTmp->lpCjss));				GlobalFree(GlobalHandle(lpDestTmp->lpCjss));			}			lpDestTmp->lpCjss =NULL;			if(lpDestTmp->lpGraph)			{				GlobalUnlock(GlobalHandle(lpDestTmp->lpGraph));				GlobalFree(GlobalHandle(lpDestTmp->lpGraph));			}			lpDestTmp->lpGraph =NULL;			if(lpDestTmp->lpZsGraph)			{				GlobalUnlock(GlobalHandle(lpDestTmp->lpZsGraph));				GlobalFree(GlobalHandle(lpDestTmp->lpZsGraph));			}			lpDestTmp->lpZsGraph =NULL;			count++;		}		else			lpDestPrev =lpDestTmp;		UnlockDest(lpDestTmp);		UnlockDest(lpDestNext);		lpDestTmp =lpDestNext;	}	dest_infos.destCount -=count;}void FreeDest(void){	LPDEST_INFO lpDestTmp;	int i;	for(i =0; i<MAX_USER_COUNT; i++)	{		lpDestTmp =&dest_info[i];       		if(lpDestTmp ==NULL) 			continue;		if(lpDestTmp->params)		{			GlobalUnlock(GlobalHandle(lpDestTmp->params));			GlobalFree(GlobalHandle(lpDestTmp->params));		}		if(lpDestTmp->lpCjss) 		{			GlobalUnlock(GlobalHandle(lpDestTmp->lpCjss));			GlobalFree(GlobalHandle(lpDestTmp->lpCjss));		}		if(lpDestTmp->lpGraph)		{			GlobalUnlock(GlobalHandle(lpDestTmp->lpGraph));			GlobalFree(GlobalHandle(lpDestTmp->lpGraph));		}		if(lpDestTmp->lpZsGraph)		{			GlobalUnlock(GlobalHandle(lpDestTmp->lpZsGraph));			GlobalFree(GlobalHandle(lpDestTmp->lpZsGraph));		}	}	dest_info_count =0;}int check_socket_status(int sd){	struct timeval wait;	fd_set send_ready,except;	wait.tv_sec =wait.tv_usec=0;	FD_ZERO(&send_ready);	FD_ZERO(&except);	FD_SET(sd,&send_ready);	FD_SET(sd,&except);	if(select(FD_SETSIZE,(fd_set *)0,&send_ready,			&except,&wait)<0)		return(-1);	if(FD_ISSET(sd,&send_ready))		return(0);	else if(FD_ISSET(sd,&except))		return(-2);	else		return(-3);}long TF_ScanDest(void){	int i,j,ret,jys;	LPDEST_INFO lpDestNext;	DP_MAIN DpMain[2];	while(1)	{		if(run_cancelled) break;		if(IsClectRun)		{			if(clCheckTime(TRUE) >=0)			{				if(HqTime[0].fRunning)				{					if(!RefreshHqData(0))					{						MsgLocal("深圳行情刷新失败,重新启动");						HqTime[0].fRunning =FALSE;						CloseDbfFile(0);					}					CreateLzwMemData(0);				}				if(HqTime[1].fRunning)  				{					if(!RefreshHqData(1))					{						MsgLocal("上海行情刷新失败,重新启动");						HqTime[1].fRunning =FALSE;						CloseDbfFile(1);                                					}					CreateLzwMemData(1);				}			}       		}		else		{			RefreshHq(0);			RefreshHq(1);		}		MsgLocal("扫描行情用户...");		for(i =0,j=0; i<dest_info_count; i++)		{			if(run_cancelled) break;			lpDestNext=&dest_info[i];			if(!lpDestNext) 				break;			if(lpDestNext->isDead)				continue;			lpDestNext->inactive++;			ret =check_socket_status(lpDestNext->sd);			if(ret ==0)			{				if(!xLockDest(lpDestNext,3))					continue;				switch(lpDestNext->reqType)				{				case REQ_HQ01:					Delay_Send_Hq01(lpDestNext);					UnlockDest(lpDestNext);				break;				case REQ_HQ10:					if(lpDestNext->version <12)					{						ret =UDP_Server_Send_Hq10(lpDestNext);						UnlockDest(lpDestNext);					}					if(lpDestNext->version ==12)						ret =Send_Hq10(lpDestNext);					if(ret<0) continue;					break;				case REQ_GRA10:					if(lpDestNext->version <12)					{						ret =UDP_Server_Send_Gra10(lpDestNext);						UnlockDest(lpDestNext);					}					if(lpDestNext->version ==12)						ret =Send_Gra10(lpDestNext);					if(ret<0) continue;					break;				default:					UnlockDest(lpDestNext);					break;				}       			//}			    FillDpMain(&DpMain[0]);			//if(ret ==0)			//{				if(memcmp(&lpDestNext->DpData, &DpMain, sizeof(DpMain))||					lpDestNext->inactive>10)				{					if(UDP_Server_Send_Dp(lpDestNext->sd,NULL, FALSE,lpDestNext) >0)						memcpy(&lpDestNext->DpData, &DpMain, sizeof(DpMain));                   					if(lpDestNext->inactive>10)						lpDestNext->inactive =0;				}			}			else			{				if(ret == -2) HqDestStopBySd(lpDestNext->sd);			}			j++;		}		SetHqUsers(j);		Sleep(2000);	}	if(IsClectRun)	{		for(jys =0;jys<2;jys++)		{			WriteHqData(jys);			WriteMmpData(jys);			WriteMaxMinData(jys);			WriteDpData(jys);		}		SetEvent(g_hEventDataWrite);	}	ExitThread(0);	return 0;}int CreateScanDestThread(void){      LONG lThreadId;		hThrdScanDest =CreateThread(NULL, 0,	      (LPTHREAD_START_ROUTINE)TF_ScanDest,	      NULL, CREATE_SUSPENDED, (LPDWORD)&lThreadId);	if(!hThrdScanDest) return -1;	//SetThreadPriority(hThrdScanDest, THREAD_PRIORITY_NORMAL);	SetThreadPriority(hThrdScanDest, THREAD_PRIORITY_ABOVE_NORMAL);	ResumeThread(hThrdScanDest);		return 0;}int FillDpMain(LPDP_MAIN lpDpMain){	int jys;	for(jys =0; jys<2; jys++)	{		lpDpMain[jys].zs =DpData[jys].zs[0];		lpDpMain[jys].zd =DpData[jys].zd[0];		lpDpMain[jys].cjzje =DpData[jys].cjzje;		lpDpMain[jys].npbl =DpData[jys].npbl;		lpDpMain[jys].cjss =DpData[jys].cjss;		lpDpMain[jys].upCount =DpData[jys].upCount;		lpDpMain[jys].downCount =DpData[jys].downCount;		lpDpMain[jys].equalCount =DpData[jys].equalCount;	}		return 0;}extern BOOL FileTranLock;BOOL GetNewsIndex(char * szNewsDir){	HFILE hFile;	OFSTRUCT os;	char file[80],search[128],content[200];    WIN32_FIND_DATA FindData;    HANDLE hFindFile;	BOOL fFind;	SYSTEMTIME SysTime;	BOOL ret =FALSE;	sprintf(file,"%s\\news.idx",szDataPath);	hFile =OpenFile(file, &os, OF_SHARE_DENY_READ|OF_WRITE|OF_CREATE);	if(hFile ==HFILE_ERROR) 		return ret;	sprintf(search,"%s\\*.*",szNewsDir);	hFindFile =FindFirstFile(search,&FindData);	if(hFindFile!=INVALID_HANDLE_VALUE)	{		FileTimeToSystemTime((FILETIME *)&FindData.ftLastWriteTime,			(SYSTEMTIME*)&SysTime);		sprintf(content,"%12s %ld.%02ld.%02ld %02ld.%02ld:%02ld %ld\n",			FindData.cFileName,			SysTime.wYear,			SysTime.wMonth,			SysTime.wDay,			SysTime.wHour,			SysTime.wMinute,			SysTime.wSecond,			FindData.nFileSizeLow +FindData.nFileSizeHigh *256);		if(FindData.dwFileAttributes!=FILE_ATTRIBUTE_DIRECTORY) 		{			_lwrite(hFile,content,strlen(content));			ret =TRUE;		}		do		{			fFind =FindNextFile(hFindFile,&FindData);			if(fFind)			{				FileTimeToSystemTime((FILETIME *)&FindData.ftLastWriteTime,					(SYSTEMTIME*)&SysTime);				sprintf(content,"%12s %ld.%02ld.%02ld %02ld.%02ld:%02ld %ld\n",					FindData.cFileName,					SysTime.wYear,					SysTime.wMonth,					SysTime.wDay,					SysTime.wHour,					SysTime.wMinute,					SysTime.wSecond,					FindData.nFileSizeLow +FindData.nFileSizeHigh *256);                    				if(FindData.dwFileAttributes!=FILE_ATTRIBUTE_DIRECTORY) 				{					_lwrite(hFile,content,strlen(content));					ret =TRUE;				}			}		}while(fFind);		FindClose(hFindFile);	}	_lclose(hFile);	return ret;}void DelNews(LPSTR szNewsDir){	char file[128],search[128];    WIN32_FIND_DATA FindData;    HANDLE hFindFile;	BOOL fFind;	sprintf(search,"%s\\*.*",szNewsDir);	hFindFile =FindFirstFile(search,&FindData);	if(hFindFile!=INVALID_HANDLE_VALUE)	{		sprintf(file,"%s\\%s",szNewsDir,FindData.cFileName);		if(FindData.dwFileAttributes!=FILE_ATTRIBUTE_DIRECTORY) 				DeleteFile(file);		do		{			fFind =FindNextFile(hFindFile,&FindData);			if(fFind)			{				sprintf(file,"%s\\%s",szNewsDir,FindData.cFileName);				if(FindData.dwFileAttributes!=FILE_ATTRIBUTE_DIRECTORY) 					DeleteFile(file);			}		}while(fFind);		FindClose(hFindFile);	}}void MoveNews(LPSTR szNewsTo,LPSTR szNewsFrom){	char to[128],search[128],from[128],temp[128];    WIN32_FIND_DATA FindData;    HANDLE hFindFile;	BOOL fFind;	OFSTRUCT os;	SYSTEMTIME CurDate,FileDate;	if(szNewsTo[0]==0||szNewsFrom[0]==0) 		return;	GetSystemTime(&CurDate);	sprintf(search,"%s\\*.*",szNewsFrom);	hFindFile =FindFirstFile(search,&FindData);	if(hFindFile!=INVALID_HANDLE_VALUE)	{		sprintf(to,"%s\\%s",szNewsTo,FindData.cFileName);		sprintf(from,"%s\\%s",szNewsFrom,FindData.cFileName);		FileTimeToSystemTime((FILETIME *)&FindData.ftLastWriteTime,			(SYSTEMTIME*)&FileDate);		if(FindData.dwFileAttributes!=FILE_ATTRIBUTE_DIRECTORY &&				FileDate.wMonth ==CurDate.wMonth &&				FileDate.wDay ==CurDate.wDay) 		{			strcpy(temp,FindData.cFileName);			strupr(temp);			if(strstr(temp,".DBF")==NULL&&strstr(temp,".EXE")==NULL)			{				if(strstr(ZxDataFile,temp)==NULL)				{					CopyFile(from,to,TRUE);                 					if(gfIsNewsSrcDel) DeleteFile(from);				}				else				{					_lclose(hfZx);					CopyFile(from,ZxDataFile,TRUE);					DeleteFile(from);					hfZx =OpenFile(ZxDataFile, &os, OF_SHARE_DENY_NONE|OF_READ);				}			}		}		do		{			fFind =FindNextFile(hFindFile,&FindData);			if(fFind)			{				sprintf(to,"%s\\%s",szNewsTo,FindData.cFileName);				sprintf(from,"%s\\%s",szNewsFrom,FindData.cFileName);				FileTimeToSystemTime((FILETIME *)&FindData.ftLastWriteTime,					(SYSTEMTIME*)&FileDate);				if(FindData.dwFileAttributes!=FILE_ATTRIBUTE_DIRECTORY &&					FileDate.wMonth==CurDate.wMonth &&					FileDate.wDay ==CurDate.wDay) 				{					strcpy(temp,FindData.cFileName);					strupr(temp);					if(strstr(temp,".DBF")==NULL&&strstr(temp,".EXE")==NULL)					{						if(strstr(ZxDataFile,temp)==NULL)						{							CopyFile(from,to,TRUE);							if(gfIsNewsSrcDel) DeleteFile(from);						}						else						{							_lclose(hfZx);							CopyFile(from,ZxDataFile,TRUE);							DeleteFile(from);							hfZx =OpenFile(ZxDataFile, &os, OF_SHARE_DENY_NONE|OF_READ);						}					}				}			}		}while(fFind);		FindClose(hFindFile);	}}void RefreshNews(LPSTR szNewsTo,LPSTR szNewsFrom){	char to[128],search[128],from[128],temp[200];    WIN32_FIND_DATA FindData;    HANDLE hFindFile ;	HFILE hFile;	BOOL fFind;	OFSTRUCT os;	SYSTEMTIME CurDate,FileDate;	if(szNewsTo[0]==0||szNewsFrom[0]==0) 		return;	sprintf(temp,"%s\\news.idx",szDataPath);	hFile =OpenFile(temp, &os, OF_SHARE_DENY_NONE|OF_WRITE);	if(hFile ==HFILE_ERROR)		return;	if(_llseek(hFile, 0, SEEK_END)==HFILE_ERROR)	{		_lclose(hFile);		return;	}	GetSystemTime(&CurDate);	sprintf(search,"%s\\*.*",szNewsFrom);	hFindFile =FindFirstFile(search,&FindData);	if(hFindFile!=INVALID_HANDLE_VALUE)	{		sprintf(to,"%s\\%s",szNewsTo,FindData.cFileName);		sprintf(from,"%s\\%s",szNewsFrom,FindData.cFileName);		FileTimeToSystemTime((FILETIME *)&FindData.ftLastWriteTime,			(SYSTEMTIME*)&FileDate);		if(FileDate.wMonth ==CurDate.wMonth &&				FileDate.wDay ==CurDate.wDay) 		{			strcpy(temp,FindData.cFileName);			strupr(temp);                   			if(strstr(ZxDataFile,temp)==NULL&&strstr(temp,".DBF")==NULL				&&strstr(temp,".EXE")==NULL)			{				if(CopyFile(from,to,TRUE))				{					sprintf(temp,"%12s %ld.%02ld.%02ld %02ld.%02ld:%02ld %ld\n",						FindData.cFileName,						FileDate.wYear,						FileDate.wMonth,						FileDate.wDay,						FileDate.wHour,						FileDate.wMinute,						FileDate.wSecond,						FindData.nFileSizeLow +FindData.nFileSizeHigh *256);					_lwrite(hFile,temp,strlen(temp));				}				if(gfIsNewsSrcDel) DeleteFile(from);			}		}		do		{			fFind =FindNextFile(hFindFile,&FindData);			if(fFind)			{				sprintf(to,"%s\\%s",szNewsTo,FindData.cFileName);				sprintf(from,"%s\\%s",szNewsFrom,FindData.cFileName);				FileTimeToSystemTime((FILETIME *)&FindData.ftLastWriteTime,					(SYSTEMTIME*)&FileDate);				if(FileDate.wMonth==CurDate.wMonth &&					FileDate.wDay ==CurDate.wDay) 				{					strcpy(temp,FindData.cFileName);					strupr(temp);					if(strstr(ZxDataFile,temp)==NULL&&strstr(temp,".DBF")==NULL						&&strstr(temp,".EXE")==NULL)					{						if(CopyFile(from,to,TRUE))						{							sprintf(temp,"%12s %ld.%02ld.%02ld %02ld.%02ld:%02ld %ld\n",								FindData.cFileName,								FileDate.wYear,								FileDate.wMonth,								FileDate.wDay,								FileDate.wHour,								FileDate.wMinute,								FileDate.wSecond,								FindData.nFileSizeLow +FindData.nFileSizeHigh *256);							_lwrite(hFile,temp,strlen(temp));						}						if(gfIsNewsSrcDel) DeleteFile(from);					}				}			}		}while(fFind);		FindClose(hFindFile);           	}       	_lclose(hFile);}long TF_NewsManager(void){	SYSTEMTIME SysTime;	static BOOL IsInit =FALSE;	int minute ;	while(1)	{		if(run_cancelled) break;		GetLocalTime(&SysTime);		minute = SysTime.wHour*60+SysTime.wMinute;		if(minute<HqTime[0].am_min_start)			IsInit =FALSE;		else		{			if(!IsInit)			{				if(!FileTranLock)				{					FileTranLock =TRUE;					Sleep(3000);					DelNews(szNewsPath);				}				MoveNews(szNewsPath,szNewsSrc);				if(GetNewsIndex(szNewsPath))				{					IsInit =TRUE;   					FileTranLock =FALSE;				}			}			else			{				RefreshNews(szNewsPath,szNewsSrc);			}		}		Sleep(1000*60);	}	CloseHandle(hNewsManager);	ExitThread(0);	return 0;}int CreateNewsManagerThread(void){      LONG lThreadId;		hNewsManager =CreateThread(NULL, 0,	      (LPTHREAD_START_ROUTINE)TF_NewsManager,	      NULL, CREATE_SUSPENDED, (LPDWORD)&lThreadId);	if(!hNewsManager) return -1;	SetThreadPriority(hNewsManager, THREAD_PRIORITY_NORMAL);		ResumeThread(hNewsManager);		return 0;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -