sjshqdlg.cpp
来自「一个通过PCI卡向LED屏发送股票实时行情的系统」· C++ 代码 · 共 1,155 行 · 第 1/3 页
CPP
1,155 行
// sjshqDlg.cpp : implementation file
//
#include "stdafx.h"
#include "sjshq.h"
#include "sjshqDlg.h"
#include "addnewstock.h"
#include "getdatabase.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
UINT OnDisplayZM(LPVOID pParam); //显示字幕
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
//{{AFX_MSG(CAboutDlg)
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CSjshqDlg dialog
CSjshqDlg::CSjshqDlg(CWnd* pParent /*=NULL*/)
: CDialog(CSjshqDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CSjshqDlg)
m_sZMBmpFilePath = _T("h:/dpm/zm/zmbmp1");//h:/dpm/zm/
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
/* m_pWnd=new CWnd;
m_pWnd->CreateEx(0,AfxRegisterWndClass(CS_DBLCLKS),"",WS_POPUP,CRect(0,0,1024,704),this,0);
m_pWnd->ShowWindow(TRUE);
pDC=m_pWnd->GetDC();
m_pMemDC=new CDC;
m_Rect=CRect(0,0,1536,704);
CBitmap m_Bitmap;
m_pMemDC->CreateCompatibleDC(pDC);
m_Bitmap.CreateCompatibleBitmap(pDC,m_Rect.Width(),m_Rect.Height());
m_pMemDC->SelectObject(&m_Bitmap);
brush.CreateSolidBrush(RGB(0,0,0));
m_pMemDC->SelectObject(&brush);
m_pMemDC->FillRect(CRect(0,0,m_Rect.Width(),m_Rect.Height()),&brush);
m_Bitmap.DeleteObject();*/
bAutoRun=0;
m_FntOld=NULL;
DlgButtonID=0;
m_ZMThread=NULL;
m_TempGGaoThread=NULL;
m_GetDatabase.m_NewStockNum=0;
// m_brush.CreateSolidBrush(m_BackGroundColor);
}
void CSjshqDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CSjshqDlg)
DDX_Text(pDX, IDC_ZM_BMP_PATH, m_sZMBmpFilePath);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CSjshqDlg, CDialog)
//{{AFX_MSG_MAP(CSjshqDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_WM_DESTROY()
ON_WM_TIMER()
ON_WM_CTLCOLOR()
ON_BN_CLICKED(IDC_GUOZHAI_RADIO, OnGuozhaiRadio)
ON_BN_CLICKED(IDC_RADIO1, OnRadio1)
ON_BN_CLICKED(IDC_RADIO2, OnRadio2)
//}}AFX_MSG_MAP
ON_CONTROL_RANGE(BN_CLICKED, IDC_BUTTON1, IDC_BUTTON7, OnDlgButton)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CSjshqDlg message handlers
BOOL CSjshqDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
//读入新股初值////////////////////////////////////////////////////////////////////////
static char *szProFile="C:\\WINDOWS\\sjshq.ini";
char cTemp[10],temp[20];
GetPrivateProfileString("NEW_STOCK","NewGuNumber","0",temp,sizeof(temp),szProFile);
m_GetDatabase.m_NewStockNum=atoi(temp);
strcpy(cTemp, "NewGu");
for(int i=0;i<m_GetDatabase.m_NewStockNum;i++)
{
itoa(i+1,&cTemp[5],10);
GetPrivateProfileString("NEW_STOCK",cTemp,"",temp,sizeof(temp),szProFile);
strcpy(m_GetDatabase.m_NewStock[i].m_NewStockCode,temp);
}
////////////////////////////////////////////////////////////////////////////////////////
m_pWnd=new CWnd;
m_pWnd->CreateEx(0,AfxRegisterWndClass(CS_DBLCLKS),"",WS_POPUP,CRect(0,0,1024,704),this,0);
m_pWnd->ShowWindow(TRUE);
pDC=m_pWnd->GetDC();
m_pMemDC=new CDC;
m_Rect=CRect(0,0,1536,704);
CBitmap m_Bitmap;
m_pMemDC->CreateCompatibleDC(pDC);
m_Bitmap.CreateCompatibleBitmap(pDC,m_Rect.Width(),m_Rect.Height());
m_pMemDC->SelectObject(&m_Bitmap);
brush.CreateSolidBrush(RGB(0,0,0));
m_pMemDC->SelectObject(&brush);
m_pMemDC->FillRect(CRect(0,0,m_Rect.Width(),m_Rect.Height()),&brush);
m_Bitmap.DeleteObject();
int ret;
ret=writeled.ReadAddress();
RECT rect;
GetWindowRect(&rect);
RECT m_WindowRect;
CWnd* pWnd=GetDesktopWindow();
pWnd->GetWindowRect(&m_WindowRect);
MoveWindow((m_WindowRect.right-rect.right+rect.left)/2,
(m_WindowRect.bottom-54),
rect.right-rect.left,
rect.bottom-rect.top,
TRUE);
// TODO: Add extra initialization here
//CDC* pDC=m_pWnd->GetDC();
CBrush bluebrush(RGB(0,0,255));
CBrush* Oldbrush=(CBrush*)pDC->SelectObject(&bluebrush);
CRect rc=CRect(0,0,1024,704);
pDC->Rectangle(rc);
pDC->SelectObject(Oldbrush);
//产生各种字体
OnCreate_AllKindsOfFonts();
m_GetDatabase.Open("SJSHQ");
SetTimer(1,1000,NULL);
SetWindowText("深圳交易所");
//设置确省显示字幕为公告
CButton* pbut=(CButton*)GetDlgItem(IDC_RADIO1);
pbut->SetCheck(1);
return TRUE; // return TRUE unless you set the focus to a control
}
void CSjshqDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CSjshqDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CString st;
CRect dRect4=CRect(0,180,1024,704);
int butID=GetCheckedRadioButton(IDC_RADIO1,IDC_GUOZHAI_RADIO);
if(butID==IDC_GUOZHAI_RADIO)
{
CEdit* pedit=(CEdit*)GetDlgItem(IDC_ZM_BMP_PATH);
pedit->GetWindowText(st);
if(st=="显示国债") //得到"记帐式( 期)国债", 标题
m_ShowBmpFile.Open_DrawTxt0812(m_pWnd,pDC,dRect4.left,dRect4.top,
dRect4.Width(),dRect4.Height(),theApp.Txt_0812,mTxt1Fnt,mTxtTitleFnt);
}
CDialog::OnPaint();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CSjshqDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CSjshqDlg::OnDlgButton(UINT nID)
{
DlgButtonID=nID;
writeled.ClearAddress();
if(nID!=IDC_BUTTON7)
bAutoRun=0;
OnBrush_BlueColor();
}
BOOL CSjshqDlg::OnRunBtn()
{
ShowZst();
ShowHanzi();
LPCTSTR lpszSQL="SELECT * FROM sjshq";
CDC *m_pMemDC1=new CDC;
CBitmap m_Bitmap1;
m_pMemDC1->CreateCompatibleDC(pDC);
m_Bitmap1.CreateCompatibleBitmap(pDC,1024,704);
m_FntOld=(CFont*)m_pMemDC->SelectObject(mhq_GNameFnt);
m_pMemDC->SetBkColor(RGB(0,0,0));
LOGFONT lp;
mhq_GNameFnt->GetLogFont(&lp);
///////////// 处理行情数据到m_pMemDC
if(!m_GetDatabase.GetSzHq(lpszSQL))
{
m_pMemDC1->DeleteDC();
delete m_pMemDC1;
m_Bitmap1.DeleteObject();
m_pMemDC->SelectObject(m_FntOld);
return FALSE;
}
for(int i=0;i<18;i++)
{
if(m_GetDatabase.AGu_Color[i]==1)
m_pMemDC->SetTextColor(RGB(255,0,0));
else if(m_GetDatabase.AGu_Color[i]==2)
m_pMemDC->SetTextColor(RGB(0,255,0));
else
m_pMemDC->SetTextColor(RGB(255,255,0));
m_pMemDC->TextOut(0,122+i*lp.lfHeight,m_GetDatabase.AGu[i],m_GetDatabase.AGu[i].GetLength());
if(m_GetDatabase.BGu_Color[i]==1)
m_pMemDC->SetTextColor(RGB(255,0,0));
else if(m_GetDatabase.BGu_Color[i]==2)
m_pMemDC->SetTextColor(RGB(0,255,0));
else
m_pMemDC->SetTextColor(RGB(255,255,0));
m_pMemDC->TextOut(1088,122+i*lp.lfHeight,m_GetDatabase.BGu[i],m_GetDatabase.BGu[i].GetLength());
}
////////////////////// 处理行情到buf
GetHangQingToBuf();
writeled.WriteToLed();
///////////////////////处理m_pMemDC to m_pMemDC1
m_pMemDC1->SelectObject(&m_Bitmap1);
m_pMemDC1->SelectObject(&brush);
m_pMemDC1->FillRect(CRect(0,0,1024,704),&brush);
m_pMemDC1->SetStretchBltMode(STRETCH_ORSCANS );
m_pMemDC1->StretchBlt(0,0,1024,704,m_pMemDC,256,0,m_Rect.Width()-512,m_Rect.Height(),SRCPAINT);//last
// m_pMemDC1->StretchBlt(0,0,1024,704,m_pMemDC,0,0,m_Rect.Width(),m_Rect.Height(),SRCPAINT);//全局
pDC->BitBlt(0,0,1024,704,m_pMemDC1,0,0,SRCCOPY);
//////////////////////
m_pMemDC->SelectObject(m_FntOld);
m_pMemDC1->DeleteDC();
delete m_pMemDC1;
m_Bitmap1.DeleteObject();
Sleep(3000);
return TRUE;
}
void CSjshqDlg::ShowZst()
{
////////////////////////走势图//////////////////////////////////////////////////////
// CBitmap m_bmp;
m_ShowBmpFile.Open_DrawBmp(m_pWnd,m_pMemDC,448,90+8,627,267,
theApp.ZST1_File,0,2,0,1,482,267);
m_ShowBmpFile.Open_DrawBmp(m_pWnd,m_pMemDC,448,90+11+27+267+8,627,267,
theApp.ZST2_File,0,2,0,1,482,267);
//抹掉多余的下边线
m_pMemDC->FillSolidRect(CRect(448+82,260+90+8,448+82+481,272+90+6),RGB(0,0,0));//宽481,高7
m_pMemDC->FillSolidRect(CRect(448+82,260+90+11+27+267+8,448+82+481,272+90+11+27+267+6),RGB(0,0,0));//268
//刷三个白色框
CBrush* Oldbrush=(CBrush*)m_pMemDC->SelectStockObject(NULL_BRUSH);
CPen* OldPen=(CPen*)m_pMemDC->SelectStockObject(WHITE_PEN);
CRect White_rect1=CRect(448,90,448+640-4,90+610);
m_pMemDC->Rectangle(White_rect1);
CRect White_rect2=CRect(448,90+267+11,448+640-4,90+267+12+27);
m_pMemDC->Rectangle(White_rect2);
CRect White_rect3=CRect(448,90+583,448+640-4,90+583+27);
m_pMemDC->Rectangle(White_rect3);
m_pMemDC->SelectObject(Oldbrush);
m_pMemDC->SelectObject(OldPen);
SetFileAttributes(theApp.ZST1_File,FILE_ATTRIBUTE_NORMAL);
SetFileAttributes(theApp.ZST2_File,FILE_ATTRIBUTE_NORMAL);
}
void CSjshqDlg::ShowHanzi()
{
CString m_str1="成交量 升跌 最近价 证券名称";
CString m_str2="证券名称 最近价 升跌 成交量";
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?