?? memoryeditorlist.cpp
字號:
GetCursorPos(&pt);
// convert point to client area co-ordinates
rect.top = pt.y;
rect.bottom = pt.y;
rect.left = pt.x;
rect.right = pt.x;
ScreenToClient(&rect);
// do a hit test
htInfo.pt.x = rect.left;
htInfo.pt.y = rect.top;
SubItemHitTest(&htInfo); // this will return the Item
//**** 20021101 add by HF
if(htInfo.iSubItem == 0) return;
//**** 20021101 end
if (htInfo.flags & LVHT_ONITEMLABEL)
{
CString description, descrFormat;
WORD memPrefix;
CString registerName;
#ifdef _UI_DEBUGGING
sprintf(position, "\nEditable data columns =%d |", m_displayableWidth);
OutputDebugString(position);
sprintf(position, "Selected at %d, %d (%d,%d)\n", rect.left, rect.top, htInfo.iItem, htInfo.iSubItem);
OutputDebugString(position);
#endif
// absItemNumber = (htInfo.iItem * m_displayableWidth) + htInfo.iSubItem-1;// work out a zero-based index
// absItemNumber = (htInfo.iItem * (NUMBER_LISTCOLS-1)) + htInfo.iSubItem-1;
// **** 20021101 mod by HF start
absItemNumber = (htInfo.iItem * (m_displayableWidth)) + htInfo.iSubItem-1;
// absItemNumber = (htInfo.iItem * (BITS_IN_WORD-1)) + htInfo.iSubItem-1;
// **** 20021101 mod by HF end
memPrefix = PLCMemPrefixes[m_memAreaDisplayed];
descrFormat.Format("Edit %s value at %s", GetFormatName(), GetAddressFormat());
description.Format(descrFormat, (IsAddressFormatHex()?0:memPrefix*10000) + absItemNumber+1);
if (pGlobalDialog->InPlantSimulation())
pGlobalDialog->GetRegisterName(m_memAreaDisplayed, absItemNumber, registerName);
if (htInfo.iSubItem)
{
// if U double-click on a digital, we just toggle it for U quickly
if (pGlobalDialog->PLCIsBitMemory(m_memAreaDisplayed))
{
if (17 == htInfo.iSubItem)
{
DWORD registerValue;
absItemNumber = (htInfo.iItem * (BITS_IN_WORD)) + 0;
registerValue = pGlobalDialog->GetWordValue(m_memAreaDisplayed,
absItemNumber,
BITS_IN_WORD);
descrFormat.Format("Edit %s value at %s", ViewerFormatNames[VIEWFORMAT_HEX], GetAddressFormat());
description.Format(descrFormat, memPrefix*10000 + absItemNumber);
#ifdef _UI_DEBUGGING
OutputDebugString(description);
#endif
{
// construct the "value editor" dialog to edit "16-bits" of I/O
CEditMemoryDlg memEditor(PLCViewerFormats[VIEWFORMAT_HEX], registerName, registerValue, VIEWFORMAT_HEX, description);
if (IDOK==memEditor.DoModal())
{
// unpack the value again into bits
registerValue = (DWORD)memEditor.m_value;
pGlobalDialog->SetWordValue(m_memAreaDisplayed,
absItemNumber,
registerValue,
BITS_IN_WORD);
}
}
// re-paint the row of digitals
RedrawItems(htInfo.iItem, htInfo.iItem);
}
else
{
descrFormat.Format("Toggle digital at %s", GetAddressFormat());
description.Format(descrFormat, (IsAddressFormatHex()? 0 : memPrefix*10000) + absItemNumber);
#ifdef _UI_DEBUGGING
OutputDebugString(description);
#endif
if (PLCMemory[m_memAreaDisplayed][absItemNumber])
PLCMemory.SetAt(m_memAreaDisplayed, absItemNumber, 0);
else
PLCMemory.SetAt(m_memAreaDisplayed, absItemNumber, 1);
// re-paint the digital
RedrawItems(htInfo.iItem, htInfo.iItem);
}
}
else // Edit the item in a dialog
{
DWORD maximumOffset = pGlobalDialog->GetPLCMemoryLimit(m_memAreaDisplayed);
if (absItemNumber < (LONG)maximumOffset/*MAX_MOD_MEMWORDS*/)
{
CEditMemoryDlg memEditor(GetViewFormatString(),
registerName,
pGlobalDialog->GetPLCMemoryValue(m_memAreaDisplayed, absItemNumber, GetViewFormat()),
GetViewFormat(),
description);
#ifdef _UI_DEBUGGING
OutputDebugString(description);
#endif
if (IDOK==memEditor.DoModal())
{
// fetch the item based on it's display formatting
PLCMemory.SetAt(m_memAreaDisplayed,
absItemNumber,
(WORD)memEditor.m_value);
// invalidate the item itself
RedrawItems(htInfo.iItem, htInfo.iItem);
}
}
}
}
else
{
// User clicked in the addresses column.
if (pGlobalDialog->IsAddressFormatHex())
pGlobalDialog->OnViewdec();
else
pGlobalDialog->OnViewhex();
}
}
else
sprintf(position, "Clicked at %d, %d", rect.left, rect.top);
//MessageBox(position);
*pResult = 0;
} // OnDblclk
// ---------------------------------- GetDataColumnCount ------------------------------
int CMemoryEditorList::GetDataColumnCount()
{
int memoryViewWidth = m_displayableWidth;
return(memoryViewWidth);
}
// ------------------------------------ OnGetdispinfo ---------------------------------
void CMemoryEditorList::OnGetdispinfo(NMHDR* pNMHDR, LRESULT* pResult)
{
LV_DISPINFO* pDispInfo = (LV_DISPINFO*)pNMHDR;
// TODO: Add your control notification handler code here
// call my internal function
*pResult = GetListViewDISPINFO((LPARAM)pNMHDR);
} // OnGetdispinfo
// --------------------------- GetListViewDISPINFO -------------------------
//
LRESULT CMemoryEditorList::GetListViewDISPINFO(LPARAM lParam)
{
LPNMHDR lpnmh = (LPNMHDR) lParam;
HWND hwndListView = m_hWnd;
DWORD absItemNumber;
DWORD memoryViewWidth;
DWORD registerValue = 0;
CString valueFormat;
float *pFloat32value;
int viewDataFormat = GetViewFormat(); // fetch user selection
DWORD maximumOffset = pGlobalDialog->GetPLCMemoryLimit(m_memAreaDisplayed);
LV_DISPINFO *lpdi = (LV_DISPINFO *)lParam;
TCHAR szString[MAX_PATH];
if(lpdi->item.iSubItem)
{
// return a sub-item (the data values)
if(lpdi->item.mask & LVIF_TEXT)
{
memoryViewWidth = m_displayableWidth;
if (pGlobalDialog->PLCIsBitMemory(m_memAreaDisplayed))
{
memoryViewWidth--;
// determine the bit #
if (17 == lpdi->item.iSubItem)
{ // the totals column
viewDataFormat = VIEWFORMAT_WORD;// always display in HEX
absItemNumber = (lpdi->item.iItem * (BITS_IN_WORD)) + 0;
registerValue = pGlobalDialog->GetWordValue(m_memAreaDisplayed,
absItemNumber,
BITS_IN_WORD);
valueFormat = PLCViewerFormats[VIEWFORMAT_HEX]; // BIT totals in HEX
}
else
{ // individual bit #
absItemNumber = (lpdi->item.iItem * BITS_IN_WORD) + lpdi->item.iSubItem-1;
registerValue = PLCMemory[m_memAreaDisplayed][absItemNumber];
valueFormat = PLCViewerFormats[VIEWFORMAT_DECIMAL]; // bits are 0 or 1
}
}
else
{
valueFormat = GetViewFormatString();
// determine the register #
absItemNumber = (lpdi->item.iItem * (memoryViewWidth)) + lpdi->item.iSubItem-1;
if (absItemNumber < maximumOffset/*MAX_MOD_MEMWORDS*/)
registerValue = pGlobalDialog->GetPLCMemoryValue(m_memAreaDisplayed, absItemNumber, GetViewFormat());
if ((m_cloneAddressing)&&(GetViewFormat() == VIEWFORMAT_FLOAT))
SwopWords(®isterValue);
}
if (absItemNumber < maximumOffset/*MAX_MOD_MEMWORDS*/)
{
// print the contents
switch (viewDataFormat)
{
case VIEWFORMAT_DECIMAL:
sprintf(szString, valueFormat, (short)registerValue);
break;
case VIEWFORMAT_HEX:
case VIEWFORMAT_WORD:
sprintf(szString, valueFormat, registerValue);
break;
case VIEWFORMAT_DWORD:
sprintf(szString, valueFormat, registerValue);
break;
case VIEWFORMAT_LONG:
sprintf(szString, valueFormat, (LONG)registerValue);
break;
case VIEWFORMAT_FLOAT:
pFloat32value = (float*)®isterValue;
sprintf(szString, valueFormat, *pFloat32value);
break;
default:
ASSERT(0);
break;
}
lstrcpyn(lpdi->item.pszText, szString, lpdi->item.cchTextMax);
}
else
{
lstrcpyn(lpdi->item.pszText, "--", lpdi->item.cchTextMax);
}
}
}
else
{
CString addrFormat;
// return address column values
if(lpdi->item.mask & LVIF_TEXT)
{
DWORD addrEndItem, offset = 0;
absItemNumber = lpdi->item.iItem * (m_displayableWidth) +1 ;//modbus addresses start at 1 not zero
if ((PROTOCOL_SELJOY232 == pGlobalDialog->m_selectedProtocol) ||
(PROTOCOL_SELAB232 == pGlobalDialog->m_selectedProtocol))
{ // Allen-Bradley
offset = 0;
}
else
{ // modbus
if (!IsAddressFormatHex()) // decimal address format
{
if (absItemNumber>9999) //5-digit offset
offset = PLCMemPrefixes[m_memAreaDisplayed]*100000;
else
offset = PLCMemPrefixes[m_memAreaDisplayed]*10000;
}
}
addrFormat.Format("%s-%s", GetAddressFormat(), GetAddressFormat());
// work out the last address on this line/row
addrEndItem = absItemNumber + m_displayableWidth-1;
if (addrEndItem > maximumOffset/*MAX_MOD_MEMWORDS*/)
addrEndItem = maximumOffset/*MAX_MOD_MEMWORDS*/; //range check it
sprintf(szString, addrFormat, offset+absItemNumber, offset+addrEndItem);
lstrcpyn(lpdi->item.pszText, szString, lpdi->item.cchTextMax);
}
if(lpdi->item.mask & LVIF_IMAGE)
{
lpdi->item.iImage = 0;
}
if(lpdi->item.mask & LVIF_INDENT)
{
lpdi->item.iIndent = 0;
}
}
return 0;
} // GetListViewDISPINFO
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -