📄 screendlg.cpp
字号:
// screenDlg.cpp : implementation file
//
#include "stdafx.h"
#include "screen.h"
#include "screenDlg.h"
#include "windows.h"
#include <process.h>
#include <math.h>
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#define INITIAL_DELAY 1000
#define REPEAT_DELAY 1000
#define IDT_TIMER 1
int fund_limit;
float buy_coef,sell_coef,stop_lost,end_price;
int fresh_needed=1; // 0 不需要 1需要
int buy_action=0;
int sell_action=0;
int seconds=0;
float price1,price2,price3,price4,price5;
HWND hWnd;//曲线窗口
HWND hWnd1;//资产窗口
HWND hWnd2;
HWND hWnd_in;//买入卖出窗口
HWND hWnd_out;//卖出窗口
HWND hWnd_plcd;//批量撤单窗口
HWND hWnd1_fresh;//fresh button in hWnd1;
HWND hWnd1_gpsl;
HWND hWnd1_kyzj;
HWND hWnd1_1;
HWND hwnd_esc;
CString arrow_color;//green 1, red 2,none 0
CString pre_status="3333333";
CString curr_status; //green 1, red 2, none 0
CString curr_time;
CString curr_price;
SYSTEMTIME CurTime,CurTime1;
SYSTEMTIME TradeTime;
SYSTEMTIME UnTradeTime,change_time;
CTime time1,time2,time3,time4,time5;
CTimeSpan timespan1;
CString before_7_arrow="0";
CString m_pre_time="00:00";
int is_undo=0;//0 不需要撤单,1 需要撤单
int undo_time;
CString sTime,sYear,sMonth,sDay,sHour,sMinute,sSecond;
HDC hScreenDC;
HDC MemDC;
RECT rect;
SIZE screensize;
HBITMAP hBitmap;
HGDIOBJ hOldBMP;
BITMAP bm;
HDC hScreenDC1;
HDC MemDC1;
RECT rect1;
SIZE screensize1;
HBITMAP hBitmap1;
HGDIOBJ hOldBMP1;
BITMAP bm1;
unsigned char *px1=new unsigned char [320]; //当前价格每个数字图象
unsigned char *px=new unsigned char [552*675*4]; //箭头图象大小
unsigned char *px2=new unsigned char [35*675*4]; //k块图象
unsigned char *px3=new unsigned char [180]; //当前时间每个数字图象
unsigned char *px_data=new unsigned char [505*699*4]; //可用资金图象及持股数字大小
unsigned char *px_data_3=new unsigned char [160]; //可用资金图象及持股数字大小每个数字图象
CString project1( unsigned char *px1,int a,int b);
CString project2( unsigned char *px1);
CString project3( unsigned char *px3);
CString character(CString vector);
CString character2(CString vector);
CString character3(CString vector);
CString arrow(unsigned char *px,int a,int b,int c);
void WriteBmpToFile(HBITMAP hBitmap, char* m_strFilePath);
void undo_trade();
int oper_condition();
CString minute_add(CString s,int i);
CString difference(CString a1, CString a2);
CString right_most(CString a1);
/////////////////////////////////////////////////////////////////////////////
// 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()
/////////////////////////////////////////////////////////////////////////////
// CScreenDlg dialog
CScreenDlg::CScreenDlg(CWnd* pParent /*=NULL*/)
: CDialog(CScreenDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CScreenDlg)
m_kmsl = _T("");
m_gplb = _T("");
m_zyzj = _T("");
m_gpdm = _T("");
m_gplb1 = -1;
m_buy_price = _T("");
m_curr_time = _T("");
m_price5 = _T("");
m_price4 = _T("");
m_price3 = _T("");
m_price2 = _T("");
m_price1 = _T("");
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CScreenDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CScreenDlg)
DDX_Control(pDX, IDC_LIST1, m_list);
DDX_Text(pDX, IDC_EDIT3, m_kmsl);
DDX_Text(pDX, IDC_EDIT1, m_zyzj);
DDX_Text(pDX, IDC_EDIT4, m_gpdm);
DDX_CBIndex(pDX, IDC_COMBO1, m_gplb1);
DDX_Text(pDX, IDC_EDIT2, m_buy_price);
DDX_Text(pDX, IDC_EDIT5, m_curr_time);
DDX_Text(pDX, IDC_EDIT10, m_price5);
DDX_Text(pDX, IDC_EDIT9, m_price4);
DDX_Text(pDX, IDC_EDIT8, m_price3);
DDX_Text(pDX, IDC_EDIT7, m_price2);
DDX_Text(pDX, IDC_EDIT6, m_price1);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CScreenDlg, CDialog)
//{{AFX_MSG_MAP(CScreenDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
ON_WM_TIMER()
ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
ON_BN_CLICKED(IDC_BUTTON3, OnButton3)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CScreenDlg message handlers
BOOL CScreenDlg::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
if (GetSystemMetrics(SM_CXSCREEN) !=1024 || GetSystemMetrics(SM_CYSCREEN) !=768)
{
AfxMessageBox("该程序必须运行在1024*768模式!", MB_OK|MB_ICONERROR);
exit(0);
}
m_zyzj="1";
pre_zzc="initial";
pre_m_kmsl="initial";
hWnd = ::GetDesktopWindow();
hWnd=::GetWindow(hWnd,GW_CHILD);
char sCaption[20];
CString nanjing;
nanjing="南京证券集成服务平";
do
{
hWnd=::GetNextWindow(hWnd,GW_HWNDNEXT);
::GetWindowText(hWnd,sCaption,20);
if ((CString)sCaption==nanjing)
break;
} while (hWnd!=NULL) ;
if ((CString)sCaption!=nanjing)
{
MessageBox("南京证券未运行!");
exit(0);
}
int a=GetDeviceCaps(::GetDC(hWnd),BITSPIXEL);
if (a !=32)
{
AfxMessageBox("该程序必须运行在32位色模式!", MB_OK|MB_ICONERROR);
exit(0);
}
CString str;
fund_limit=GetPrivateProfileInt("config", "fund_limit",0,".\\config.ini");
undo_time=GetPrivateProfileInt("config", "undo_time",1,".\\config.ini");
GetPrivateProfileString("config", "stock_type","",str.GetBuffer(100), 100, ".\\config.ini");
str.ReleaseBuffer();
m_gplb=str;
if (m_gplb=="深圳A股股票")
m_gplb1=2;
else
m_gplb1=1;
GetPrivateProfileString("config", "stock_code","",str.GetBuffer(100), 100, ".\\config.ini");
str.ReleaseBuffer();
m_gpdm=str;
GetPrivateProfileString("config", "buy_price","",str.GetBuffer(100), 100, ".\\config.ini");
str.ReleaseBuffer();
m_buy_price=str;
UpdateData(FALSE);
GetPrivateProfileString("config", "buy_coefficient","",str.GetBuffer(100), 100, ".\\config.ini");
str.ReleaseBuffer();
buy_coef=atof(str.GetBuffer(0));
GetPrivateProfileString("config", "sell_coefficient","",str.GetBuffer(100), 100, ".\\config.ini");
str.ReleaseBuffer();
sell_coef=atof(str.GetBuffer(0));
GetPrivateProfileString("config", "stop_lost","",str.GetBuffer(100), 100, ".\\config.ini");
str.ReleaseBuffer();
stop_lost=atof(str.GetBuffer(0));
GetPrivateProfileString("config", "end_price","",str.GetBuffer(100), 100, ".\\config.ini");
str.ReleaseBuffer();
end_price=atof(str.GetBuffer(0));
hWnd=::GetWindow(hWnd,GW_CHILD);
hWnd=::GetWindow(hWnd,GW_CHILD);
hWnd=::GetWindow(hWnd,GW_CHILD);
hWnd1 = ::GetDesktopWindow();
hWnd1=::GetWindow(hWnd1,GW_CHILD);
do
{
hWnd1=::GetNextWindow(hWnd1,GW_HWNDNEXT);
::GetWindowText(hWnd1,sCaption,20);
if ((CString)sCaption=="南京证券")
break;
} while (hWnd1!=NULL) ;
if ((CString)sCaption!="南京证券")
{
MessageBox("南京证券1未运行!");
exit(0);
}
::MoveWindow (hWnd1,-50,150,100,100,0);
hWnd2=hWnd1;
do
{
hWnd2=::GetNextWindow(hWnd2,GW_HWNDNEXT);
::GetWindowText(hWnd2,sCaption,20);
if ((CString)sCaption=="南京证券")
break;
} while (hWnd2!=NULL) ;
do
{
hWnd2=::GetNextWindow(hWnd2,GW_HWNDNEXT);
::GetWindowText(hWnd2,sCaption,20);
if ((CString)sCaption=="南京证券")
break;
} while (hWnd2!=NULL) ;
if ((CString)sCaption!="南京证券")
{
MessageBox("南京证券2未运行!");
exit(0);
}
::MoveWindow (hWnd2,-50,430,100,100,0);
hWnd1_1=::GetWindow(hWnd1,GW_CHILD);
hWnd1_1=::GetWindow(hWnd1_1,GW_CHILD);
hWnd1_1=::GetWindow(hWnd1_1,GW_CHILD);
for (int i11=0;i11<37;i11++)
hWnd1_1=::GetNextWindow(hWnd1_1,GW_HWNDNEXT);
::PostMessage(hWnd1_1,BM_CLICK,0,0);
Sleep(1000);
hWnd1_fresh=hWnd1_1;
for ( i11=0;i11<8;i11++)
hWnd1_fresh=::GetNextWindow(hWnd1_fresh,GW_HWNDNEXT);
hWnd1_fresh=::GetWindow(hWnd1_fresh,GW_CHILD);
hWnd1_fresh=::GetWindow(hWnd1_fresh,GW_CHILD);
hWnd1_fresh=::GetNextWindow(hWnd1_fresh,GW_HWNDNEXT);
hWnd1_1=::GetWindow(hWnd1,GW_CHILD);
hWnd1_1=::GetWindow(hWnd1_1,GW_CHILD);
hWnd1_1=::GetWindow(hWnd1_1,GW_CHILD);
hWnd1_1=::GetWindow(hWnd1_1,GW_CHILD);
hWnd1_1=::GetNextWindow(hWnd1_1,GW_HWNDNEXT);
hWnd1_kyzj=::GetWindow(hWnd1_1,GW_CHILD);
hWnd1_gpsl=::GetNextWindow(hWnd1_1,GW_HWNDNEXT);
hWnd_plcd=hWnd2;
for (i11=0;i11<39;i11++)
hWnd_plcd=::GetNextWindow(hWnd_plcd,GW_HWNDNEXT);
hWnd_out=hWnd2;
for (i11=0;i11<43;i11++)
hWnd_out=::GetNextWindow(hWnd_out,GW_HWNDNEXT);
hWnd_in=::GetNextWindow(hWnd_out,GW_HWNDNEXT);
AfxOleInit();
m_pConnection.CreateInstance(__uuidof(Connection));
try
{
m_pConnection->Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=Demo.mdb","","",adModeUnknown);
}
catch(_com_error e)
{
AfxMessageBox("数据库连接失败,确认数据库Demo.mdb是否在当前路径下!");
return FALSE;
}
m_pRecordset.CreateInstance(__uuidof(Recordset));
m_pRecordset1.CreateInstance(__uuidof(Recordset));
try
{
m_pRecordset->Open("SELECT * FROM Table1", // 查询DemoTable表中所有字段
m_pConnection.GetInterfacePtr(), // 获取库接库的IDispatch指针
adOpenDynamic,
adLockOptimistic,
adCmdText);
m_pRecordset1->Open("SELECT * FROM Table2", // 查询DemoTable表中所有字段
m_pConnection.GetInterfacePtr(), // 获取库接库的IDispatch指针
adOpenDynamic,
adLockOptimistic,
adCmdText);
}
catch(_com_error *e)
{
AfxMessageBox(e->ErrorMessage());
}
/* hScreenDC = ::GetDC(hWnd); //获得屏幕的HDC.
MemDC = ::CreateCompatibleDC(hScreenDC);
::GetWindowRect(hWnd,&rect);
rect.bottom=rect.bottom-50;
rect.left=rect.left+780;
SIZE screensize;
screensize.cx=rect.right-rect.left;
screensize.cy=rect.bottom-rect.top;
hBitmap = ::CreateCompatibleBitmap(hScreenDC,screensize.cx,screensize.cy);
*/
return TRUE; // return TRUE unless you set the focus to a control
}
void CScreenDlg::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 CScreenDlg::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
{
CDialog::OnPaint();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CScreenDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
CString difference(CString a1, CString a2)
{
CString s1,s2;
int i;
i=a1.GetLength();
for (int j=i;j>0;j--)
{
if ( a1.Mid(j-1,1) != "0" || a2.Mid(j-1,1) != "0")
{
s1=a1.Mid(j-1,1);
s2=a1.Mid(j-1,1)+a2.Mid(j-1,1);
return s2;
}
}
return "00";
}
CString right_most(CString a1)
{
int i=6;
for (int j=i;j>=0;j--)
{
if (a1.Mid(i,1)!="0")
return a1.Mid(i,1);
}
return "0";
}
int oper_condition()
{
// AfxMessageBox(difference(pre_status,curr_status));
int i=0;
if (curr_status=="0000000")
{
if (before_7_arrow=="1")
return 2;
if (before_7_arrow=="2")
return 1;
}
if (right_most(curr_status)=="1")
return 2;
if (right_most(curr_status)=="2")
return 1;
if (difference(pre_status,curr_status)=="01")
return 2;
if (difference(pre_status,curr_status)=="20")
return 2;
if (difference(pre_status,curr_status)=="21")
return 2;
if (difference(pre_status,curr_status)=="02")
return 1;
if (difference(pre_status,curr_status)=="10")
return 1;
if (difference(pre_status,curr_status)=="12")
return 1;
return i;
}
void CScreenDlg::read_fund()
{
::PostMessage(hWnd1_fresh,BM_CLICK,0,0);
Sleep(2000);
m_bitmap1.Detach();
hScreenDC1 = ::GetDC(hWnd1_gpsl); //获得屏幕的HDC.
MemDC1 = ::CreateCompatibleDC(hScreenDC1);
::GetWindowRect(hWnd1_gpsl,&rect1);
rect1.left=rect1.left+323;
rect1.right=rect1.left+56;
rect1.top=rect1.top+23;
rect1.bottom=rect1.top+8;
SIZE screensize;
screensize.cx=rect1.right-rect1.left;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -