// SellDlg.cpp: 实现文件
|
//
|
#include "common/pch.h"
|
#include "FloatTrade.h"
|
#include "SellDlg.h"
|
#include "afxdialogex.h"
|
#include "../common/NetworkApi.h"
|
#include "../common/JsonUtil.h"
|
#include <thread>
|
|
|
// SellDlg 对话框
|
|
IMPLEMENT_DYNAMIC(SellDlg, CDialogEx)
|
|
void SellDlg::initView(SellDlg* context)
|
{
|
//context->btnSell.SetTextColor(RGB(0, 255, 0));
|
//context->btnSell.SetFaceColor(RGB(0, 0, 0), TRUE);
|
//btnSell.Invalidate();
|
//context->btnClose.SubclassDlgItem(IDC_BUTTON_CLOSE, context);
|
|
HBITMAP hBitmap = ::LoadBitmap(AfxGetInstanceHandle(), MAKEINTRESOURCE(IDB_PNG_CLOSE)); //IDB_BITMAP1 为BITMAP资源
|
context->btnClose.SetBitmap(hBitmap);
|
}
|
|
void SellDlg::requestCurrentPriceInfo(SellDlg* context)
|
{
|
while (TRUE) {
|
|
try
|
{
|
if (context->killed) {
|
break;
|
}
|
string result = NetworkApi::get_l2_deal_price(context->code);
|
auto doc = JsonUtil::parseUTF16(result);
|
if (context->killed) {
|
break;
|
}
|
if (doc.IsObject()) {
|
if (doc.HasMember(L"code") && doc[L"code"].GetInt() == 0) {
|
auto data = doc[L"data"].GetObjectW();
|
if (data.HasMember(L"rate")) {
|
float rate = ((int)(data[L"rate"].GetDouble() * 10000)) / 100.f;
|
if (rate > 0)
|
{
|
context->rateColor = RGB(205, 54, 54);
|
}
|
else if (rate < 0) {
|
context->rateColor = RGB(0, 230, 0);
|
}
|
else {
|
context->rateColor = RGB(0, 0, 0);
|
}
|
std::ostringstream oss;
|
oss << std::fixed << std::setprecision(2) << rate;
|
CString priceRateStr = CString(oss.str().c_str());
|
priceRateStr.Append(L"%");
|
context->labelPriceRate.SetWindowTextW(priceRateStr);
|
context->labelPriceRate.Invalidate();
|
}
|
}
|
else {
|
context->rateColor = RGB(0, 0, 0);
|
context->labelPriceRate.SetWindowTextW(L"-");
|
context->labelPriceRate.Invalidate();
|
}
|
}
|
}
|
catch (...)
|
{
|
|
}
|
Sleep(1000);
|
}
|
|
|
}
|
|
void SellDlg::SetBtnSellText()
|
{
|
// 设置卖信息
|
CString st = L"";
|
st.Append(codeName);
|
//st.Append(L"-");
|
//st.Append(to_wstring(position.total - position.available).c_str());
|
//st.Append(L"/");
|
//st.Append(to_wstring(position.total).c_str());
|
btnSell.SetWindowTextW(st);
|
}
|
|
SellDlg::SellDlg(string code, CString name, CodePosition position, SellCallbackFunc callback, CloseCallbackFunc closeCallback, CWnd* pParent /*=nullptr*/)
|
: CDialogEx(IDD_DIALOG_SELL, pParent)
|
{
|
this->pParent = pParent;
|
this->code = code;
|
this->codeName = name;
|
this->position = position;
|
this->sellCallback = callback;
|
this->closeCallback = closeCallback;
|
}
|
|
SellDlg::~SellDlg()
|
{
|
}
|
|
void SellDlg::SetPositionInfo(int total, int avaiable)
|
{
|
this->position.total = total;
|
this->position.available = avaiable;
|
SetBtnSellText();
|
}
|
|
void SellDlg::DoDataExchange(CDataExchange* pDX)
|
{
|
CDialogEx::DoDataExchange(pDX);
|
DDX_Control(pDX, IDC_MFCBUTTON_SELL, btnSell);
|
DDX_Control(pDX, IDC_BUTTON_CLOSE, btnClose);
|
DDX_Control(pDX, IDC_STATIC_RATE, labelPriceRate);
|
}
|
|
|
BEGIN_MESSAGE_MAP(SellDlg, CDialogEx)
|
ON_WM_NCHITTEST()
|
ON_BN_CLICKED(IDC_BUTTON_CLOSE, &SellDlg::OnBnClickedButtonClose)
|
ON_BN_CLICKED(IDC_MFCBUTTON_SELL, &SellDlg::OnBnClickedMfcbuttonSell)
|
ON_WM_CTLCOLOR()
|
END_MESSAGE_MAP()
|
|
|
// SellDlg 消息处理程序
|
|
|
|
LRESULT SellDlg::OnNcHitTest(CPoint point)
|
{
|
|
|
return HTCAPTION;
|
}
|
|
|
BOOL SellDlg::OnInitDialog()
|
{
|
CDialogEx::OnInitDialog();
|
// 设置对话框背景颜色
|
SetBackgroundColor(RGB(0,0,0));
|
SetBtnSellText();
|
int scale = GetDpiForSystem();
|
font.CreateFont(27, 0, 0, 0, FW_NORMAL, 0, 0, 0, 0, 0, 0, 0, 0, L"微软雅黑");
|
|
// 设置透明度(0透明,255完全不透明)
|
ModifyStyleEx(0, WS_EX_LAYERED);
|
BYTE opacity = 255; // 透明度值取值范围为0~255
|
SetLayeredWindowAttributes(RGB(0, 0, 0), opacity, LWA_ALPHA);
|
|
//设置字体
|
labelPriceRate.SetFont(&font, FALSE);
|
|
killed = FALSE;
|
|
|
std::thread t1(initView, this);
|
t1.detach();
|
|
std::thread t2(requestCurrentPriceInfo, this);
|
t2.detach();
|
|
return TRUE;
|
}
|
|
void SellDlg::OnBnClickedButtonClose()
|
{
|
killed = TRUE;
|
this->closeCallback(code, this->pParent);
|
}
|
|
|
void SellDlg::OnBnClickedMfcbuttonSell()
|
{
|
this->sellCallback(code, this->pParent);
|
}
|
|
|
|
|
|
|
|
HBRUSH SellDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
|
{
|
HBRUSH hbr = CDialogEx::OnCtlColor(pDC, pWnd, nCtlColor);
|
|
if (nCtlColor == CTLCOLOR_STATIC) {
|
int nID = pWnd->GetDlgCtrlID();
|
switch (nID) {
|
case IDC_STATIC_RATE:
|
pDC->SetTextColor(rateColor);
|
break;
|
}
|
}
|
return hbr;
|
}
|