ResourceStringSelectionDlg.cpp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. //===========================================================================//
  2. // Copyright (C) Microsoft Corporation. All rights reserved. //
  3. //===========================================================================//
  4. // ResourceStringSelectionDlg.cpp : implementation file
  5. //
  6. #include "stdafx.h"
  7. #include "resource.h"
  8. #include "ResourceStringSelectionDlg.h"
  9. #include "assert.h"
  10. #include "../MCLib/Utilities.h" /*for cLoadString*/
  11. #ifdef _DEBUG
  12. #define new DEBUG_NEW
  13. #undef THIS_FILE
  14. static char THIS_FILE[] = __FILE__;
  15. #endif
  16. /////////////////////////////////////////////////////////////////////////////
  17. // ResourceStringSelectionDlg dialog
  18. ResourceStringSelectionDlg::ResourceStringSelectionDlg(CWnd* pParent /*=NULL*/)
  19. : CDialog(ResourceStringSelectionDlg::IDD, pParent)
  20. {
  21. m_BottomOfIDRange = 0;
  22. m_TopOfIDRange = 65535;
  23. m_SelectedResourceStringID = -1;
  24. //{{AFX_DATA_INIT(ResourceStringSelectionDlg)
  25. // NOTE: the ClassWizard will add member initialization here
  26. //}}AFX_DATA_INIT
  27. }
  28. void ResourceStringSelectionDlg::DoDataExchange(CDataExchange* pDX)
  29. {
  30. CDialog::DoDataExchange(pDX);
  31. //{{AFX_DATA_MAP(ResourceStringSelectionDlg)
  32. DDX_Control(pDX, IDC_RESOURCE_STRING_SELECTION_COMBO, m_Combo);
  33. //}}AFX_DATA_MAP
  34. }
  35. BEGIN_MESSAGE_MAP(ResourceStringSelectionDlg, CDialog)
  36. //{{AFX_MSG_MAP(ResourceStringSelectionDlg)
  37. //}}AFX_MSG_MAP
  38. END_MESSAGE_MAP()
  39. /////////////////////////////////////////////////////////////////////////////
  40. // ResourceStringSelectionDlg message handlers
  41. static BOOL CSLoadString(int resourceID, CString &targetStr) {
  42. char szTmp[16384/*max string length*/];
  43. cLoadString( resourceID, szTmp, 16384/*max string length*/ );
  44. targetStr = szTmp;
  45. CString tmpStr;
  46. tmpStr.Format("mc2res.dll:%d Not defined", resourceID);
  47. if (0 == strcmp(tmpStr.GetBuffer(0), szTmp)) {
  48. return (0);
  49. }
  50. return (!0);
  51. }
  52. BOOL ResourceStringSelectionDlg::OnInitDialog()
  53. {
  54. CDialog::OnInitDialog();
  55. m_ResourceStringIDs.Clear();
  56. m_Combo.ResetContent();
  57. unsigned long i;
  58. for (i = m_BottomOfIDRange; i <= (unsigned long)m_TopOfIDRange; i += 1) {
  59. CString tmpStr;
  60. //BOOL result = tmpStr.LoadString(i);
  61. BOOL result = CSLoadString(i, tmpStr);
  62. if (0 != result) {
  63. CString tmpStr2;
  64. tmpStr2.Format("%d: ", i);
  65. tmpStr2 += tmpStr;
  66. m_Combo.AddString(tmpStr2);
  67. m_ResourceStringIDs.Append(i);
  68. }
  69. }
  70. for (i = 0; i < m_ResourceStringIDs.Count(); i += 1) {
  71. if (m_SelectedResourceStringID == m_ResourceStringIDs[i]) {
  72. m_Combo.SetCurSel(i);
  73. break;
  74. }
  75. }
  76. if (m_ResourceStringIDs.Count() == i) {
  77. m_SelectedResourceStringID = -1;
  78. m_Combo.SetCurSel(-1);
  79. }
  80. return TRUE; // return TRUE unless you set the focus to a control
  81. // EXCEPTION: OCX Property Pages should return FALSE
  82. }
  83. void ResourceStringSelectionDlg::OnOK()
  84. {
  85. unsigned long selectionIndex = m_Combo.GetCurSel();
  86. if (CB_ERR != selectionIndex) {
  87. assert(m_ResourceStringIDs.Count() > selectionIndex);
  88. m_SelectedResourceStringID = m_ResourceStringIDs[selectionIndex];
  89. }
  90. CDialog::OnOK();
  91. }