策略为王-预警窗口(Alarm.cpp)

Published

预警数据的计算

1.分笔数据到达时,数据处理线程会调用下面的函数进行计算。如果有大单,则发送STKRCV_ALARM_WARNING消息。

G:\stock\TskingVS2019\src\Client\StkNet\Src\StkReceiver.cpp
void CStkReceiver::OnReceiveReport(REPORT * pReport)
{
	CStockContainer & container = AfxGetStockContainer();
	REPORT reportLast;
	if (!UpdateStockContainerByREPORT(container, pReport, TRUE, &reportLast))
		return;

	CStockInfo infoCur;

	// 主力大单
	if (container.GetStockInfo(pReport->m_szCode, &infoCur, NULL))
	{
		if (0 != reportLast.m_time && reportLast.m_time < pReport->m_time
			&& pReport->m_fVolume - reportLast.m_fVolume >= 100000
			&& !infoCur.IsIndex() && !infoCur.IsBond() && !infoCur.IsFund() && !infoCur.IsBondIndex())
		{
			REPORT	report;
			memcpy(&report, pReport, sizeof(report));
			report.m_fVolume	=	pReport->m_fVolume - infoCur.m_reportLatest.m_fVolume;
			report.m_fAmount	=	pReport->m_fAmount - infoCur.m_reportLatest.m_fAmount;
			AfxGetDB().StoreReport(&report, 1, TRUE);
		}
	}

	// 指数发生变化
	if (0 == strncmp(pReport->m_szCode, STKLIB_CODE_MAIN, sizeof(pReport->m_szCode))
		|| 0 == strncmp(pReport->m_szCode, STKLIB_CODE_MAINSZN, sizeof(pReport->m_szCode)))
	{
		NotifyWndRcvAlarm(STKRCV_ALARM_REFRESH, 0);
	}

	// 盘中预警在此处加入
	if (AfxGetAlarmContainer().OnReceiveReport(&infoCur, pReport, &reportLast))
	{
		NotifyWndRcvAlarm(STKRCV_ALARM_WARNING, 0);
	}
}

G:\stock\TskingVS2019\src\Client\StkLib\Src\Alarm.cpp

这是预警数据的计算类,结果会存入容器中。

// 窗口预警:由AfxGetAlarmContainer().OnReceiveReport()计算,盘中预警在此处加入
	if (AfxGetAlarmContainer().OnReceiveReport(&infoCur, pReport, &reportLast))
	{
		NotifyWndRcvAlarm(STKRCV_ALARM_WARNING, 0);
	}

 

预警数据的显示

G:\stock\TskingVS2019\src\Client\StkUI\MainFrm.cpp

定义了 ON_MESSAGE(WM_APP_STKRECEIVER_ALARM, OnStkReceiverAlarm) //预警窗口:定义预警窗口消息处理函数 

	ON_MESSAGE(WM_APP_STKRECEIVER_ALARM, OnStkReceiverAlarm) //预警窗口:定义预警窗口消息处理函数  by freeman

 

消息处理函数

//预警窗口:消息处理函数 by freeman
LRESULT CMainFrame::OnStkReceiverAlarm(WPARAM wParam, LPARAM lParam)
{
	
	if (STKRCV_ALARM_WARNING == wParam)
	{
		CAlarmTipDlg::GetInstance().ShowGradual();
		CAlarmTipDlg::GetInstance().SetAutoHide(5, TRUE);
	}

	UINT nIDIcon = IDR_MAINFRAME;

	if (AfxGetAlarmContainer().HasWarning())
	{
		nIDIcon = IDI_ALARM_WARNING;
	}
	else
	{
		CStockInfo info;
		double dDiff;
		if (AfxGetStockContainer().GetStockInfo(STKLIB_CODE_MAIN, &info)
			&& info.GetDiff(&dDiff, info.m_datetech, 1))
		{
			if (dDiff > 0)
				nIDIcon = IDI_ALARM_INDEXRED;
			if (dDiff < 0)
				nIDIcon = IDI_ALARM_INDEXGREEN;
		}
	}

	// Notify Icon
	NOTIFYICONDATA	nid;
	memset(&nid, 0, sizeof(nid));
	nid.cbSize = sizeof(nid);
	nid.hWnd = GetSafeHwnd();
	nid.uID = 1;
	nid.uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP;
	nid.uCallbackMessage = WM_USER_NIFMESSAGE;
	nid.hIcon = AfxGetApp()->LoadIcon(nIDIcon);
	CString strName = AfxGetStockIndexReportTip();
	strncpy(nid.szTip, strName, min(strName.GetLength(), sizeof(nid.szTip) - 1));
	Shell_NotifyIcon(NIM_MODIFY, &nid);

	return 0;
}

 

窗口预警对话框

G:\stock\TskingVS2019\src\Client\StkUI\Dialog\AlarmTipDlg.cpp