home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Controls / Visual Basic Controls.iso / vbcontrol / aals / aals.exe / DISK1 / _SETUP.1 / VC4JoyDlg.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1997-04-03  |  4.8 KB  |  203 lines

  1. // VC4JoyDlg.cpp : implementation file
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "VC4Joy.h"
  6. #include "VC4JoyDlg.h"
  7.  
  8. #ifdef _DEBUG
  9. #define new DEBUG_NEW
  10. #undef THIS_FILE
  11. static char THIS_FILE[] = __FILE__;
  12. #endif
  13.  
  14. /////////////////////////////////////////////////////////////////////////////
  15. // CAboutDlg dialog used for App About
  16.  
  17. class CAboutDlg : public CDialog
  18. {
  19. public:
  20.     CAboutDlg();
  21.  
  22. // Dialog Data
  23.     //{{AFX_DATA(CAboutDlg)
  24.     enum { IDD = IDD_ABOUTBOX };
  25.     //}}AFX_DATA
  26.  
  27.     // ClassWizard generated virtual function overrides
  28.     //{{AFX_VIRTUAL(CAboutDlg)
  29.     protected:
  30.     virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
  31.     //}}AFX_VIRTUAL
  32.  
  33. // Implementation
  34. protected:
  35.     //{{AFX_MSG(CAboutDlg)
  36.     //}}AFX_MSG
  37.     DECLARE_MESSAGE_MAP()
  38. };
  39.  
  40. CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
  41. {
  42.     //{{AFX_DATA_INIT(CAboutDlg)
  43.     //}}AFX_DATA_INIT
  44. }
  45.  
  46. void CAboutDlg::DoDataExchange(CDataExchange* pDX)
  47. {
  48.     CDialog::DoDataExchange(pDX);
  49.     //{{AFX_DATA_MAP(CAboutDlg)
  50.     //}}AFX_DATA_MAP
  51. }
  52.  
  53. BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
  54.     //{{AFX_MSG_MAP(CAboutDlg)
  55.         // No message handlers
  56.     //}}AFX_MSG_MAP
  57. END_MESSAGE_MAP()
  58.  
  59. /////////////////////////////////////////////////////////////////////////////
  60. // CVC4JoyDlg dialog
  61.  
  62. CVC4JoyDlg::CVC4JoyDlg(CWnd* pParent /*=NULL*/)
  63.     : CDialog(CVC4JoyDlg::IDD, pParent)
  64. {
  65.     //{{AFX_DATA_INIT(CVC4JoyDlg)
  66.     //}}AFX_DATA_INIT
  67.     // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
  68.     m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
  69. }
  70.  
  71. void CVC4JoyDlg::DoDataExchange(CDataExchange* pDX)
  72. {
  73.     CDialog::DoDataExchange(pDX);
  74.     //{{AFX_DATA_MAP(CVC4JoyDlg)
  75.     DDX_Control(pDX, IDC_BUTTON1, m_button1);
  76.     DDX_Control(pDX, IDC_EDIT4, m_edit4);
  77.     DDX_Control(pDX, IDC_EDIT3, m_edit3);
  78.     DDX_Control(pDX, IDC_EDIT2, m_edit2);
  79.     DDX_Control(pDX, IDC_EDIT1, m_edit1);
  80.     DDX_Control(pDX, IDC_JOYSTICKCTRL1, m_joy);
  81.     //}}AFX_DATA_MAP
  82. }
  83.  
  84. BEGIN_MESSAGE_MAP(CVC4JoyDlg, CDialog)
  85.     //{{AFX_MSG_MAP(CVC4JoyDlg)
  86.     ON_WM_SYSCOMMAND()
  87.     ON_WM_PAINT()
  88.     ON_WM_QUERYDRAGICON()
  89.     ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
  90.     //}}AFX_MSG_MAP
  91. END_MESSAGE_MAP()
  92.  
  93. /////////////////////////////////////////////////////////////////////////////
  94. // CVC4JoyDlg message handlers
  95.  
  96. BOOL CVC4JoyDlg::OnInitDialog()
  97. {
  98.     CDialog::OnInitDialog();
  99.  
  100.     // Add "About..." menu item to system menu.
  101.  
  102.     // IDM_ABOUTBOX must be in the system command range.
  103.     ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
  104.     ASSERT(IDM_ABOUTBOX < 0xF000);
  105.  
  106.     CMenu* pSysMenu = GetSystemMenu(FALSE);
  107.     CString strAboutMenu;
  108.     strAboutMenu.LoadString(IDS_ABOUTBOX);
  109.     if (!strAboutMenu.IsEmpty())
  110.     {
  111.         pSysMenu->AppendMenu(MF_SEPARATOR);
  112.         pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
  113.     }
  114.  
  115.     // Set the icon for this dialog.  The framework does this automatically
  116.     //  when the application's main window is not a dialog
  117.     SetIcon(m_hIcon, TRUE);            // Set big icon
  118.     SetIcon(m_hIcon, FALSE);        // Set small icon
  119.     
  120.     // TODO: Add extra initialization here
  121.     
  122.     return TRUE;  // return TRUE  unless you set the focus to a control
  123. }
  124.  
  125. void CVC4JoyDlg::OnSysCommand(UINT nID, LPARAM lParam)
  126. {
  127.     if ((nID & 0xFFF0) == IDM_ABOUTBOX)
  128.     {
  129.         CAboutDlg dlgAbout;
  130.         dlgAbout.DoModal();
  131.     }
  132.     else
  133.     {
  134.         CDialog::OnSysCommand(nID, lParam);
  135.     }
  136. }
  137.  
  138. // If you add a minimize button to your dialog, you will need the code below
  139. //  to draw the icon.  For MFC applications using the document/view model,
  140. //  this is automatically done for you by the framework.
  141.  
  142. void CVC4JoyDlg::OnPaint() 
  143. {
  144.     if (IsIconic())
  145.     {
  146.         CPaintDC dc(this); // device context for painting
  147.  
  148.         SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
  149.  
  150.         // Center icon in client rectangle
  151.         int cxIcon = GetSystemMetrics(SM_CXICON);
  152.         int cyIcon = GetSystemMetrics(SM_CYICON);
  153.         CRect rect;
  154.         GetClientRect(&rect);
  155.         int x = (rect.Width() - cxIcon + 1) / 2;
  156.         int y = (rect.Height() - cyIcon + 1) / 2;
  157.  
  158.         // Draw the icon
  159.         dc.DrawIcon(x, y, m_hIcon);
  160.     }
  161.     else
  162.     {
  163.         CDialog::OnPaint();
  164.     }
  165. }
  166.  
  167. // The system calls this to obtain the cursor to display while the user drags
  168. //  the minimized window.
  169. HCURSOR CVC4JoyDlg::OnQueryDragIcon()
  170. {
  171.     return (HCURSOR) m_hIcon;
  172. }
  173.  
  174. BEGIN_EVENTSINK_MAP(CVC4JoyDlg, CDialog)
  175.     //{{AFX_EVENTSINK_MAP(CVC4JoyDlg)
  176.     ON_EVENT(CVC4JoyDlg, IDC_JOYSTICKCTRL1, 3 /* JoyMove */, OnJoyMoveJoystickctrl1, VTS_NONE)
  177.     //}}AFX_EVENTSINK_MAP
  178. END_EVENTSINK_MAP()
  179.  
  180. void CVC4JoyDlg::OnJoyMoveJoystickctrl1() 
  181. {
  182. CString str;
  183.  
  184.     str.Format("%g",m_joy.GetXPos());
  185.     m_edit1.SetWindowText(str);
  186.  
  187.     str.Format("%g",m_joy.GetYPos());
  188.     m_edit2.SetWindowText(str);
  189.  
  190.     str.Format("%g",m_joy.GetZPos());
  191.     m_edit3.SetWindowText(str);
  192.  
  193.     str.Format("%g",m_joy.GetRPos());
  194.     m_edit4.SetWindowText(str);
  195.     
  196. }
  197.  
  198. void CVC4JoyDlg::OnButton1() 
  199. {
  200.     m_joy.ShowPropertyPage();
  201.     
  202. }
  203.