home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 July / CMCD0704.ISO / Software / Freeware / Utilitare / VisualBoyAdvance-1.7.2 / src / win32 / Associate.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2004-05-13  |  3.1 KB  |  129 lines

  1. // VisualBoyAdvance - Nintendo Gameboy/GameboyAdvance (TM) emulator.
  2. // Copyright (C) 1999-2003 Forgotten
  3. // Copyright (C) 2004 Forgotten and the VBA development team
  4.  
  5. // This program is free software; you can redistribute it and/or modify
  6. // it under the terms of the GNU General Public License as published by
  7. // the Free Software Foundation; either version 2, or(at your option)
  8. // any later version.
  9. //
  10. // This program is distributed in the hope that it will be useful,
  11. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. // GNU General Public License for more details.
  14. //
  15. // You should have received a copy of the GNU General Public License
  16. // along with this program; if not, write to the Free Software Foundation,
  17. // Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  18.  
  19. // Associate.cpp : implementation file
  20. //
  21.  
  22. #include "stdafx.h"
  23. #include "vba.h"
  24. #include "Associate.h"
  25. #include "Reg.h"
  26.  
  27. #ifdef _DEBUG
  28. #define new DEBUG_NEW
  29. #undef THIS_FILE
  30. static char THIS_FILE[] = __FILE__;
  31. #endif
  32.  
  33. /////////////////////////////////////////////////////////////////////////////
  34. // Associate dialog
  35.  
  36.  
  37. Associate::Associate(CWnd* pParent /*=NULL*/)
  38.   : CDialog(Associate::IDD, pParent)
  39. {
  40.   //{{AFX_DATA_INIT(Associate)
  41.   m_agb = FALSE;
  42.   m_bin = FALSE;
  43.   m_cgb = FALSE;
  44.   m_gb = FALSE;
  45.   m_gba = FALSE;
  46.   m_gbc = FALSE;
  47.   m_sgb = FALSE;
  48.   //}}AFX_DATA_INIT
  49. }
  50.  
  51.  
  52. void Associate::DoDataExchange(CDataExchange* pDX)
  53. {
  54.   CDialog::DoDataExchange(pDX);
  55.   //{{AFX_DATA_MAP(Associate)
  56.   DDX_Check(pDX, IDC_AGB, m_agb);
  57.   DDX_Check(pDX, IDC_BIN, m_bin);
  58.   DDX_Check(pDX, IDC_CGB, m_cgb);
  59.   DDX_Check(pDX, IDC_GB, m_gb);
  60.   DDX_Check(pDX, IDC_GBA, m_gba);
  61.   DDX_Check(pDX, IDC_GBC, m_gbc);
  62.   DDX_Check(pDX, IDC_SGB, m_sgb);
  63.   //}}AFX_DATA_MAP
  64. }
  65.  
  66.  
  67. BEGIN_MESSAGE_MAP(Associate, CDialog)
  68.   //{{AFX_MSG_MAP(Associate)
  69.   ON_BN_CLICKED(ID_CANCEL, OnCancel)
  70.   ON_BN_CLICKED(ID_OK, OnOk)
  71.   //}}AFX_MSG_MAP
  72.   END_MESSAGE_MAP()
  73.  
  74.   /////////////////////////////////////////////////////////////////////////////
  75. // Associate message handlers
  76.  
  77. BOOL Associate::OnInitDialog() 
  78. {
  79.   CDialog::OnInitDialog();
  80.   
  81.   CenterWindow();
  82.   
  83.   return TRUE;  // return TRUE unless you set the focus to a control
  84.                 // EXCEPTION: OCX Property Pages should return FALSE
  85. }
  86.  
  87. void Associate::OnCancel() 
  88. {
  89.   EndDialog(FALSE);
  90. }
  91.  
  92. void Associate::OnOk() 
  93. {
  94.   UpdateData();
  95.  
  96.   int mask = 0;
  97.   if(m_gb)
  98.     mask |= 1;
  99.   if(m_sgb)
  100.     mask |= 2;
  101.   if(m_cgb)
  102.     mask |= 4;
  103.   if(m_gbc)
  104.     mask |= 8;
  105.   if(m_gba)
  106.     mask |= 16;
  107.   if(m_agb)
  108.     mask |= 32;
  109.   if(m_bin)
  110.     mask |= 64;
  111.   if(mask) {
  112.     char applicationPath[2048];
  113.     CString commandPath;
  114.     LPCTSTR types[] = { ".gb", ".sgb", ".cgb", ".gbc", ".gba", ".agb", ".bin" };
  115.     GetModuleFileName(NULL, applicationPath, 2048);
  116.     commandPath.Format("\"%s\" \"%%1\"", applicationPath);
  117.     regAssociateType("VisualBoyAdvance.Binary",
  118.                      "Binary",
  119.                      commandPath);
  120.   
  121.     for(int i = 0; i < 7; i++) {
  122.       if(mask & (1<<i)) {
  123.         regCreateFileType(types[i],"VisualBoyAdvance.Binary");
  124.       }
  125.     }
  126.   }
  127.   EndDialog(TRUE);
  128. }
  129.