Leaked source code of windows server 2003
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.

155 lines
3.3 KiB

  1. #include "common.hpp"
  2. CSelControlDlg::CSelControlDlg(CDeviceView &view, CDeviceControl &control, BOOL bReselect, DWORD dwOfs, const DIDEVICEINSTANCEW &didi) :
  3. m_bReselect(bReselect), m_dwOfs(dwOfs), m_didi(didi),
  4. m_view(view), m_control(control), m_bAssigned(FALSE), m_bNoItems(TRUE)
  5. {
  6. }
  7. CSelControlDlg::~CSelControlDlg()
  8. {
  9. }
  10. int CSelControlDlg::DoModal(HWND hParent)
  11. {
  12. return CFlexWnd::DoModal(hParent, IDD_SELCONTROLDLG, g_hModule);
  13. }
  14. BOOL CALLBACK AddItem(LPCDIDEVICEOBJECTINSTANCE lpddoi, LPVOID pvRef)
  15. {
  16. if (pvRef == NULL || lpddoi == NULL)
  17. return DIENUM_CONTINUE;
  18. return ((CSelControlDlg *)pvRef)->AddItem(*lpddoi);
  19. }
  20. BOOL CSelControlDlg::AddItem(const DIDEVICEOBJECTINSTANCE &doi)
  21. {
  22. if (m_hList == NULL || m_view.DoesCalloutOtherThanSpecifiedExistForOffset(&m_control, doi.dwType))
  23. return DIENUM_CONTINUE;
  24. LRESULT i = SendMessage(m_hList, LB_ADDSTRING, 0, (LPARAM)(LPCTSTR)doi.tszName);
  25. if (i == LB_ERR || i == LB_ERRSPACE)
  26. return DIENUM_CONTINUE;
  27. m_bNoItems = FALSE;
  28. i = SendMessage(m_hList, LB_SETITEMDATA, (WPARAM)i, (LPARAM)doi.dwType);
  29. return DIENUM_CONTINUE;
  30. }
  31. void CSelControlDlg::OnInit()
  32. {
  33. m_hList = GetDlgItem(m_hWnd, IDC_LIST);
  34. if (m_hList == NULL)
  35. return;
  36. LPDIRECTINPUTDEVICE8 pDID = NULL;
  37. LPDIRECTINPUT8 pDI = NULL;
  38. DWORD dwVer = DIRECTINPUT_VERSION;
  39. HRESULT hr;
  40. if (FAILED(hr = DirectInput8Create(g_hModule, dwVer, IID_IDirectInput8, (LPVOID*)&pDI, NULL)))
  41. return;
  42. if (FAILED(hr = pDI->CreateDevice(m_didi.guidInstance, &pDID, NULL)))
  43. {
  44. pDID = NULL;
  45. return;
  46. }
  47. pDI->Release();
  48. pDI = NULL;
  49. if (FAILED(hr = pDID->EnumObjects(::AddItem, this, DIDFT_AXIS | DIDFT_BUTTON | DIDFT_POV)))
  50. return;
  51. pDID->Release();
  52. pDID = NULL;
  53. if (m_bNoItems)
  54. {
  55. EndDialog(SCDR_NOFREE);
  56. return;
  57. }
  58. // indicate callout offset assignment...
  59. int i = -1;
  60. if (m_control.IsOffsetAssigned())
  61. {
  62. BOOL m_bAssigned = TRUE;
  63. m_dwOfs = m_control.GetOffset();
  64. i = GetItemWithOffset(m_dwOfs);
  65. }
  66. SendMessage(m_hList, LB_SETCURSEL, (WPARAM)i, 0);
  67. }
  68. LRESULT CSelControlDlg::OnCommand(WORD wNotifyCode, WORD wID, HWND hWnd)
  69. {
  70. switch (wNotifyCode)
  71. {
  72. case LBN_SELCHANGE:
  73. {
  74. if (m_hList == NULL || m_hList != hWnd)
  75. break;
  76. LRESULT lr = SendMessage(m_hList, LB_GETCURSEL, 0, 0);
  77. if (lr == LB_ERR)
  78. break;
  79. lr = SendMessage(m_hList, LB_GETITEMDATA, (WPARAM)lr, 0);
  80. if (lr == LB_ERR)
  81. break;
  82. m_dwOfs = (DWORD)lr;
  83. m_bAssigned = TRUE;
  84. break;
  85. }
  86. case BN_CLICKED:
  87. switch (wID)
  88. {
  89. case IDOK:
  90. if (m_bAssigned)
  91. EndDialog(SCDR_OK);
  92. else
  93. MessageBox(m_hWnd, TEXT("You must either select a control for this callout or click cancel."), TEXT("Select a Control"), MB_OK);
  94. break;
  95. case IDCANCEL:
  96. EndDialog(SCDR_CANCEL);
  97. break;
  98. }
  99. break;
  100. }
  101. return 0;
  102. }
  103. int CSelControlDlg::GetItemWithOffset(DWORD dwOfs)
  104. {
  105. if (m_hList == NULL)
  106. return -1;
  107. LRESULT lr = SendMessage(m_hList, LB_GETCOUNT, 0, 0);
  108. if (lr == LB_ERR)
  109. return -1;
  110. int n = int(lr);
  111. if (n < 1)
  112. return -1;
  113. for (int i = 0; i < n; i++)
  114. {
  115. lr = SendMessage(m_hList, LB_GETITEMDATA, (WPARAM)i, 0);
  116. if (lr == LB_ERR)
  117. continue;
  118. if ((DWORD)lr == dwOfs)
  119. return i;
  120. }
  121. return -1;
  122. }