⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 screendlg.cpp

📁 一个很不错的
💻 CPP
📖 第 1 页 / 共 4 页
字号:
	  time3=time4;
	  time4=time5;
      time5=GetCurrentTime();
   }
   m_price5.Format("%f",price5);
   m_price4.Format("%f",price4);
   m_price3.Format("%f",price3);
   m_price2.Format("%f",price2);
   m_price1.Format("%f",price1);
   m_price5=m_price5.Left(5);
   m_price4=m_price4.Left(5);
   m_price3=m_price3.Left(5);
   m_price2=m_price2.Left(5);
   m_price1=m_price1.Left(5);


return;
}

void CScreenDlg::image_capture()
{
    
    m_bitmap.Detach();
	UpdateData(FALSE);
	hScreenDC = ::GetDC(hWnd);   //获得屏幕的HDC.
	MemDC = ::CreateCompatibleDC(hScreenDC);
//	RECT rect;
//1002 max of column
//780 原捕捉的位置
//795 直线的位置
//	795-72-231=795-293=502
// 75 width of k
// 24 windth of blank
//497 position of 3th k
//552 position of 4th k 597-552+1=46=width of k  613-552=16=windth of blank  
//469 position of 7th k 35 width of k  11 windth of blank  	
	::GetWindowRect(hWnd,&rect);


	rect.bottom=rect.bottom-24;
    rect.left=rect.left+469;
    SIZE screensize;
	screensize.cx=rect.right-rect.left;
	screensize.cy=rect.bottom-rect.top;
	 hBitmap = ::CreateCompatibleBitmap(hScreenDC,screensize.cx,screensize.cy);
	 hOldBMP = ::SelectObject(MemDC,hBitmap);

	::BitBlt(MemDC,0,0,screensize.cx,screensize.cy,hScreenDC,469,0,SRCCOPY);
//	::BitBlt(MemDC,0,0,screensize.cx,screensize.cy,hScreenDC,721,666,SRCCOPY);
	::SelectObject(MemDC,hOldBMP);
	::DeleteObject(MemDC);
	::ReleaseDC(hWnd,hScreenDC);
	

///	::SetForegroundWindow(m_hWnd);
//    AfxGetMainWnd()->ShowWindow(SW_NORMAL);     
    
//	WriteBmpToFile(hBitmap,	"d:\\128.bmp");

//  BITMAP   bm;   
//  GetObject(hBitmap,sizeof(bm),&bm);
  m_bitmap.Attach(hBitmap);
  m_bitmap.GetBitmap(&bm);
  m_bitmap.GetBitmapBits(bm.bmHeight*bm.bmWidthBytes,px); 
  ::DeleteObject(hBitmap);
	return;
}

