comparison src/win32/GSACodeSelect.cpp @ 1:f9f4f1b99eed

importing src directory
author Robert McIntyre <rlm@mit.edu>
date Sat, 03 Mar 2012 10:31:27 -0600
parents
children
comparison
equal deleted inserted replaced
0:8ced16adf2e1 1:f9f4f1b99eed
1 // GSACodeSelect.cpp : implementation file
2 //
3
4 #include "stdafx.h"
5 #include "resource.h"
6 #include "GSACodeSelect.h"
7
8 /////////////////////////////////////////////////////////////////////////////
9 // GSACodeSelect dialog
10
11 GSACodeSelect::GSACodeSelect(FILE *file, CWnd*pParent /*=NULL*/)
12 : CDialog(GSACodeSelect::IDD, pParent)
13 {
14 //{{AFX_DATA_INIT(GSACodeSelect)
15 // NOTE: the ClassWizard will add member initialization here
16 //}}AFX_DATA_INIT
17 m_file = file;
18 }
19
20 void GSACodeSelect::DoDataExchange(CDataExchange*pDX)
21 {
22 CDialog::DoDataExchange(pDX);
23 //{{AFX_DATA_MAP(GSACodeSelect)
24 DDX_Control(pDX, IDC_GAME_LIST, m_games);
25 //}}AFX_DATA_MAP
26 }
27
28 BEGIN_MESSAGE_MAP(GSACodeSelect, CDialog)
29 //{{AFX_MSG_MAP(GSACodeSelect)
30 ON_BN_CLICKED(ID_OK, OnOk)
31 ON_LBN_SELCHANGE(IDC_GAME_LIST, OnSelchangeGameList)
32 ON_BN_CLICKED(ID_CANCEL, OnCancel)
33 //}}AFX_MSG_MAP
34 END_MESSAGE_MAP()
35
36 /////////////////////////////////////////////////////////////////////////////
37 // GSACodeSelect message handlers
38
39 void GSACodeSelect::OnCancel()
40 {
41 EndDialog(-1);
42 }
43
44 void GSACodeSelect::OnOk()
45 {
46 EndDialog(m_games.GetCurSel());
47 }
48
49 void GSACodeSelect::OnSelchangeGameList()
50 {
51 int item = m_games.GetCurSel();
52 CWnd *ok = GetDlgItem(ID_OK);
53
54 ok->EnableWindow(item != -1);
55 }
56
57 BOOL GSACodeSelect::OnInitDialog()
58 {
59 CDialog::OnInitDialog();
60
61 char buffer[1024];
62
63 FILE *f = m_file;
64 int games = 0;
65 int len = 0;
66 fseek(f, -4, SEEK_CUR);
67 fread(&games, 1, 4, f);
68 while (games > 0)
69 {
70 fread(&len, 1, 4, f);
71 fread(buffer, 1, len, f);
72 buffer[len] = 0;
73 m_games.AddString(buffer);
74 int codes = 0;
75 fread(&codes, 1, 4, f);
76
77 while (codes > 0)
78 {
79 fread(&len, 1, 4, f);
80 fseek(f, len, SEEK_CUR);
81 fread(&len, 1, 4, f);
82 fseek(f, len, SEEK_CUR);
83 fseek(f, 4, SEEK_CUR);
84 fread(&len, 1, 4, f);
85 fseek(f, len*12, SEEK_CUR);
86 codes--;
87 }
88 games--;
89 }
90 GetDlgItem(ID_OK)->EnableWindow(FALSE);
91 CenterWindow();
92
93 return TRUE; // return TRUE unless you set the focus to a control
94 // EXCEPTION: OCX Property Pages should return FALSE
95 }
96