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

📄 formclass.cpp

📁 该模拟器是在Keil7.0中使用。 只要把Ex02Dll.dll复制到 X:KeilC51BIN目录下。 打开测试程序
💻 CPP
字号:
// Formclass.cpp : implementation file
//

#include "stdafx.h"
#include "Ex02Dll.h"
#include "AGSI.H"
#include "Common.h"
#include "Formclass.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CFormclass dialog
static CFormclass  * pCFormclass;

static DWORD  cP0,pP0,stat;

static void FormUpdate (void);
static void FormKill   (AGSIDLGD *pM);
static void FormDisp   (AGSIMENU *pM);

AGSIDLGD FormDlg =  { 0, NULL, NULL, { -1, -1, -1, -1, }, FormUpdate, FormKill };

AGSIMENU FormMenu =  {1, "LED &3" , FormDisp, 0, IDD_DIALOG1,  &FormDlg };  // Peripheral Dialog

static void FormUpdate (void)  {            // Update Function
 if (pCFormclass) pCFormclass->Update();
}

static void FormKill (AGSIDLGD *pM)  {      // Kill Function
 if (pCFormclass == NULL) return;
  pCFormclass->SendMessage (WM_CLOSE);
  pCFormclass  = NULL;
  pM->iOpen = 0;
  pM->hw    = NULL;

}


static void FormDisp (AGSIMENU *pM)  {
  if (pM->pDlg->hw != NULL)  {              // created
    FormKill (pM->pDlg);                    // close
  } else  {
//    AFX_MANAGE_STATE(AfxGetStaticModuleState());// -- not necessary.
    pCFormclass = new CFormclass (pM, NULL);     // modeless construction
    if (pCFormclass != NULL)  {                   // construction was Ok.
      pM->pDlg->hw = pCFormclass->m_hWnd;         // Dialog handle
    }
  }

}


CFormclass::CFormclass (AGSIMENU *pMen, CWnd *pWnd)  {
  pM = pMen;                     // save DYM-Descriptor locally.
  Create (IDD_DIALOG1, pWnd);
  pCFormclass = this;
}

//////////////////////////////////////////////////////////////////////////////



BEGIN_MESSAGE_MAP(CFormclass, CDialog)
	//{{AFX_MSG_MAP(CFormclass)
	ON_WM_CLOSE()
	ON_WM_TIMER()
	ON_WM_PAINT()
	ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CFormclass message handlers
void CFormclass::DispPnum(DWORD Pnum,DWORD value)
{
  CBitmap bitmap1,bitmap2,bitmap3,bitmap4,bitmap5,bitmap6;
  CDC dcMemory;
  POINT Pxy;
  CClientDC dc(this);  
  bitmap1.LoadBitmap(IDB_1);
  bitmap2.LoadBitmap(IDB_2);
  bitmap3.LoadBitmap(IDB_3);
  bitmap4.LoadBitmap(IDB_4);
  bitmap5.LoadBitmap(IDB_5);
  bitmap6.LoadBitmap(IDB_6);
  dcMemory.CreateCompatibleDC(&dc);

 switch (Pnum)
 {
 case P0 :{Pxy.x =10;Pxy.y=10; break;}
 case P1 :{Pxy.x =50;Pxy.y=10; break;}
 case P2 :{Pxy.x =90;Pxy.y=10; break;}
 case P3 :{Pxy.x =130;Pxy.y=10; break;}
 }
 
  dcMemory.SelectObject(&bitmap1);
  if (value&128) dc.BitBlt(Pxy.x-2,Pxy.y,16,3,&dcMemory,0,0,SRCCOPY); else 	 dc.BitBlt(Pxy.x-2,Pxy.y,16,3,&dcMemory,0,0,WHITENESS);
  
  dcMemory.SelectObject(&bitmap2);
  if (value&64)  dc.BitBlt(Pxy.x+13,Pxy.y,3,16,&dcMemory,0,0,SRCCOPY); else	 dc.BitBlt(Pxy.x+13,Pxy.y,3,16,&dcMemory,0,0,WHITENESS);
  
  if (value&32) dc.BitBlt(Pxy.x+13,Pxy.y+16,3,16,&dcMemory,0,0,SRCCOPY); else  dc.BitBlt(Pxy.x+13,Pxy.y+16,3,16,&dcMemory,0,0,WHITENESS);
  
  dcMemory.SelectObject(&bitmap4);
  if (value&16)  dc.BitBlt(Pxy.x,Pxy.y+32,16,3,&dcMemory,0,0,SRCCOPY); else	 dc.BitBlt(Pxy.x,Pxy.y+32,16,3,&dcMemory,0,0,WHITENESS);

  dcMemory.SelectObject(&bitmap3);
  if (value&8) dc.BitBlt(Pxy.x,Pxy.y+16,3,16,&dcMemory,0,0,SRCCOPY); else  dc.BitBlt(Pxy.x,Pxy.y+16,3,16,&dcMemory,0,0,WHITENESS);
  
  if (value&4)  dc.BitBlt(Pxy.x,Pxy.y,3,16,&dcMemory,0,0,SRCCOPY); else dc.BitBlt(Pxy.x,Pxy.y,3,16,&dcMemory,0,0,WHITENESS);
  dcMemory.SelectObject(&bitmap5);
  if (value&2) dc.BitBlt(Pxy.x,Pxy.y+16,16,3,&dcMemory,0,0,SRCCOPY); else  dc.BitBlt(Pxy.x,Pxy.y+16,16,3,&dcMemory,0,0,WHITENESS);
  
  dcMemory.SelectObject(&bitmap6);
  if (value&1)  dc.BitBlt(Pxy.x+16,Pxy.y+32,3,3,&dcMemory,0,0,SRCCOPY); else dc.BitBlt(Pxy.x+16,Pxy.y+32,3,3,&dcMemory,0,0,WHITENESS);
};

void CFormclass::Update()
{
  
  Agsi.ReadSFR(P0,  &cP0,  &pP0,  0xFF);
 
  if (IsDlgButtonChecked(IDC_CHECK1) )cP0=~cP0;
  DispPnum(P0,cP0);

  Agsi.ReadSFR(P1,  &cP0,  &pP0,  0xFF);
  if (IsDlgButtonChecked(IDC_CHECK2) )cP0=~cP0;
  DispPnum(P1,cP0);

 
  Agsi.ReadSFR(P2,  &cP0,  &pP0,  0xFF);
  if (IsDlgButtonChecked(IDC_CHECK3) )cP0=~cP0;
  DispPnum(P2,cP0);

  Agsi.ReadSFR(P3,  &cP0,  &pP0,  0xFF);
  if (IsDlgButtonChecked(IDC_CHECK4) )cP0=~cP0;
  DispPnum(P3,cP0);
}

void CFormclass::PostNcDestroy() 
{
	// TODO: Add your specialized code here and/or call the base class
  delete this;              // delete the new'ed object
  pCFormclass = NULL;      // clear external Object pointer here.

}

void CFormclass::OnClose() 
{
	// TODO: Add your message handler code here and/or call default
  GetWindowRect (&pM->pDlg->rc);  // save Window position
  pM->pDlg->hw = NULL;            // clear m_hWnd
  DestroyWindow();                //--- modeless
}

BOOL CFormclass::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	// TODO: Add extra initialization here

  if (FormDlg.rc.left != -1) {
 	SetWindowPos(NULL,                        /* placement order - not used */
                 FormDlg.rc.left,             /* left */
                 FormDlg.rc.top,              /* top  */
                 0,                           /* width - not used */
                 0,                           /* height - not used */
                 SWP_NOSIZE | SWP_NOZORDER);  /* flags */
  }

  Update();	
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CFormclass::OnTimer(UINT nIDEvent) 
{
	// TODO: Add your message handler code here and/or call default
	Agsi.UpdateWindows();
	CDialog::OnTimer(nIDEvent);
}


void CFormclass::OnPaint() 
{
	CPaintDC dc(this); // device context for painting
	
	// TODO: Add your message handler code here
	dc.Rectangle(5,    5,33,    48);
	dc.Rectangle(5+40, 5,33+40, 48);
	dc.Rectangle(5+80, 5,33+80, 48);
	dc.Rectangle(5+120,5,33+120,48);


	// Do not call CDialog::OnPaint() for painting messages
}

void CFormclass::OnButton1() 
{
	// TODO: Add your control notification handler code here
  CString str1;
  GetDlgItemText(IDC_BUTTON1,str1);
  if (str1.Compare("实时")==0) 
  {
	  m_nTimer = SetTimer(1, 3, NULL);
      SetDlgItemText(IDC_BUTTON1,"跟踪");
  }
  else
  {
	  if (m_nTimer!=0) KillTimer(m_nTimer);	
	  SetDlgItemText(IDC_BUTTON1,"实时");
  }
}

⌨️ 快捷键说明

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