void CScreenDlg::OnTimer(UINT nIDEvent) 
{
	// TODO: Add your message handler code here and/or call default
    image_capture();
	get_arrow();
	get_price();
//	get_time();
	UpdateData(FALSE);

/*	if (m_pre_time=="00:00")
	    m_pre_time=m_curr_time;
	if (m_curr_time<="09:27" && m_curr_time.GetLength()==5)
		return;
	if (m_curr_time>"09:27" && m_curr_time<="09:31" && atof(curr_price.GetBuffer(0))!=0 ) //开盘前操作程序
	{
		if ( atof(curr_price.GetBuffer(0)) <= end_price )
		   return;
		else
		{
			OnButton3(); //买入
			return;
		}
	}
    if (m_curr_time=="09:31")
		curr_status="333333"+curr_status.Right(1);
    if (m_curr_time=="09:32")
		curr_status="33333"+curr_status.Right(2);
    if (m_curr_time=="09:33")
		curr_status="3333"+curr_status.Right(3);
    if (m_curr_time=="09:34")
		curr_status="333"+curr_status.Right(4);
    if (m_curr_time=="09:35")
		curr_status="33"+curr_status.Right(5);
    if (m_curr_time=="09:36")
		curr_status="3"+curr_status.Right(6);


    if (m_curr_time=="15:30")  //尾盘操作程序
	{
		seconds++;
		if (seconds<10 )
			return;
		else if (seconds>=10 && seconds <60) 
		{
			OnButton1(); //买出
			return;
		}
		else if (seconds>=60)
		{
			WritePrivateProfileString("config", "end_price",curr_price.GetBuffer(0), ".\\config.ini");
			return;
		}
	}

	if (curr_status=="0000000") //止损操作
	{
		if (atof(curr_price.GetBuffer(0))<atof(m_buy_price.GetBuffer(0))*stop_lost)
		{
			OnButton1(); //卖出
            pre_status=curr_status;
	        m_pre_time=m_curr_time;
			return;
		}
	}


   if (m_curr_time !=m_pre_time) //出现新的k块
   {
      if (pre_status.Left(1)!="0")
	     before_7_arrow=pre_status.Left(1);
   }

    if (  curr_status==pre_status.Right(6)+"0" && m_curr_time !=m_pre_time )
	{
        pre_status=curr_status;
	    m_pre_time=m_curr_time;
		return;
	}

*/
	GetLocalTime(&CurTime);
    sYear.Format("%d年",CurTime.wYear);
    sMonth.Format("%d月",CurTime.wMonth);
    sDay.Format("%d日",CurTime.wDay);
    sHour.Format("%d时",CurTime.wHour);
    sMinute.Format("%d分",CurTime.wMinute);
    sSecond.Format("%d秒",CurTime.wSecond);
	curr_time= sYear+ sMonth + sDay+ sHour+sMinute+sSecond;
   
   m_list.InsertString(0, curr_time + " -> "+curr_status+" -> "+curr_price );
   if (m_list.GetCount()>50)
	   	m_list.ResetContent();

 /*  try
	{
		// 写入各字段值
		m_pRecordset->AddNew();
		m_pRecordset->PutCollect("curr_price", _variant_t(curr_price));
		m_pRecordset->PutCollect("curr_time", _variant_t(curr_time));
		m_pRecordset->PutCollect("curr_status", _variant_t(curr_status));
		m_pRecordset->Update();
	}
	catch(_com_error *e)
	{
		AfxMessageBox(e->ErrorMessage());
	}
*/
 /* if ( oper_condition() == 1 ) //买入
  {
     TradeTime=CurTime;
	 OnButton3();
     pre_status=curr_status;
	 m_pre_time=m_curr_time;

  }
  if ( oper_condition() == 2 ) //卖出
  {
	 TradeTime=CurTime;
	 OnButton1();
     pre_status=curr_status;
	 m_pre_time=m_curr_time;
  }
  */
//	timespan1=time5-time3;
	
/*	if (price5>price4 && price4>price3 && (int)timespan1.GetTotalSeconds() < 30000)
		OnButton3();
	if (price5<price4 && price4<price3  && (int)timespan1.GetTotalSeconds() < 60000)
		OnButton1();
*/
     pre_status=curr_status;
	 m_pre_time=m_curr_time;

  CDialog::OnTimer(nIDEvent);
}





void CScreenDlg::OnButton1() 
{
	// TODO: Add your control notification handler code here
	//卖出股票
 	if (m_kmsl=="0")
		return;
//	if ( atof(curr_price.GetBuffer(0)) < atof(m_buy_price.GetBuffer(0))*1.0006 )
//		return;
	
	KillTimer(IDT_TIMER);  //close timer
	CString m_price,m_kmsl_temp,curr_status_temp;
    m_price.Format("%f",atof(curr_price.GetBuffer(0)) * sell_coef);
	m_price=m_price.Left(m_price.Find(".")+4);

	sell(m_kmsl,m_price); //first attempt
	Sleep(5000);
    read_fund();
//	Sleep(1000);
   // if (m_kmsl!="0")
       undo_trade();

	pre_status=curr_status;
	m_pre_time=m_curr_time;

	SetTimer(IDT_TIMER, INITIAL_DELAY, NULL); //open timer

  
}

