home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Controls / Visual Basic Controls.iso / vbcontrol / aals / aals.exe / DISK1 / _SETUP.1 / VCDemoDlg.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1997-07-06  |  7.0 KB  |  257 lines

  1. // VCDemoDlg.cpp : implementation file
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "VCDemo.h"
  6. #include "VCDemoDlg.h"
  7. #include "math.h"
  8.  
  9. #ifdef _DEBUG
  10. #define new DEBUG_NEW
  11. #undef THIS_FILE
  12. static char THIS_FILE[] = __FILE__;
  13. #endif
  14.  
  15. /////////////////////////////////////////////////////////////////////////////
  16. // CVCDemoDlg dialog
  17.  
  18. CVCDemoDlg::CVCDemoDlg(CWnd* pParent /*=NULL*/)
  19.     : CDialog(CVCDemoDlg::IDD, pParent)
  20. {
  21.     //{{AFX_DATA_INIT(CVCDemoDlg)
  22.         // NOTE: the ClassWizard will add member initialization here
  23.     //}}AFX_DATA_INIT
  24.     // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
  25.     m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
  26.  
  27.     init = FALSE;
  28.     mousedown = FALSE;
  29.  
  30. }
  31.  
  32. void CVCDemoDlg::DoDataExchange(CDataExchange* pDX)
  33. {
  34.     CDialog::DoDataExchange(pDX);
  35.     //{{AFX_DATA_MAP(CVCDemoDlg)
  36.     DDX_Control(pDX, IDC_ADF, ADF);
  37.     DDX_Control(pDX, IDC_ALT, ALT);
  38.     DDX_Control(pDX, IDC_CLIMB, CLIMB);
  39.     DDX_Control(pDX, IDC_HEADING, HEADING);
  40.     DDX_Control(pDX, IDC_HORIZON, HORIZON);
  41.     DDX_Control(pDX, IDC_HSI, HSI);
  42.     DDX_Control(pDX, IDC_OBI, OBI);
  43.     DDX_Control(pDX, IDC_RMI, RMI);
  44.     DDX_Control(pDX, IDC_SPEED, SPEED);
  45.     DDX_Control(pDX, IDC_TURN, TURN);
  46.     //}}AFX_DATA_MAP
  47. }
  48.  
  49. BEGIN_MESSAGE_MAP(CVCDemoDlg, CDialog)
  50.     //{{AFX_MSG_MAP(CVCDemoDlg)
  51.     ON_WM_PAINT()
  52.     ON_WM_QUERYDRAGICON()
  53.     ON_WM_TIMER()
  54.     ON_WM_LBUTTONDBLCLK()
  55.     ON_WM_MOUSEMOVE()
  56.     //}}AFX_MSG_MAP
  57. END_MESSAGE_MAP()
  58.  
  59. /////////////////////////////////////////////////////////////////////////////
  60. // CVCDemoDlg message handlers
  61.  
  62. BOOL CVCDemoDlg::OnInitDialog()
  63. {
  64.     CDialog::OnInitDialog();
  65.  
  66.     // Set the icon for this dialog.  The framework does this automatically
  67.     //  when the application's main window is not a dialog
  68.     SetIcon(m_hIcon, TRUE);            // Set big icon
  69.     SetIcon(m_hIcon, FALSE);        // Set small icon
  70.     
  71.     // TODO: Add extra initialization here
  72.     
  73.     return TRUE;  // return TRUE  unless you set the focus to a control
  74. }
  75.  
  76. // If you add a minimize button to your dialog, you will need the code below
  77. //  to draw the icon.  For MFC applications using the document/view model,
  78. //  this is automatically done for you by the framework.
  79.  
  80. void CVCDemoDlg::OnPaint() 
  81. {
  82.     if (IsIconic())
  83.     {
  84.         CPaintDC dc(this); // device context for painting
  85.  
  86.         SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
  87.  
  88.         // Center icon in client rectangle
  89.         int cxIcon = GetSystemMetrics(SM_CXICON);
  90.         int cyIcon = GetSystemMetrics(SM_CYICON);
  91.         CRect rect;
  92.         GetClientRect(&rect);
  93.         int x = (rect.Width() - cxIcon + 1) / 2;
  94.         int y = (rect.Height() - cyIcon + 1) / 2;
  95.  
  96.         // Draw the icon
  97.         dc.DrawIcon(x, y, m_hIcon);
  98.     }
  99.     else
  100.     {
  101.         CDialog::OnPaint();
  102.     }
  103.  
  104.  
  105.     if (!init) {
  106.         init = TRUE;
  107.  
  108.         //SetTimer(1000,50,NULL);
  109.         SetTimer(1001,200,NULL);
  110.         }
  111.  
  112. }
  113.  
  114. // The system calls this to obtain the cursor to display while the user drags
  115. //  the minimized window.
  116. HCURSOR CVCDemoDlg::OnQueryDragIcon()
  117. {
  118.     return (HCURSOR) m_hIcon;
  119. }
  120.  
  121. BOOL CVCDemoDlg::DestroyWindow() 
  122. {
  123.     //KillTimer(1000);
  124.     if (IsWindow(m_hWnd)) {
  125.         KillTimer(1001);
  126.         //KillTimer(1000);
  127.         }
  128.     
  129.     return CDialog::DestroyWindow();
  130. }
  131.  
  132. void CVCDemoDlg::OnTimer(UINT nIDEvent) 
  133. {
  134.     switch (nIDEvent) {
  135.         case 1001:
  136.             CLIMB.SetClimbRate(50.0f * SPEED.GetAirspeed() 
  137.                 * (float) sin((double) HORIZON.GetAHPitch() 
  138.                 * (float) cos((double) HORIZON.GetAHRoll() * 3.14159f / 180.0f) * 3.14159f / 180.0f));
  139.             ALT.SetAltitude(ALT.GetAltitude() + CLIMB.GetClimbRate() / 100.0f);
  140.             
  141.             SPEED.SetAirspeed(SPEED.GetAirspeed() - CLIMB.GetClimbRate() / 2000.0f);
  142.             if (SPEED.GetAirspeed() > 120.0f) SPEED.SetAirspeed(120.0f);
  143.             if (SPEED.GetAirspeed() < 60.0f) SPEED.SetAirspeed(60.0f);
  144.             
  145.             HEADING.SetHeadingIndicator(HEADING.GetHeadingIndicator() + SPEED.GetAirspeed() * (float) sin((double) HORIZON.GetAHRoll() * 3.14159f / 180.0f) / 20.0f);
  146.             OBI.SetOBICourse(HEADING.GetHeadingIndicator());
  147.             ADF.SetADFBearing(HEADING.GetHeadingIndicator() + 30.0f);
  148.             RMI.SetRMIBearing1(HEADING.GetHeadingIndicator() + 45.0f);
  149.             HORIZON.SetAHHeading(HEADING.GetHeadingIndicator());
  150.             HSI.SetHSIHeading(HEADING.GetHeadingIndicator());
  151.             
  152.             TURN.SetTCTurn(SPEED.GetAirspeed() * (float) sin((double) HORIZON.GetAHRoll() * 3.14159f / 180.0f) * (float) sin((double) HORIZON.GetAHPitch() * 3.14159f / 180.0f));
  153.             
  154.             //In this cockpit demo, all instruments have the AutoRedraw property
  155.             //set to false for improved refresh rates.  This requires that
  156.             //you force the instruments to redraw after all the instruments'
  157.             //properties have been updated.  Setting the Redraw property to
  158.             //True forces the instruments to be refreshed immediately.
  159.             
  160.             HEADING.Redraw();
  161.             SPEED.Redraw();
  162.             CLIMB.Redraw();
  163.             ALT.Redraw();
  164.             HSI.Redraw();
  165.             OBI.Redraw();
  166.             RMI.Redraw();
  167.             ADF.Redraw();
  168.             TURN.Redraw();
  169.             HORIZON.Redraw();
  170.             
  171.             break;
  172.         }
  173.     
  174.     CDialog::OnTimer(nIDEvent);
  175. }
  176.  
  177. BEGIN_EVENTSINK_MAP(CVCDemoDlg, CDialog)
  178.     //{{AFX_EVENTSINK_MAP(CVCDemoDlg)
  179.     ON_EVENT(CVCDemoDlg, IDC_HORIZON, -605 /* MouseDown */, OnMouseDownHorizon, VTS_I2 VTS_I2 VTS_I4 VTS_I4)
  180.     ON_EVENT(CVCDemoDlg, IDC_HORIZON, -606 /* MouseMove */, OnMouseMoveHorizon, VTS_I2 VTS_I2 VTS_I4 VTS_I4)
  181.     ON_EVENT(CVCDemoDlg, IDC_HORIZON, -607 /* MouseUp */, OnMouseUpHorizon, VTS_I2 VTS_I2 VTS_I4 VTS_I4)
  182.     ON_EVENT(CVCDemoDlg, IDC_ADF, -601 /* DblClick */, OnDblClickAdf, VTS_NONE)
  183.     ON_EVENT(CVCDemoDlg, IDC_ALT, -601 /* DblClick */, OnDblClickAlt, VTS_NONE)
  184.     ON_EVENT(CVCDemoDlg, IDC_CLIMB, -601 /* DblClick */, OnDblClickClimb, VTS_NONE)
  185.     ON_EVENT(CVCDemoDlg, IDC_HEADING, -601 /* DblClick */, OnDblClickHeading, VTS_NONE)
  186.     ON_EVENT(CVCDemoDlg, IDC_HORIZON, -601 /* DblClick */, OnDblClickHorizon, VTS_NONE)
  187.     ON_EVENT(CVCDemoDlg, IDC_HSI, -601 /* DblClick */, OnDblClickHsi, VTS_NONE)
  188.     ON_EVENT(CVCDemoDlg, IDC_OBI, -601 /* DblClick */, OnDblClickObi, VTS_NONE)
  189.     ON_EVENT(CVCDemoDlg, IDC_RMI, -601 /* DblClick */, OnDblClickRmi, VTS_NONE)
  190.     //}}AFX_EVENTSINK_MAP
  191. END_EVENTSINK_MAP()
  192.  
  193. void CVCDemoDlg::OnMouseDownHorizon(short Button, short Shift, long x, long y) 
  194. {
  195.     mousedown = TRUE;
  196.     mousex = x;
  197.     mousey = y;
  198.     pitch = HORIZON.GetAHPitch();
  199.     roll = HORIZON.GetAHRoll();
  200. }
  201.  
  202. void CVCDemoDlg::OnMouseMoveHorizon(short Button, short Shift, long x, long y) 
  203. {
  204.     if (mousedown) {
  205.         if (mousex!=x || mousey!=y) {
  206.             HORIZON.SetAHPitch(pitch + (y - mousey)/5.0f);
  207.             HORIZON.SetAHRoll(roll + (x - mousex)/5.0f);
  208.             HORIZON.Redraw();
  209.             }
  210.         }
  211. }
  212.  
  213. void CVCDemoDlg::OnMouseUpHorizon(short Button, short Shift, long x, long y) 
  214. {
  215.     mousedown = FALSE;
  216. }
  217.  
  218. void CVCDemoDlg::OnDblClickAdf() 
  219. {
  220.     ADF.ShowPropertyPage();        
  221. }
  222.  
  223. void CVCDemoDlg::OnDblClickAlt() 
  224. {
  225.     ALT.ShowPropertyPage();    
  226. }
  227.  
  228. void CVCDemoDlg::OnDblClickClimb() 
  229. {
  230.     CLIMB.ShowPropertyPage();    
  231. }
  232.  
  233. void CVCDemoDlg::OnDblClickHeading() 
  234. {
  235.     HEADING.ShowPropertyPage();    
  236. }
  237.  
  238. void CVCDemoDlg::OnDblClickHorizon() 
  239. {
  240.     HORIZON.ShowPropertyPage();        
  241. }
  242.  
  243. void CVCDemoDlg::OnDblClickHsi() 
  244. {
  245.     HSI.ShowPropertyPage();
  246. }
  247.  
  248. void CVCDemoDlg::OnDblClickObi() 
  249. {
  250.     OBI.ShowPropertyPage();        
  251. }
  252.  
  253. void CVCDemoDlg::OnDblClickRmi() 
  254. {
  255.     RMI.ShowPropertyPage();    
  256. }
  257.