1 #include "stdafx.h"
2 #include "vba.h"
3 #include "Associate.h"
4 #include "Reg.h"
5
6 #ifdef _DEBUG
7 #define new DEBUG_NEW
8 #undef THIS_FILE
9 static char THIS_FILE[] = __FILE__;
10 #endif
11
12 /////////////////////////////////////////////////////////////////////////////
13 // Associate dialog
14
15
Associate(CWnd * pParent)16 Associate::Associate(CWnd* pParent /*=NULL*/)
17 : CDialog(Associate::IDD, pParent)
18 {
19 //{{AFX_DATA_INIT(Associate)
20 m_agb = FALSE;
21 m_bin = FALSE;
22 m_cgb = FALSE;
23 m_dmg = FALSE;
24 m_gb = FALSE;
25 m_gba = FALSE;
26 m_gbc = FALSE;
27 m_sgb = FALSE;
28 //}}AFX_DATA_INIT
29 }
30
31
DoDataExchange(CDataExchange * pDX)32 void Associate::DoDataExchange(CDataExchange* pDX)
33 {
34 CDialog::DoDataExchange(pDX);
35 //{{AFX_DATA_MAP(Associate)
36 DDX_Check(pDX, IDC_AGB, m_agb);
37 DDX_Check(pDX, IDC_BIN, m_bin);
38 DDX_Check(pDX, IDC_CGB, m_cgb);
39 DDX_Check(pDX, IDC_DMG, m_dmg);
40 DDX_Check(pDX, IDC_GB, m_gb);
41 DDX_Check(pDX, IDC_GBA, m_gba);
42 DDX_Check(pDX, IDC_GBC, m_gbc);
43 DDX_Check(pDX, IDC_SGB, m_sgb);
44 //}}AFX_DATA_MAP
45 }
46
47
BEGIN_MESSAGE_MAP(Associate,CDialog)48 BEGIN_MESSAGE_MAP(Associate, CDialog)
49 //{{AFX_MSG_MAP(Associate)
50 ON_BN_CLICKED(ID_CANCEL, OnCancel)
51 ON_BN_CLICKED(ID_OK, OnOk)
52 //}}AFX_MSG_MAP
53 END_MESSAGE_MAP()
54
55 /////////////////////////////////////////////////////////////////////////////
56 // Associate message handlers
57
58 BOOL Associate::OnInitDialog()
59 {
60 CDialog::OnInitDialog();
61
62 CenterWindow();
63
64 return TRUE; // return TRUE unless you set the focus to a control
65 // EXCEPTION: OCX Property Pages should return FALSE
66 }
67
OnCancel()68 void Associate::OnCancel()
69 {
70 EndDialog(FALSE);
71 }
72
OnOk()73 void Associate::OnOk()
74 {
75 UpdateData();
76
77 int mask = 0;
78 if(m_gb)
79 mask |= 1;
80 if(m_dmg)
81 mask |= 2;
82 if(m_sgb)
83 mask |= 4;
84 if(m_cgb)
85 mask |= 8;
86 if(m_gbc)
87 mask |= 16;
88 if(m_gba)
89 mask |= 32;
90 if(m_agb)
91 mask |= 64;
92 if(m_bin)
93 mask |= 128;
94 if(mask) {
95 char applicationPath[2048];
96 CString commandPath;
97 LPCTSTR types[] = { "*.dmg", ".gb", ".sgb", ".cgb", ".gbc", ".gba", ".agb", ".bin" };
98 GetModuleFileName(NULL, applicationPath, 2048);
99 commandPath.Format("\"%s\" \"%%1\"", applicationPath);
100 regAssociateType("VisualBoyAdvance.Binary",
101 "Binary",
102 commandPath,
103 "%SystemRoot%\\system32\\SHELL32.dll,-13");
104
105 for(int i = 0; i < 8; i++) {
106 if(mask & (1<<i)) {
107 regCreateFileType(types[i],"VisualBoyAdvance.Binary");
108 }
109 }
110 }
111 EndDialog(TRUE);
112 }
113