void CScreenDlg::buy(CString kmsl,CString jiage)
{
	char sCaption[20];	
	HWND hwnd1,hwnd2,hwnd_f3,hwnd_esc;
    char buf[16]="";
	hwnd1=hWnd2;
	hwnd1=::GetWindow(hwnd1,GW_CHILD);
    hwnd1=::GetWindow(hwnd1,GW_CHILD);
    hwnd1=::GetWindow(hwnd1,GW_CHILD);
    for (int i11=0;i11<44;i11++)
	   hwnd1=::GetNextWindow(hwnd1,GW_HWNDNEXT);

    hWnd_in=hwnd1;
	::SendMessage(hWnd_in,BM_CLICK,0,0);

	Sleep(200);
    hwnd1=hWnd2;
    hwnd1=::GetWindow(hwnd1,GW_CHILD);
    hwnd1=::GetWindow(hwnd1,GW_CHILD);
    hwnd1=::GetWindow(hwnd1,GW_CHILD);
    hwnd1=::GetWindow(hwnd1,GW_CHILD);
    hwnd1=::GetWindow(hwnd1,GW_CHILD);
	hwnd1=::GetNextWindow(hwnd1,GW_HWNDNEXT);

    hwnd1=::GetWindow(hwnd1,GW_CHILD);
	hwnd1=::GetNextWindow(hwnd1,GW_HWNDNEXT);
	hwnd1=::GetNextWindow(hwnd1,GW_HWNDNEXT);
	hwnd1=::GetNextWindow(hwnd1,GW_HWNDNEXT);

		//jiage
	strcpy(buf,jiage);
	::SendMessage(hwnd1,WM_SETTEXT,16,(LPARAM)buf);

	hwnd1=::GetNextWindow(hwnd1,GW_HWNDNEXT);
	//shuliang
	strcpy(buf,kmsl);
	::SendMessage(hwnd1,WM_SETTEXT,16,(LPARAM)buf);

	hwnd1=::GetNextWindow(hwnd1,GW_HWNDNEXT);
	hwnd1=::GetNextWindow(hwnd1,GW_HWNDNEXT);
    //gplb
	strcpy(buf,m_gplb);
	::SendMessage(hwnd1,CB_SELECTSTRING,-1,(LPARAM)buf);

	hwnd1=::GetNextWindow(hwnd1,GW_HWNDNEXT);
	hwnd1=::GetNextWindow(hwnd1,GW_HWNDNEXT);
	hwnd1=::GetNextWindow(hwnd1,GW_HWNDNEXT);
    //gpdm
    strcpy(buf,m_gpdm);
//	::SetForegroundWindow(hwnd1);
	::SendMessage(hwnd1,WM_SETTEXT,16,(LPARAM)buf);
	
     //tijiao 卖出F3
   hwnd2=hWnd_in;
   hwnd2=::GetNextWindow(hwnd2,GW_HWNDNEXT);
 //  hwnd2=::GetNextWindow(hwnd2,GW_HWNDNEXT);
   hwnd2=::GetWindow(hwnd2,GW_CHILD);
   hwnd2=::GetWindow(hwnd2,GW_CHILD);
 	do 
	{
		::GetWindowText(hwnd2,sCaption,20);
		if ((CString)sCaption=="买入F3")
		  hwnd_f3=hwnd2;
		if ((CString)sCaption=="返回ESC")
		  hwnd_esc=hwnd2;
		hwnd2=::GetNextWindow(hwnd2,GW_HWNDNEXT);
	} while (hwnd2!=NULL) ;
/*   hwnd2=::GetNextWindow(hwnd2,GW_HWNDNEXT);
//   hwnd2=::GetNextWindow(hwnd2,GW_HWNDNEXT);
//   hwnd2=::GetNextWindow(hwnd2,GW_HWNDNEXT);
   hwnd2=::GetNextWindow(hwnd2,GW_HWNDNEXT);
   hwnd_f3=hwnd2;
   hwnd2=::GetNextWindow(hwnd2,GW_HWNDNEXT);
   hwnd2=::GetNextWindow(hwnd2,GW_HWNDNEXT);
   hwnd_esc=hwnd2;
//   MessageBox("wait1");
*/   Sleep(200);
   ::SendMessage(hwnd_f3,BM_CLICK,0,0);

   Sleep(100);
  
   hwnd2=::FindWindow(NULL,"警告");

   if (hwnd2)
   {
	  hwnd2=::GetWindow(hwnd2,GW_CHILD);
      //取消
      //   ::SendMessage(hwnd2,BM_CLICK,0,0);
//	  MessageBox("1");
	  hwnd2=::GetNextWindow(hwnd2,GW_HWNDNEXT);
      //确定
      ::PostMessage(hwnd2,BM_CLICK,0,0);
	  }
   
   hwnd2=::FindWindow(NULL,"提示信息");
   if (hwnd2)
   {
	  hwnd2=::GetWindow(hwnd2,GW_CHILD);
      //取消
      //   ::SendMessage(hwnd2,BM_CLICK,0,0);
	  //hwnd2=::GetNextWindow(hwnd2,GW_HWNDNEXT);
      //确定
      ::PostMessage(hwnd2,BM_CLICK,0,0);
	  }
   Sleep(100);
   //返回
   ::PostMessage(hwnd_esc,BM_CLICK,0,0);
  
return;
}

void CScreenDlg::sell(CString kmsl,CString jiage)
{
	char buf[16]="";
	char sCaption[20];
//	UpdateData(FALSE);
	HWND hwnd1,hwnd2,hwnd_f3;
	if (m_kmsl=="0")
		return;
	::GetLocalTime(&TradeTime);
	hwnd1=hWnd2;
	hwnd1=::GetWindow(hwnd1,GW_CHILD);
    hwnd1=::GetWindow(hwnd1,GW_CHILD);
    hwnd1=::GetWindow(hwnd1,GW_CHILD);
    for (int i11=0;i11<43;i11++)
	   hwnd1=::GetNextWindow(hwnd1,GW_HWNDNEXT);

    hWnd_out=hwnd1;
	::SendMessage(hWnd_out,BM_CLICK,0,0);

	Sleep(400);
    hwnd1=hWnd2;
    hwnd1=::GetWindow(hwnd1,GW_CHILD);
    hwnd1=::GetWindow(hwnd1,GW_CHILD);
    hwnd1=::GetWindow(hwnd1,GW_CHILD);
    hwnd1=::GetWindow(hwnd1,GW_CHILD);
    hwnd1=::GetWindow(hwnd1,GW_CHILD);
	hwnd1=::GetNextWindow(hwnd1,GW_HWNDNEXT);

    hwnd1=::GetWindow(hwnd1,GW_CHILD);
	hwnd1=::GetNextWindow(hwnd1,GW_HWNDNEXT);
	hwnd1=::GetNextWindow(hwnd1,GW_HWNDNEXT);
	::SetForegroundWindow(hwnd1);
	//shuliang
	strcpy(buf, kmsl.GetBuffer(0));
	::SendMessage(hwnd1,WM_SETTEXT,16,(LPARAM)buf);

	hwnd1=::GetNextWindow(hwnd1,GW_HWNDNEXT);
	hwnd1=::GetNextWindow(hwnd1,GW_HWNDNEXT);
    //jiage

	strcpy(buf,jiage);
	::SendMessage(hwnd1,WM_SETTEXT,16,(LPARAM)buf);

	hwnd1=::GetNextWindow(hwnd1,GW_HWNDNEXT);
	hwnd1=::GetNextWindow(hwnd1,GW_HWNDNEXT);
    //gplb
	strcpy(buf,m_gplb);
	::SendMessage(hwnd1,CB_SELECTSTRING,-1,(LPARAM)buf);

	hwnd1=::GetNextWindow(hwnd1,GW_HWNDNEXT);
	hwnd1=::GetNextWindow(hwnd1,GW_HWNDNEXT);
    //gpdm
    strcpy(buf,m_gpdm);
//	::SetForegroundWindow(hwnd1);
	::SendMessage(hwnd1,WM_SETTEXT,16,(LPARAM)buf);
//    ::UpdateData(hwnd1,FALSE);
	
     //tijiao 卖出F3
   hwnd2=hWnd_out;
   hwnd2=::GetNextWindow(hwnd2,GW_HWNDNEXT);
   hwnd2=::GetNextWindow(hwnd2,GW_HWNDNEXT);
   hwnd2=::GetWindow(hwnd2,GW_CHILD);
   hwnd2=::GetWindow(hwnd2,GW_CHILD);
 	do 
	{
		::GetWindowText(hwnd2,sCaption,20);
		if ((CString)sCaption=="卖出F3")
		  hwnd_f3=hwnd2;
		if ((CString)sCaption=="返回ESC")
		  hwnd_esc=hwnd2;
		hwnd2=::GetNextWindow(hwnd2,GW_HWNDNEXT);
	} while (hwnd2!=NULL) ;


//   hwnd2=::GetNextWindow(hwnd2,GW_HWNDNEXT);
//   hwnd2=::GetNextWindow(hwnd2,GW_HWNDNEXT);
//  hwnd2=::GetNextWindow(hwnd2,GW_HWNDNEXT);
//   hwnd2=::GetNextWindow(hwnd2,GW_HWNDNEXT);
//   hwnd_f3=hwnd2;
//   hwnd2=::GetNextWindow(hwnd2,GW_HWNDNEXT);
//   hwnd2=::GetNextWindow(hwnd2,GW_HWNDNEXT);
//   hwnd_esc=hwnd2;
 //  MessageBox("wait2");
   Sleep(200);
   ::SendMessage(hwnd_f3,BM_CLICK,0,0);

   Sleep(100);
  
   hwnd2=::FindWindow(NULL,"警告");

   if (hwnd2)
   {
	  hwnd2=::GetWindow(hwnd2,GW_CHILD);
      //取消
      //   ::SendMessage(hwnd2,BM_CLICK,0,0);
//	  MessageBox("1");
	  hwnd2=::GetNextWindow(hwnd2,GW_HWNDNEXT);
      //确定
      ::PostMessage(hwnd2,BM_CLICK,0,0);
	  }
   
   hwnd2=::FindWindow(NULL,"提示信息");
   if (hwnd2)
   {
	  hwnd2=::GetWindow(hwnd2,GW_CHILD);
      //取消
      //   ::SendMessage(hwnd2,BM_CLICK,0,0);
	  //hwnd2=::GetNextWindow(hwnd2,GW_HWNDNEXT);
      //确定
      ::PostMessage(hwnd2,BM_CLICK,0,0);
	  }
   Sleep(100);
   //返回
   ::PostMessage(hwnd_esc,BM_CLICK,0,0);

	return;
}

void CScreenDlg::OnButton3() 
{
	// TODO: Add your control notification handler code here
	//买入	

    CString m_kmsl_temp,curr_status_temp;
//	KillTimer(IDT_TIMER);  //close timer
 /*   curr_status_temp= curr_status;
	Sleep(3000);
    image_capture();
    get_arrow();
    if (curr_status_temp != curr_status)
	{
    	SetTimer(IDT_TIMER, INITIAL_DELAY, NULL); //open timer
		return;
	}
	UpdateData(FALSE);
    m_kmsl_temp=m_kmsl; 
*/
	CString m_price;
    m_price.Format("%f",atof(curr_price.GetBuffer(0)) * buy_coef);
	m_price=m_price.Left(m_price.Find(".")+4);

	int m_shuliang;
	CString s_shuliang;
    m_shuliang=(int) (atof(m_zyzj.GetBuffer(0)) / atof(m_price.GetBuffer(0))*1.003) /100;
    m_shuliang=100*m_shuliang;
    s_shuliang.Format("%d",m_shuliang);
    if (m_shuliang==0)
	{
  //  	SetTimer(IDT_TIMER, INITIAL_DELAY, NULL); //open timer
		return;
	}
	KillTimer(IDT_TIMER);  //close timer	
	::GetLocalTime(&TradeTime);

	m_buy_price=m_price,
    UpdateData(FALSE);
    WritePrivateProfileString("config", "buy_price",m_price.GetBuffer(0), ".\\config.ini");
    s_shuliang="100";
	buy(s_shuliang,m_price);//first attempt
//	buy(100,m_price);//first attempt
//	Sleep(1000);
	Sleep(5000);
    read_fund();
//	Sleep(3000);
//	if (m_kmsl=="0")
	   undo_trade();

/*	if (m_kmsl!=m_kmsl_temp)
    	undo_trade();
    read_fund();

	if (m_kmsl==m_kmsl_temp)
	{
 	    buy(s_shuliang,m_price); //second attempt
        read_fund();
	    if (m_kmsl!=m_kmsl_temp)
    	   undo_trade();
        read_fund();
	}
	
*/
	 pre_status=curr_status;
	 m_pre_time=m_curr_time;

	SetTimer(IDT_TIMER, INITIAL_DELAY, NULL); //open timer
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -