📄 findstockview.cpp
字号:
// FindStockView.cpp : implementation file
//
#include "stdafx.h"
#include "StockSearch.h"
#include "FindStockView.h"
#include "DataStruct.h"
#include <commdlg.h>
#include <dlgs.h>
#include <windows.h>
extern CStockSearchApp theApp;
char* g_aTypeNote[TYPE_MAX]={
"价增量升",
"低位放量",
"高位放量"
};
UINT g_aParamNum[TYPE_MAX]={12,3,3};
char* g_aParamNote[TYPE_MAX][PARAM_MAX]={
"量比(第二天/第一天)(低)",
"量比(第二天/第一天)(高)",
"量比(第三天/第二天)(低)",
"量比(第三天/第二天)(高)",
"价比(第二天/第一天)(低)",
"价比(第二天/第一天)(高)",
"价比(第三天/第二天)(低)",
"价比(第三天/第二天)(高)",
"量比(第三天/最高)(低)%",
"量比(第三天/最高)(高)%",
"价比(第三天/最高)(低)%",
"价比(第三天/最高)(高)%",
"str21",
"str22",
"str23",
"str31",
"str32",
"str33"
};
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
UINT SearchThread(LPVOID pParam);
int SearchOneStock(CString sDataFile, float* m_Param);
void NoteUser();
bool FileExists(const char * filename);
CString GetSaveFileName(CString oldFileName, CString sTitle, HWND hWnd);
/////////////////////////////////////////////////////////////////////////////
// CFindStockView
IMPLEMENT_DYNCREATE(CFindStockView, CFormView)
CFindStockView::CFindStockView()
: CFormView(CFindStockView::IDD)
{
//{{AFX_DATA_INIT(CFindStockView)
//}}AFX_DATA_INIT
m_pThread = NULL;
m_bSearching = false;
}
CFindStockView::~CFindStockView()
{
}
void CFindStockView::DoDataExchange(CDataExchange* pDX)
{
CFormView::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CFindStockView)
DDX_Control(pDX, IDC_LIST_TYPE, m_oListType);
DDX_Control(pDX, IDC_EDIT_ALL, m_oEditAll);
DDX_Control(pDX, IDC_LIST_STOCKS, m_oListStocks);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CFindStockView, CFormView)
//{{AFX_MSG_MAP(CFindStockView)
ON_BN_CLICKED(IDC_BTN_START, OnBtnStart)
ON_BN_CLICKED(IDC_BTN_COPY, OnBtnCopy)
ON_LBN_SELCHANGE(IDC_LIST_TYPE, OnSelchangeListType)
ON_BN_CLICKED(IDC_BTN_SAVEPARAM, OnBtnSaveparam)
ON_BN_CLICKED(IDC_BTN_STOP, OnBtnStop)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CFindStockView diagnostics
#ifdef _DEBUG
void CFindStockView::AssertValid() const
{
CFormView::AssertValid();
}
void CFindStockView::Dump(CDumpContext& dc) const
{
CFormView::Dump(dc);
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CFindStockView message handlers
void CFindStockView::OnBtnStart()
{
(CButton*)GetDlgItem(IDC_BTN_START)->EnableWindow(false);
UINT nType = m_oListType.GetCurSel();
CString sParamValue;
GetParamCtrl(nType);
for(UINT i=0; i<g_aParamNum[nType]; i++){
m_oParamEdit[i]->GetWindowText(sParamValue);
m_Param[i] = (float)atof(sParamValue);
}
m_pThread = AfxBeginThread(SearchThread, this);
(CButton*)GetDlgItem(IDC_BTN_STOP)->EnableWindow(true);
}
void CFindStockView::ShowStock(CString sStockCode, int nType)
{
if (nType == SIGNAL_TOTAL){
m_oEditAll.SetWindowText(sStockCode.Left(6));
}else if (nType == SIGNAL_JZLS){
m_oListStocks.AddString(sStockCode.Left(6));
Beep(5555, 20);
}
}
int CFindStockView::getParam(int nType)
{
CString sSectionName = g_aTypeNote[nType];
CString sTmp, sParamName;
BOOL bExists = theApp.m_oIniReader.sectionExists(sSectionName);
if(!bExists){
AfxMessageBox("INI文件JZLS节不正确!");
return -1;
}
for(UINT i=0; i<g_aParamNum[nType]; i++){
sTmp.Empty();
sParamName.Format("param%d", i);
sTmp = theApp.m_oIniReader.getKeyValue(sParamName , sSectionName);
m_Param[i] = (float)atof(sTmp);
}
return 0;
}
UINT SearchThread(LPVOID pParam)
{
CFindStockView* pView = (CFindStockView*)pParam;
CString sDataPath ;
CString sFullMask ;
CString sDataFile;
CString sStockFile;
WIN32_FIND_DATA ffData;
HANDLE hFind;
pView->m_bSearching = true;
// 上海
for(int i=0; i<2 && pView->m_bSearching; i++)
{
if (i==0)
sDataPath = theApp.m_sDZHPath + _T("\\DATA\\SHase\\Day\\");
else
sDataPath = theApp.m_sDZHPath + _T("\\DATA\\SZnse\\Day\\");
sFullMask = sDataPath + _T("*.*");
hFind = FindFirstFile(sFullMask, &ffData);
if (hFind == INVALID_HANDLE_VALUE)
return FALSE;
while (pView->m_bSearching && hFind
&& FindNextFile(hFind, &ffData))
{
if (ffData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
continue;
sStockFile = ffData.cFileName;
if (sStockFile == "000009.day")
sStockFile = sStockFile;
pView->ShowStock(ffData.cFileName, SIGNAL_TOTAL);
sDataFile = sDataPath + ffData.cFileName;
if ((sStockFile.Left(3) == "000") ||
(sStockFile.Left(3) == "600") ||
(sStockFile.Left(3) == "002"))
{
if (SearchOneStock(sDataFile, pView->m_Param)==SIGNAL_JZLS)
pView->ShowStock(ffData.cFileName, SIGNAL_JZLS);
}
}
FindClose(hFind);
}
NoteUser();
pView->stopSearch();
return 0;
}
int SearchOneStock(CString sDataFile, float* m_Param)
{
CFile theFile;
UINT nBytesRead ;
long theData[LEN_STOCKDATA/4], tmpLong;
long lMaxPrice=0, lMinPrice=MAX_PRICE, lMaxAmount=0;
// 日期 开盘 最高 最低 收盘 成交额 成交量 4个未明
if (!theFile.Open(sDataFile, CFile::modeRead)){
AfxMessageBox("打开文件" + sDataFile + "出错");
return -1;
}
do{
nBytesRead = theFile.Read(&theData, LEN_STOCKDATA);
tmpLong = theData[0];
if (tmpLong >= theApp.m_lStartDate){
tmpLong = theData[2];
if(tmpLong > lMaxPrice) lMaxPrice = tmpLong;
tmpLong = theData[3];
if(tmpLong < lMinPrice) lMinPrice = tmpLong;
tmpLong = theData[6];
if(tmpLong > lMaxAmount) lMaxAmount = tmpLong;
}
}while(nBytesRead > 0);
theFile.SeekToEnd();
theFile.Seek(- NUM_DAY_JZLS * LEN_STOCKDATA, CFile::end );
long lClose[NUM_DAY_JZLS];
long lAmount[NUM_DAY_JZLS];
for(int i=0; i< NUM_DAY_JZLS; i++){
nBytesRead = theFile.Read(&theData, LEN_STOCKDATA);
lClose[i] = theData[4];
lAmount[i] = theData[6];
}
if (lAmount[0] * m_Param[0] < lAmount[1]
&& lAmount[0] * m_Param[1] > lAmount[1]
&& lAmount[1] * m_Param[2] < lAmount[2]
&& lAmount[1] * m_Param[3] > lAmount[2]
&& lClose[0] * m_Param[4] < lClose[1]
&& lClose[0] * m_Param[5] > lClose[1]
&& lClose[1] * m_Param[6] < lClose[2]
&& lClose[1] * m_Param[7] > lClose[2]
&& lAmount[2] * 100 > lMaxAmount * m_Param[8]
&& lAmount[2] * 100 < lMaxAmount * m_Param[9]
&& (lClose[2] - lMinPrice) * 100
> (lMaxPrice - lMinPrice) * m_Param[10]
&& (lClose[2] - lMinPrice) * 100
< (lMaxPrice - lMinPrice) * m_Param[11]
)
return SIGNAL_JZLS;
return 0;
}
void CFindStockView::OnBtnCopy()
{
CString str;
int n, nRet;
CString sOutFileName;
CString sDate, sParamValue;
UINT nType = m_oListType.GetCurSel();
sDate.Format("%ld", theApp.m_lStartDate + 10000);
sOutFileName = theApp.m_sRunPath + "\\..\\Data\\" + sDate
+ "_" + g_aTypeNote[nType] + ".txt";
if (FileExists(sOutFileName)){
nRet = AfxMessageBox("文件\r" + sOutFileName + "\r已经存在, 覆盖?", MB_YESNOCANCEL);
if (nRet == IDCANCEL ) return;
if (nRet == IDNO){
do{
sOutFileName = GetSaveFileName(sOutFileName, "保存搜索结果", this->m_hWnd);
}while(sOutFileName=="" || FileExists(sOutFileName));
}
}
CStdioFile outFile(sOutFileName , CFile::modeCreate | CFile::modeWrite | CFile::typeText );
str = sDate;
str = str.Left(4) + "年" + str.Mid(4,2) + "月"
+ str.Right(2) + "日\n\n";
outFile.WriteString(str);
outFile.WriteString(g_aTypeNote[nType]);
outFile.WriteString(":\n");
for (int i=0;i < m_oListStocks.GetCount();i++)
{
n = m_oListStocks.GetTextLen( i );
m_oListStocks.GetText( i, str);
str += " \n";
outFile.WriteString(str);
}
outFile.WriteString("\n参数:\n");
for(i=0; i < (int)g_aParamNum[nType]; i++){
outFile.WriteString(g_aParamNote[nType][i]);
outFile.WriteString(" = " + getParamStr(i) + "\n");
}
outFile.Close();
if (AfxMessageBox("打开结果文件?", MB_YESNO) == IDYES)
ShellExecute(this->m_hWnd, "open", "notepad.exe", sOutFileName, ".", SW_SHOWNORMAL );
NoteUser();
}
bool FileExists(const char * filename)
{
return GetFileAttributes(filename) != 0xFFFFFFFF;
}
CString GetSaveFileName(CString oldFileName, CString sTitle, HWND hWnd)
{
OPENFILENAME OpenFileName;
TCHAR szFile[MAX_PATH] = "\0";
TCHAR szTitle[MAX_PATH] = "\0";
strcpy( szFile, oldFileName);
strcpy( szTitle, sTitle);
// Fill in the OPENFILENAME structure to support a template and hook.
OpenFileName.lStructSize = sizeof(OPENFILENAME);
OpenFileName.hwndOwner = hWnd;
OpenFileName.hInstance = theApp.m_hInstance;
OpenFileName.lpstrFilter = NULL;
OpenFileName.lpstrCustomFilter = NULL;
OpenFileName.nMaxCustFilter = 0;
OpenFileName.nFilterIndex = 0;
OpenFileName.lpstrFile = szFile;
OpenFileName.nMaxFile = sizeof(szFile);
OpenFileName.lpstrFileTitle = NULL;
OpenFileName.nMaxFileTitle = 0;
OpenFileName.lpstrInitialDir = NULL;
OpenFileName.lpstrTitle = szTitle;
OpenFileName.nFileOffset = 0;
OpenFileName.nFileExtension = 0;
OpenFileName.lpstrDefExt = NULL;
OpenFileName.lCustData = NULL;
OpenFileName.lpfnHook = NULL;
OpenFileName.lpTemplateName = NULL; // MAKEINTRESOURCE(IDD_COMDLG32);
OpenFileName.Flags = OFN_SHOWHELP | OFN_EXPLORER ; //| OFN_ENABLEHOOK | OFN_ENABLETEMPLATE;
// Call the common dialog function.
if (GetOpenFileName(&OpenFileName))
return OpenFileName.lpstrFile;
return "";
}
void NoteUser()
{
Beep(3333, 50);
Beep(5555, 50);
}
void CFindStockView::OnInitialUpdate()
{
CFormView::OnInitialUpdate();
for(int i=0; i < TYPE_MAX; i++)
m_oListType.AddString(g_aTypeNote[i]);
}
void CFindStockView::OnSelchangeListType()
{
UINT nType = m_oListType.GetCurSel();
GetParamCtrl(nType);
getParam(nType);
for(UINT i=0; i < g_aParamNum[nType]; i++){
m_oParamStatic[i]->SetWindowText(g_aParamNote[nType][i]);
m_oParamStatic[i]->ShowWindow(SW_SHOW);
m_oParamEdit[i]->ShowWindow(SW_SHOW);
m_oParamEdit[i]->SetWindowText(getParamStr(i));
}
(CButton*)GetDlgItem(IDC_BTN_START)->EnableWindow(true);
}
void CFindStockView::GetParamCtrl(int nType)
{
m_oParamStatic[0] = (CStatic*)this->GetDlgItem(IDC_STATIC1);
m_oParamStatic[1] = (CStatic*)this->GetDlgItem(IDC_STATIC2);
m_oParamStatic[2] = (CStatic*)this->GetDlgItem(IDC_STATIC3);
m_oParamStatic[3] = (CStatic*)this->GetDlgItem(IDC_STATIC4);
m_oParamStatic[4] = (CStatic*)this->GetDlgItem(IDC_STATIC5);
m_oParamStatic[5] = (CStatic*)this->GetDlgItem(IDC_STATIC6);
m_oParamStatic[6] = (CStatic*)this->GetDlgItem(IDC_STATIC7);
m_oParamStatic[7] = (CStatic*)this->GetDlgItem(IDC_STATIC8);
m_oParamStatic[8] = (CStatic*)this->GetDlgItem(IDC_STATIC9);
m_oParamStatic[9] = (CStatic*)this->GetDlgItem(IDC_STATIC10);
m_oParamStatic[10] = (CStatic*)this->GetDlgItem(IDC_STATIC11);
m_oParamStatic[11] = (CStatic*)this->GetDlgItem(IDC_STATIC12);
m_oParamEdit[0] = (CEdit*)this->GetDlgItem(IDC_EDIT_PARAM1);
m_oParamEdit[1] = (CEdit*)this->GetDlgItem(IDC_EDIT_PARAM2);
m_oParamEdit[2] = (CEdit*)this->GetDlgItem(IDC_EDIT_PARAM3);
m_oParamEdit[3] = (CEdit*)this->GetDlgItem(IDC_EDIT_PARAM4);
m_oParamEdit[4] = (CEdit*)this->GetDlgItem(IDC_EDIT_PARAM5);
m_oParamEdit[5] = (CEdit*)this->GetDlgItem(IDC_EDIT_PARAM6);
m_oParamEdit[6] = (CEdit*)this->GetDlgItem(IDC_EDIT_PARAM7);
m_oParamEdit[7] = (CEdit*)this->GetDlgItem(IDC_EDIT_PARAM8);
m_oParamEdit[8] = (CEdit*)this->GetDlgItem(IDC_EDIT_PARAM9);
m_oParamEdit[9] = (CEdit*)this->GetDlgItem(IDC_EDIT_PARAM10);
m_oParamEdit[10] = (CEdit*)this->GetDlgItem(IDC_EDIT_PARAM11);
m_oParamEdit[11] = (CEdit*)this->GetDlgItem(IDC_EDIT_PARAM12);
}
void CFindStockView::OnBtnSaveparam()
{
UINT nType = m_oListType.GetCurSel();
CString sSectionName = g_aTypeNote[nType];
CString sParamName, sParamValue;
GetParamCtrl(nType);
BOOL bExists = theApp.m_oIniReader.sectionExists(sSectionName);
if(!bExists){
AfxMessageBox("INI文件JZLS节不正确!");
return;
}
for(UINT i=0; i<g_aParamNum[nType]; i++){
m_oParamEdit[i]->GetWindowText(sParamValue);
m_Param[i] = (float)atof(sParamValue);
sParamName.Format("param%d", i);
theApp.m_oIniReader.setKey(sParamValue, sParamName , sSectionName);
}
}
void CFindStockView::OnBtnStop()
{
stopSearch();
}
CString CFindStockView::getParamStr(int nParamNo)
{
CString sParamValue;
sParamValue.Format("%3.3f", m_Param[nParamNo]);
int nPonintPos = sParamValue.Find(".", 0);
while(sParamValue.Right(1)=="0" && sParamValue.GetLength() > nPonintPos)
sParamValue = sParamValue.Left(sParamValue.GetLength() -1);
if (sParamValue.Right(1)==".")
sParamValue = sParamValue.Left(sParamValue.GetLength() -1);
return sParamValue;
}
void CFindStockView::stopSearch()
{
m_bSearching = false;
(CButton*)GetDlgItem(IDC_BTN_START)->EnableWindow(true);
(CButton*)GetDlgItem(IDC_BTN_STOP)->EnableWindow(false);
(CButton*)GetDlgItem(IDC_BTN_COPY)->EnableWindow(true);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -