Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

175 lines
5.7 KiB

  1. // Wiaeditpropflags.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "wiatest.h"
  5. #include "Wiaeditpropflags.h"
  6. #ifdef _DEBUG
  7. #define new DEBUG_NEW
  8. #undef THIS_FILE
  9. static char THIS_FILE[] = __FILE__;
  10. #endif
  11. /////////////////////////////////////////////////////////////////////////////
  12. // CWiaeditpropflags dialog
  13. CWiaeditpropflags::CWiaeditpropflags(CWnd* pParent /*=NULL*/)
  14. : CDialog(CWiaeditpropflags::IDD, pParent)
  15. {
  16. //{{AFX_DATA_INIT(CWiaeditpropflags)
  17. m_szPropertyName = _T("");
  18. m_szPropertyValue = _T("");
  19. m_lValidValues = 0;
  20. m_lCurrentValue = 0;
  21. //}}AFX_DATA_INIT
  22. }
  23. void CWiaeditpropflags::DoDataExchange(CDataExchange* pDX)
  24. {
  25. CDialog::DoDataExchange(pDX);
  26. //{{AFX_DATA_MAP(CWiaeditpropflags)
  27. DDX_Control(pDX, IDC_FLAGS_PROPERTYVALUE_LISTBOX, m_PropertyValidValuesListBox);
  28. DDX_Text(pDX, IDC_FLAGS_PROPERTY_NAME, m_szPropertyName);
  29. DDX_Text(pDX, IDC_FLAGS_PROPERTYVALUE_EDITBOX, m_szPropertyValue);
  30. //}}AFX_DATA_MAP
  31. }
  32. BEGIN_MESSAGE_MAP(CWiaeditpropflags, CDialog)
  33. //{{AFX_MSG_MAP(CWiaeditpropflags)
  34. ON_LBN_SELCHANGE(IDC_FLAGS_PROPERTYVALUE_LISTBOX, OnSelchangeFlagsPropertyvalueListbox)
  35. //}}AFX_MSG_MAP
  36. END_MESSAGE_MAP()
  37. /////////////////////////////////////////////////////////////////////////////
  38. // CWiaeditpropflags message handlers
  39. void CWiaeditpropflags::SetPropertyName(TCHAR *szPropertyName)
  40. {
  41. m_szPropertyName = szPropertyName;
  42. }
  43. void CWiaeditpropflags::SetPropertyValue(TCHAR *szPropertyValue)
  44. {
  45. m_szPropertyValue = szPropertyValue;
  46. TSSCANF(szPropertyValue,TEXT("%d"),&m_lCurrentValue);
  47. m_szPropertyValue.Format("0x%08X",m_lCurrentValue);
  48. }
  49. void CWiaeditpropflags::SetPropertyValidValues(LONG lPropertyValidValues)
  50. {
  51. m_lValidValues = lPropertyValidValues;
  52. }
  53. void CWiaeditpropflags::OnSelchangeFlagsPropertyvalueListbox()
  54. {
  55. m_lCurrentValue = 0;
  56. TCHAR szListBoxValue[MAX_PATH];
  57. LONG lListBoxValue = 0;
  58. int indexArray[100];
  59. memset(indexArray,0,sizeof(indexArray));
  60. int iNumItemsSelected = m_PropertyValidValuesListBox.GetSelItems(100,indexArray);
  61. for(int i = 0; i < iNumItemsSelected; i++){
  62. memset(szListBoxValue,0,sizeof(szListBoxValue));
  63. m_PropertyValidValuesListBox.GetText(indexArray[i],szListBoxValue);
  64. if(TSTR2WIACONSTANT(m_szPropertyName.GetBuffer(m_szPropertyName.GetLength()),szListBoxValue,&lListBoxValue)){
  65. m_lCurrentValue |= lListBoxValue;
  66. } else {
  67. LONG lVal = 0;
  68. TSSCANF(szListBoxValue, TEXT("0x%08X"),&lVal);
  69. m_lCurrentValue |= lVal;
  70. }
  71. }
  72. m_szPropertyValue.Format("0x%08X",m_lCurrentValue);
  73. UpdateData(FALSE);
  74. }
  75. BOOL CWiaeditpropflags::OnInitDialog()
  76. {
  77. CDialog::OnInitDialog();
  78. AddValidValuesToListBox();
  79. SelectCurrentValue();
  80. return TRUE; // return TRUE unless you set the focus to a control
  81. // EXCEPTION: OCX Property Pages should return FALSE
  82. }
  83. void CWiaeditpropflags::SelectCurrentValue()
  84. {
  85. //
  86. // TO DO: Fix this code to make the current value match
  87. // the current selection.
  88. //
  89. /*
  90. TCHAR szCurrentValue[MAX_PATH];
  91. memset(szCurrentValue,0,sizeof(szCurrentValue));
  92. lstrcpy(szCurrentValue,m_szPropertyValue);
  93. LONG lVal = 0;
  94. TSSCANF(szCurrentValue,TEXT("%d"),&lVal);
  95. INT iNumItemsInListBox = m_PropertyValidValuesListBox.GetCount();
  96. while(iNumItemsInListBox > 0){
  97. TCHAR szListBoxValue[MAX_PATH];
  98. LONG lListBoxValue = 0;
  99. memset(szListBoxValue,0,sizeof(szListBoxValue));
  100. m_PropertyValidValuesListBox.GetText((iNumItemsInListBox-1),szListBoxValue);
  101. if(TSTR2WIACONSTANT(m_szPropertyName.GetBuffer(m_szPropertyName.GetLength()),szListBoxValue,&lListBoxValue)){
  102. if(lListBoxValue & lVal){
  103. m_PropertyValidValuesListBox.SetSel(iNumItemsInListBox-1);
  104. }
  105. }
  106. iNumItemsInListBox--;
  107. }
  108. */
  109. }
  110. void CWiaeditpropflags::AddValidValuesToListBox()
  111. {
  112. int iStartIndex = FindStartIndexInTable(m_szPropertyName.GetBuffer(m_szPropertyName.GetLength()));
  113. int iEndIndex = FindEndIndexInTable(m_szPropertyName.GetBuffer(m_szPropertyName.GetLength()));
  114. TCHAR szListBoxValue[MAX_PATH];
  115. LONG x = 1;
  116. for (LONG bit = 0; bit<32; bit++) {
  117. memset(szListBoxValue,0,sizeof(szListBoxValue));
  118. // check to see if the bit is set
  119. if (m_lValidValues & x) {
  120. // the bit is set, so find it in the table
  121. if (iStartIndex >= 0) {
  122. // we have a table for this property, use it
  123. TCHAR *pszListBoxValue = NULL;
  124. for (int index = iStartIndex; index <= iEndIndex;index++) {
  125. if (x == WIACONSTANT_VALUE_FROMINDEX(index)) {
  126. pszListBoxValue = WIACONSTANT_TSTR_FROMINDEX(index);
  127. }
  128. }
  129. if(pszListBoxValue != NULL){
  130. // we found the item in the table
  131. lstrcpy(szListBoxValue,pszListBoxValue);
  132. } else {
  133. // we could not find the item in the table, so use
  134. // the actual value
  135. TSPRINTF(szListBoxValue,TEXT("0x%08X"),x);
  136. }
  137. } else {
  138. // we have no items in the table for this property, so use
  139. // the actual value
  140. TSPRINTF(szListBoxValue,TEXT("0x%08X"),x);
  141. }
  142. // add the string to the list box
  143. m_PropertyValidValuesListBox.AddString(szListBoxValue);
  144. }
  145. x <<= 1;
  146. }
  147. }
  148. void CWiaeditpropflags::OnOK()
  149. {
  150. m_szPropertyValue.Format(TEXT("%d"),m_lCurrentValue);
  151. CDialog::OnOK();
  152. }