home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 July / CMCD0704.ISO / Software / Freeware / Utilitare / VisualBoyAdvance-1.7.2 / src / win32 / GSACodeSelect.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2004-05-13  |  3.0 KB  |  121 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. // GSACodeSelect.cpp : implementation file
  20. //
  21.  
  22. #include "stdafx.h"
  23. #include "vba.h"
  24. #include "GSACodeSelect.h"
  25.  
  26. #ifdef _DEBUG
  27. #define new DEBUG_NEW
  28. #undef THIS_FILE
  29. static char THIS_FILE[] = __FILE__;
  30. #endif
  31.  
  32. /////////////////////////////////////////////////////////////////////////////
  33. // GSACodeSelect dialog
  34.  
  35.  
  36. GSACodeSelect::GSACodeSelect(FILE *file, CWnd* pParent /*=NULL*/)
  37.   : CDialog(GSACodeSelect::IDD, pParent)
  38. {
  39.   //{{AFX_DATA_INIT(GSACodeSelect)
  40.   // NOTE: the ClassWizard will add member initialization here
  41.   //}}AFX_DATA_INIT
  42.   m_file = file;
  43. }
  44.  
  45.  
  46. void GSACodeSelect::DoDataExchange(CDataExchange* pDX)
  47. {
  48.   CDialog::DoDataExchange(pDX);
  49.   //{{AFX_DATA_MAP(GSACodeSelect)
  50.   DDX_Control(pDX, IDC_GAME_LIST, m_games);
  51.   //}}AFX_DATA_MAP
  52. }
  53.  
  54.  
  55. BEGIN_MESSAGE_MAP(GSACodeSelect, CDialog)
  56.   //{{AFX_MSG_MAP(GSACodeSelect)
  57.   ON_BN_CLICKED(ID_OK, OnOk)
  58.   ON_LBN_SELCHANGE(IDC_GAME_LIST, OnSelchangeGameList)
  59.   ON_BN_CLICKED(ID_CANCEL, OnCancel)
  60.   //}}AFX_MSG_MAP
  61.   END_MESSAGE_MAP()
  62.  
  63.   /////////////////////////////////////////////////////////////////////////////
  64. // GSACodeSelect message handlers
  65.  
  66. void GSACodeSelect::OnCancel() 
  67. {
  68.   EndDialog(-1);
  69. }
  70.  
  71. void GSACodeSelect::OnOk() 
  72. {
  73.   EndDialog(m_games.GetCurSel());
  74. }
  75.  
  76. void GSACodeSelect::OnSelchangeGameList() 
  77. {
  78.   int item = m_games.GetCurSel();
  79.   CWnd *ok = GetDlgItem(ID_OK);
  80.  
  81.   ok->EnableWindow(item != -1);
  82. }
  83.  
  84. BOOL GSACodeSelect::OnInitDialog() 
  85. {
  86.   CDialog::OnInitDialog();
  87.   
  88.   char buffer[1024];
  89.   
  90.   FILE *f = m_file;
  91.   int games = 0;
  92.   int len = 0;
  93.   fseek(f, -4, SEEK_CUR);
  94.   fread(&games, 1, 4, f);
  95.   while(games > 0) {
  96.     fread(&len, 1, 4, f);
  97.     fread(buffer, 1, len, f);
  98.     buffer[len] = 0;
  99.     m_games.AddString(buffer);
  100.     int codes = 0;
  101.     fread(&codes, 1, 4, f);
  102.     
  103.     while(codes > 0) {
  104.       fread(&len, 1, 4, f);
  105.       fseek(f, len, SEEK_CUR);
  106.       fread(&len, 1, 4, f);
  107.       fseek(f, len, SEEK_CUR);
  108.       fseek(f, 4, SEEK_CUR);
  109.       fread(&len, 1, 4, f);
  110.       fseek(f, len*12, SEEK_CUR);
  111.       codes--;
  112.     }
  113.     games--;
  114.   }
  115.   GetDlgItem(ID_OK)->EnableWindow(FALSE);
  116.   CenterWindow();
  117.   
  118.   return TRUE;  // return TRUE unless you set the focus to a control
  119.                 // EXCEPTION: OCX Property Pages should return FALSE
  120. }
  121.