開始研究飛狐預(yù)警文件的時候,是想實時讀取盤中的預(yù)警信號??墒牵髞戆l(fā)現(xiàn)其原理是這樣的: 1)飛狐每次啟動之時,程序就會一次性讀取alert.alt的記錄進內(nèi)存。 2)飛狐預(yù)警的新設(shè)置和盤中預(yù)警產(chǎn)生的新記錄,都不會實時寫到alert.alt文件上,要等到飛狐關(guān)閉的時候才會寫到alert.alt。 關(guān)于alert.alt的文件結(jié)構(gòu),飛狐沒有公開,而文件前面部分結(jié)構(gòu)涉及一些預(yù)警設(shè)置的內(nèi)容,不是我想要的--所以沒去研究。 對于其預(yù)警信號方面,我倒有一個山寨版的初步解析: ![]() ![]() ![]() 用C++讀alert.alt所有預(yù)警記錄: #include <string> #include <iostream> #include <fstream> using namespace std; int main() { fstream f("User\\alert.alt",ios::in|ios::out|ios::binary); //尋找預(yù)警總數(shù)標記256...... 如為減少搜索時間:可從指定位置如n=809000開始,每次移動1字節(jié) int i,j,k,n,m,l; for (n=0;n<1000000;n=n+1) { f.seekg(n,ios::beg); f.read((char*)(& i),sizeof(i)); if(i==256) { f.seekg(n-12,ios::beg); f.read((char*)(& l),sizeof(l)); //特殊標記 int 1240832 f.seekg(n-8,ios::beg); f.read((char*)(& j),sizeof(j)); //確認標記前面的2個int為0 f.seekg(n-4,ios::beg); f.read((char*)(& k),sizeof(k)); if(j==0 && k==0 && l==1240832) break; } } cout<<"標記位置: "<<n<<"\n"; f.seekg(n+4,ios::beg); f.read((char*)(& m),sizeof(m)); cout<<"預(yù)警總數(shù): "<<m<<"\n"; //預(yù)警總數(shù) int start; int _stlogo,clong; short xnumber,_unlogo; char xno[9]; char cond[20]; int xtime; float xprice; start=n+8; while(m>0 && f.eof()==false) { f.seekg(start,ios::beg); f.read((char*)(& _stlogo),sizeof(_stlogo)); cout<<"標記: "<<_stlogo<<"\n"; //257 標記 f.seekg(start+4,ios::beg); // start-36-i-2-11 f.read((char*)& xno,sizeof(xno)); cout<<"股票代碼: "<<xno<<"\n"; f.seekg(start+13,ios::beg); // 股票代碼之后的那2個字節(jié) short: 26795 f.read((char*)(&_unlogo),sizeof(_unlogo)); cout<<"un標記: "<<_unlogo<<"\n"; f.seekg(start+15,ios::beg); f.read((char*)(&xnumber),sizeof(xnumber)); clong =(int) xnumber/256; cout<<"2字節(jié)值: "<<xnumber<<"\n"; cout<<"換算長度: "<<clong<<"\n"; f.seekg(start+17,ios::beg); f.read((char*)& cond,clong); cout<<"預(yù)警條件: "<<cond<<"\n"; f.seekg(start+17+clong,ios::beg); f.read((char*)(&xtime),sizeof(xtime)); cout<<"預(yù)警時間: "<<xtime<<"\n"; f.seekg(start+21+clong,ios::beg); f.read((char*)(&xprice),sizeof(xprice)); cout<<"預(yù)警價格: "<<xprice<<"\n"; cout<<"\n"; start = start+53+clong; //start+21+clong+4+28 } f.close(); return 0; } 往alert.alt里添加預(yù)警紀錄,其原理也是一樣的:首先要注意修改預(yù)警總數(shù),否則系統(tǒng)無法讀出新增的記錄。 |