SerialItem.cpp 854 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #include "StdAfx.h"
  2. #include ".\serialitem.h"
  3. CSerialItem::CSerialItem(void)
  4. {
  5. m_serial = "12348765";
  6. }
  7. CSerialItem::~CSerialItem(void)
  8. {
  9. }
  10. CPropertyGrid::EEditMode CSerialItem::GetEditMode()
  11. {
  12. return CPropertyGrid::EM_INPLACE;
  13. }
  14. void CSerialItem::DrawItem(CDC& dc, CRect rc, bool focused)
  15. {
  16. string serial = m_serial;
  17. while (serial.length()<8) serial += " ";
  18. serial = serial.substr(0,4) + "-" + serial.substr(4,4);
  19. rc.left += m_pGrid->GetTextMargin();
  20. dc.DrawText(serial.c_str(), rc, DT_SINGLELINE|DT_LEFT|DT_VCENTER|DT_END_ELLIPSIS|DT_NOPREFIX);
  21. }
  22. string CSerialItem::GetStringForInPlaceEdit()
  23. {
  24. return m_serial;
  25. }
  26. bool CSerialItem::OnItemEdited(string strNewValue)
  27. {
  28. if (strNewValue.length()!=8)
  29. {
  30. AfxMessageBox("Invalid serial number");
  31. return false;
  32. }
  33. else
  34. {
  35. m_serial = strNewValue;
  36. return true;
  37. }
  38. }