// ServiceEditDlg.cpp : 实现文件//
#include “stdafx.h”
#include “ServiceEditDlg.h”
#include “afxdialogex.h”
#include “MFCAppTool.h”
// CServiceEdit 对话框
IMPLEMENT_DYNAMIC(CServiceEditDlg, CDialogEx)
- CServiceEditDlg::CServiceEditDlg(CWnd* pParent / =NULL/)
-
CDialogEx(IDD_DIALOG_SERVICE, pParent)
{
CString DesciptionArray0[7] = { TEXT(“RBT201”), TEXT(“RBT131”), TEXT(“RBT111”), TEXT(“RBTA01”), TEXT(“RBT10F”), TEXT(“RBT10X”), TEXT(“RBT10M”) };
CString LengthArray0[7] = { TEXT(“0.52”), TEXT(“19.02”), TEXT(“9.52”), TEXT(“9.02”), TEXT(“4.52”), TEXT(“3.52”), TEXT(“9.79”) };
CString ZeroLengthArray0[7] = { TEXT(“RBTWAVE3:8.77”), TEXT(“RBTOTHER:5.32”), TEXT(“RBTWAVE3:10.11”), TEXT(“RBTWAVE5:3.99”), TEXT(“RBTOTHER:4.07”), TEXT(“RBTWAVE5:2.82”), TEXT(“RBTWAVE5:5.15”) };
CString ODArray0[7] = { TEXT(“5.87”), TEXT(“3.67”), TEXT(“8.88”), TEXT(“9.12”), TEXT(“0.07”), TEXT(“8.03”), TEXT(“3.81”) };
CString WeightArray0[7] = { TEXT(“21.52”), TEXT(“49.02”), TEXT(“9.06”), TEXT(“11.20”), TEXT(“5.02”), TEXT(“2.42”), TEXT(“0.79”) };for (int i = 0; i < sizeof(DesciptionArray0) / sizeof(DesciptionArray0[0]); i++)
DesciptionArray[i] = DesciptionArray0[i];for (int i = 0; i < sizeof(LengthArray0) / sizeof(LengthArray0[0]); i++)
LengthArray0[i] = LengthArray0[i];for (int i = 0; i < sizeof(ZeroLengthArray0) / sizeof(ZeroLengthArray0[0]); i++)
ZeroLengthArray[i] = ZeroLengthArray0[i];for (int i = 0; i < sizeof(ODArray0) / sizeof(ODArray0[0]); i++)
ODArray[i] = ODArray0[i];for (int i = 0; i < sizeof(WeightArray0) / sizeof(WeightArray0[0]); i++)
WeightArray[i] = WeightArray0[i];
}
CServiceEditDlg::~CServiceEditDlg()
{
}
void CServiceEditDlg::DoDataExchange(CDataExchange* pDX)
{
CDialogEx::DoDataExchange(pDX);
DDX_Control(pDX, IDC_TREE_TOOLS, m_tree_tools);
DDX_Control(pDX, IDC_LIST_SERVICES, m_list_services);
DDX_Control(pDX, IDC_EDIT_SERVICE_NAME, m_eidt_service_name);
DDX_Control(pDX, IDC_STATIC_SENSORS_PICTURE, m_static_drawning);
DDX_Control(pDX, IDC_STATIC_TEST, m_statinc_test);
}
BEGIN_MESSAGE_MAP(CServiceEditDlg, CDialogEx)
ON_NOTIFY_EX(TTN_NEEDTEXT, 0, OnToolTipNotify)
ON_BN_CLICKED(ID_SAVE, &CServiceEditDlg::OnBnClickedSave)
ON_BN_CLICKED(IDC_BUTTON_ADD, &CServiceEditDlg::OnBnClickedButtonAdd)
ON_NOTIFY(TVN_SELCHANGED, IDC_TREE_TOOLS, &CServiceEditDlg::OnTvnSelchangedTreeTools)
ON_WM_CREATE()
ON_WM_LBUTTONDOWN()
ON_WM_LBUTTONUP()
ON_WM_MOUSEMOVE()
ON_BN_CLICKED(IDC_BUTTON_FIND, &CServiceEditDlg::OnBnClickedButtonFind)
ON_WM_PAINT()
ON_WM_TIMER()
ON_NOTIFY(LVN_ITEMCHANGED, IDC_LIST_SERVICES, &CServiceEditDlg::OnLvnItemchangedListServices)
ON_NOTIFY(TVN_BEGINDRAG, IDC_TREE_TOOLS, &CServiceEditDlg::OnBegindragTreeTools)
ON_WM_DRAWITEM()
ON_WM_MOUSEHOVER()
ON_STN_CLICKED(IDC_STATIC_SENSORS_PICTURE, &CServiceEditDlg::OnClickedStaticSensorsPicture)
ON_WM_RBUTTONDOWN()
ON_COMMAND(ID_DELETE_DELETE, &CServiceEditDlg::OnDeleteDelete)
END_MESSAGE_MAP()
// CServiceEdit 消息处理程序
//设计和编程说明:(1)2个表数据显示时排序;(2)左右表格数据联动;(3)右表数据与下发数据联动;(4)删除时,需确认后再直接保存数据;(5)如果下面数据更改,而用户操作变化时,需提示用户是否保存数据;(6)表格数据有序号列;(7)可以用Tab Control现实
BOOL CServiceEditDlg::OnInitDialog()
{
CDialogEx::OnInitDialog();
HICON m_hIcon; //定义一个icon句柄
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);//加载资源文件ID为IDR_MAINFRAME的资源
SetIcon(m_hIcon, FALSE); // Set small icon 设置小图标
EnableToolTips(TRUE);
//m_pToolTipCtrl.AddTool(GetDlgItem(IDC_LIST_SKETCH_DRAWING), LPSTR_TEXTCALLBACK);
// 初始化服务仪器串列表
initListControl_Services();
// 初始化仪器串树形表
initTreeView_Data();
/// 初始化界面, 长度,风格等
initOtherControlData();
return TRUE; // return TRUE unless you set the focus to a control
}
BOOL CServiceEditDlg::OnToolTipNotify(UINT id, NMHDR * pTTTStruct, LRESULT * pResult)
{
UNREFERENCED_PARAMETER(id);
TOOLTIPTEXT *pTTT = (TOOLTIPTEXT *)pTTTStruct;
UINT nID = pTTTStruct->idFrom;
if (pTTT->uFlags && TTF_IDISHWND)
{
nID = ::GetDlgCtrlID((HWND)nID);
switch (nID)
{
case IDD_DIALOG_SERVICE:
case IDC_TREE_TOOLS:
case IDC_LIST_SERVICES:
//pTTT->lpszText = _T("设计和编程说明:(1)2个表数据显示时排序;(2)左右表格数据联动;(3)右表数据与下发数据联动;(4)删除时,需确认后再直接保存数据;(5)如果下面数据更改,而用户操作变化时,需提示用户是否保存数据;(6)表格数据有序号列;(7)可以用Tab Control现实");
pTTT->lpszText = _T("trol现实");
pTTT->hinst = AfxGetResourceHandle();
//MessageBox(_T("OnToolTipNotify"));
break;
}
}
*pResult = 0;
return TRUE;
}
void CServiceEditDlg::initOtherControlData()
{
/// 初始化界面, 长度,风格等
m_eidt_service_name.SetWindowTextW(TEXT(“2.00”));
pDC = m_static_drawning.GetDC();
m_static_drawning.GetClientRect(&rectView);
rectView.left += nGridMargin;
rectView.top += nGridMargin;
rectView.bottom -= nGridMargin;
rectView.right -= nGridMargin;
//TRACE3("\n\r\n\r initOtherControlData rectView.left = %d rectView.top = %d rectView.right = %d rectView.bottom = %d", rectView.left, rectView.top, rectView.right, rectView.bottom);
colorSkectchBackGround = pDC->GetBkColor(); //背景色
colorSkectchBackGround = RGB(255, 255, 255); // TRANSPARENT
fontHeaderText.CreateFont(
18, 0, 0, 700, FW_BOLD, FALSE, FALSE, 0, ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,
DEFAULT_QUALITY, DEFAULT_PITCH | FF_SWISS, _T("Arial")); ///FW_NORMAL
colorHeaderText = (COLORREF)RGB(0, 0, 0); //(COLORREF)RGB(255,0, 0);
colorBodyText = (COLORREF)RGB(0, 0, 0);
LOGFONT logFont;
pFontBodyTextNormal = GetFont();
pFontBodyTextNormal->GetLogFont(&logFont);
logFont.lfHeight = -100;
fontBodyTextNormal.DeleteObject();
fontBodyTextNormal.CreatePointFontIndirect(&logFont);
pFontBodyTextNormal = &fontBodyTextNormal;
}
void CServiceEditDlg::initSketchViewAll(){
pDC->Rectangle(&rectView);
drawingSketchGrid();
drawingSketchHeaderText();
}
// 根据图片文件的名称, 在指定位置显示图片
bool CServiceEditDlg::showGraph_JpgGifBmpWmf(CDC* &pDC0, CString strPath, int x, int y, int width, int height, COLORREF colorBack)
{
CFile file;
CFileStatus fstatus;
IStream *pStm;
LONG cb;
HGLOBAL hGlobal = NULL;
LPVOID pvData = NULL;
TRACE(TEXT("\n\r\n\r") + strPath);
//pDC0 = m_static_drawning.GetDC();
// 打开文件
if (!(file.Open(strPath, CFile::modeRead) && file.GetStatus(strPath, fstatus) && ((cb = (LONG)fstatus.m_size) != -1))) {
return false;
}
// 分配内存
hGlobal = GlobalAlloc(GMEM_MOVEABLE, cb);
if (!hGlobal)
{
file.Close();
return false;
}
// 锁定内存
pvData = GlobalLock(hGlobal);
if (!pvData)
{
file.Close();
GlobalFree(hGlobal);
return false;
}
//读取文件
file.Read(pvData, cb);
file.Close();
GlobalUnlock(hGlobal);
CreateStreamOnHGlobal(hGlobal, TRUE, &pStm);
//显示JPEG和GIF格式的图片,GIF只能显示一帧,还不能显示动画,
//要显示动画GIF请使用ACTIVE控//件。
IPicture *pPic = nullptr;
/// load image from file stream
if (!SUCCEEDED(OleLoadPicture(pStm, (LONG)fstatus.m_size, TRUE, IID_IPicture, (LPVOID*)&pPic)))
{
GlobalFree(hGlobal);
return false;
}
GlobalFree(hGlobal);
RECT rect;
rect.left = x; rect.top = y; rect.bottom = y + height; rect.right = x + width;
// 因为前后图片大小不一,故清除区域
pDC->FillSolidRect(&rect, colorBack);
OLE_XSIZE_HIMETRIC hmWidth;
OLE_YSIZE_HIMETRIC hmHeight;
//get image height and width
pPic->get_Width(&hmWidth);
pPic->get_Height(&hmHeight);
double fX, fY;
//fX = (double)pDC->GetDeviceCaps(HORZRES)*(double)hmWidth / ((double)pDC->GetDeviceCaps(HORZSIZE)*100.0);
//fY = (double)pDC->GetDeviceCaps(VERTRES)*(double)hmHeight / ((double)pDC->GetDeviceCaps(VERTSIZE)*100.0);
fX = width;
fY = height;
//use render function display image
if (FAILED(pPic->Render(*pDC0, x, y, (DWORD)fX, (DWORD)fY, 0, hmHeight, hmWidth, -hmHeight, NULL)))
{
pPic->Release();
return false;
}
pPic->Release();
return true;
}
void CServiceEditDlg::drawToolSketchAll(CString strSketchFileName, CRect rect) {
showGraph_JpgGifBmpWmf(pDC, strSketchFileName, rect.left, rect.top, rect.right, rect.bottom, colorSkectchBackGround);
pDC->SetBkMode(TRANSPARENT);
pDC->SetTextColor(colorBodyText); //设置字体颜色
pDC->SelectObject(pFontBodyTextNormal); // pFontBodyTextNormal
pDC->MoveTo((rect.left + rect.right) * 2 / 3 + 10, rect.top - 1);
pDC->LineTo((rect.left + rect.right) * 2 / 3 + 99, rect.top - 1);
pDC->MoveTo((rect.left + rect.right) * 2 / 3 + 10, rect.top + rect.bottom - 1);
pDC->LineTo((rect.left + rect.right) * 2 / 3 + 99, rect.top + rect.bottom - 1);
pDC->TextOut((rect.left + rect.right) * 2 / 3 + 16, rect.top + rect.bottom / 2 - 10, _T("<"));
pDC->MoveTo((rect.left + rect.right) * 2 / 3 + 20, rect.top + rect.bottom / 2 - 2);
pDC->LineTo((rect.left + rect.right) * 2 / 3 + 116, rect.top + rect.bottom / 2 - 2);
drawTextAlignCenter(rectView.left + nSkectchWidth, rect.top + rect.bottom / 2 - 8, nDataColWidth, 0, strFileNameArray[nIndex]);
//drawTextAlignCenter(rectView.left + nSkectchWidth, rect.top + rect.bottom / 2 - 8, nDataColWidth, 0, DesciptionArray[nIndex]);
if (nIndex % 3)
drawTextAlignCenter(rectView.left + nSkectchWidth, rect.top + rect.bottom / 2 + 10, nDataColWidth, 0, _T("113905"));
drawTextAlignCenter(rectView.left + nSkectchWidth + nDataColWidth, rect.top + rect.bottom / 2 - 8, nDataColWidth, 0, LengthArray[nIndex]);
if (nIndex % 2)
drawTextAlignCenter(rectView.left + nSkectchWidth + nDataColWidth * 2, rect.top + rect.bottom / 2 - 26, nDataColWidth, 0, _T("RBTOTHER:3.67"));
drawTextAlignCenter(rectView.left + nSkectchWidth + nDataColWidth * 2, rect.top + rect.bottom / 2 - 8, nDataColWidth, 0, ZeroLengthArray[nIndex]);
if (nIndex % 2)
drawTextAlignCenter(rectView.left + nSkectchWidth + nDataColWidth * 2, rect.top + rect.bottom / 2 + 10, nDataColWidth, 0, _T("RBTWAVE5:3.67"));
drawTextAlignCenter(rectView.left + nSkectchWidth + nDataColWidth * 3, rect.top + rect.bottom / 2 - 8, nDataColWidth, 0, ODArray[nIndex]);
drawTextAlignCenter(rectView.left + nSkectchWidth + nDataColWidth * 4, rect.top + rect.bottom / 2 - 8, nDataColWidth, 0, WeightArray[nIndex]);
dSumLength += _wtof(LengthArray[nIndex].GetBuffer());
dSumWeight += _wtof(WeightArray[nIndex].GetBuffer());
rect.left = rectView.left + nSkectchWidth + nDataColWidth + 8; rect.top = rectView.bottom - 22;
rect.right = rect.left + nDataColWidth - 8; rect.bottom = rect.top + 20;
pDC->FillSolidRect(rect, colorSkectchBackGround);
rect.left += nDataColWidth * 3;
rect.right += nDataColWidth * 3;
pDC->FillSolidRect(rect, colorSkectchBackGround);
CString strTemp;
strTemp.Format(TEXT("ToolString(%.2f)"), dSumLength);
drawTextAlignCenter(rectView.left + nSkectchWidth + nDataColWidth, rectView.bottom - 22, nDataColWidth, 0, strTemp);
strTemp.Format(TEXT("ToolString(%.2f)"), dSumWeight);
drawTextAlignCenter(rectView.left + nSkectchWidth + nDataColWidth * 4, rectView.bottom - 22, nDataColWidth, 0, strTemp);
}
void CServiceEditDlg::readToolSketchFile(CString strSketchFileName, CRect &rect) {
CString strAppPath;
GetModuleFileName(NULL, strAppPath.GetBuffer(MAX_PATH), MAX_PATH);
strAppPath.ReleaseBuffer(); //Must ReleaseBuffer, or GetLength=0
int len = strAppPath.GetLength();
int pos = strAppPath.ReverseFind(_T('\\'));
strAppPath = strAppPath.Left(pos + 1);
strSketchFileName = strAppPath + TEXT("res\\tools\\") + strSketchFileName;
TRACE(TEXT("\n\r\n\r") + strSketchFileName);
drawToolSketchAll(strSketchFileName, rect);
}
void CServiceEditDlg::OnBnClickedSave()
{
// TODO: 在此添加控件通知处理程序代码
nNumberOfTools = 0;
initSketchViewAll();
}
void CServiceEditDlg::OnBnClickedButtonAdd()
{
nNumberOfTools = 0;
initSketchViewAll();
}
void CServiceEditDlg::initTreeView_Data() {
// 初始化仪器串树形表
HTREEITEM hTreeItemRoot; // 树的根节点的句柄
HTREEITEM hTreeItemSum; // 二级节点的句柄 插入根节点
CImageList *m_pImageList;
m_pImageList = new CImageList();
m_pImageList->Create(32, 32, ILC_COLOR32, 0, 2);
m_pImageList->Add(AfxGetApp()->LoadIconW(IDI_ICON_Start1));
m_pImageList->Add(AfxGetApp()->LoadIconW(IDI_ICON_Pause1));
m_tree_tools.SetImageList(m_pImageList, TVSIL_NORMAL);
hTreeItemRoot = m_tree_tools.InsertItem(_T("RUSTOOL"), 1, 0);
// 在根节点下插入子节点
hTreeItemSum = m_tree_tools.InsertItem(_T("BSW"), 1, 0, hTreeItemRoot, TVI_LAST);
// 在根节点下插入第二个子节点
hTreeItemSum = m_tree_tools.InsertItem(_T("BULL"), 1, 0, hTreeItemRoot, TVI_LAST);
// 在根节点下插入第三个子节点
hTreeItemSum = m_tree_tools.InsertItem(_T("CCL"), 1, 0, hTreeItemRoot, TVI_LAST);
hTreeItemRoot = m_tree_tools.InsertItem(_T("FDD"), 1, 0);
hTreeItemSum = m_tree_tools.InsertItem(_T("MCT40"), 1, 0, hTreeItemRoot, TVI_LAST);
hTreeItemSum = m_tree_tools.InsertItem(_T("SF"), 1, 0, hTreeItemRoot, TVI_LAST);
hTreeItemSum = m_tree_tools.InsertItem(_T("CAT"), 1, 0);
hTreeItemSum = m_tree_tools.InsertItem(_T("MCT24"), 1, 0, hTreeItemRoot, TVI_LAST);
hTreeItemSum = m_tree_tools.InsertItem(_T("CTF"), 1, 0, hTreeItemRoot, TVI_LAST);
}
void CServiceEditDlg::OnTvnSelchangedTreeTools(NMHDR *pNMHDR, LRESULT *pResult)
{
LPNMTREEVIEW pNMTreeView = reinterpret_cast(pNMHDR);
// TODO: 在此添加控件通知处理程序代码
*pResult = 0;
CString strText; // 树节点的标签文本字符串
// 获取当前选中节点的句柄
HTREEITEM hItem = m_tree_tools.GetSelectedItem();
HTREEITEM hRoot = m_tree_tools.GetParentItem(hItem);
// 获取选中节点的标签文本字符串
strText = m_tree_tools.GetItemText(hRoot) + "->" + m_tree_tools.GetItemText(hItem);
//// 将字符串显示到编辑框中
//SetDlgItemText(IDC_EDIT_REMARK, strText);
}
void CServiceEditDlg::drawingSketchGrid() {
CRect lineRectArrary[6];
CPen *pOldPen, pen(PS_SOLID, 4, RGB(128, 128, 225));
// 外边框
pOldPen = pDC->SelectObject(&pen);
pDC->MoveTo(rectView.left, rectView.top);
pDC->LineTo(rectView.right, rectView.top);
pDC->LineTo(rectView.right, rectView.bottom);
pDC->LineTo(rectView.left, rectView.bottom);
pDC->LineTo(rectView.left, rectView.top);
// 列横线
pDC->SelectObject(pOldPen);
pDC->MoveTo(rectView.left, rectView.top + nHeaderHeight);
pDC->LineTo(rectView.right, rectView.top + nHeaderHeight);
nSkectchWidth = nSkectchWidthRatio*(rectView.right - rectView.left) / 100;
nDataColWidth = (rectView.right - rectView.left - nSkectchWidth) / 5;
int nX = rectView.left + nSkectchWidth;
// 列竖线
pDC->MoveTo(nX, rectView.top);
pDC->LineTo(nX, rectView.bottom);
pDC->MoveTo(nX + nDataColWidth, rectView.top);
pDC->LineTo(nX + nDataColWidth, rectView.bottom);
pDC->MoveTo(nX + nDataColWidth * 2, rectView.top);
pDC->LineTo(nX + nDataColWidth * 2, rectView.bottom);
pDC->MoveTo(nX + nDataColWidth * 3, rectView.top);
pDC->LineTo(nX + nDataColWidth * 3, rectView.bottom);
pDC->MoveTo(nX + nDataColWidth * 4, rectView.top);
pDC->LineTo(nX + nDataColWidth * 4, rectView.bottom);
}
void CServiceEditDlg::drawingSketchHeaderText()
{
CFont *pfontOld;
pfontOld = pDC->GetCurrentFont();//保存原始
int x = rectView.left + nSkectchWidth / 2 - 26;
int y = rectView.top + nHeaderHeight / 2 - 6;
pDC->SetBkMode(TRANSPARENT);
pDC->SetTextColor(colorHeaderText); //设置字体颜色
pDC->SelectObject(&fontHeaderText);
drawTextAlignCenter(rectView.left, y, nSkectchWidth, 0, _T("Sketch"));
drawTextAlignCenter(rectView.left + nSkectchWidth, y, nDataColWidth, 0, _T("Desciption"));
drawTextAlignCenter(rectView.left + nSkectchWidth + nDataColWidth, y, nDataColWidth, 0, _T("Length(ft)"));
drawTextAlignCenter(rectView.left + nSkectchWidth + nDataColWidth * 2, y, nDataColWidth, 0, _T("Zero Length(ft)"));
drawTextAlignCenter(rectView.left + nSkectchWidth + nDataColWidth * 3, y, nDataColWidth, 0, _T("OD(mm)"));
drawTextAlignCenter(rectView.left + nSkectchWidth + nDataColWidth * 4, y, nDataColWidth, 0, _T("Weight(lb)"));
//////////////////////////////////////////////////////////////////////////
CFont fontTextSizeExample;
fontTextSizeExample.CreateFont(
80, 0, 700, 0, FW_BOLD, FALSE, FALSE, 0, ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,
DEFAULT_QUALITY, DEFAULT_PITCH | FF_SWISS, _T("Arial"));
pDC->SelectObject(&fontTextSizeExample);
pDC->SetTextColor(colorHeaderText); //设置字体颜色
//pDC->TextOut(nSkectchWidth, nHeaderHeight*5, _T("Sketch"));
//////////////////////////////////////////////////////////////////////////
pDC->SelectObject(pfontOld);
}
void CServiceEditDlg::OnBnClickedButtonFind()
{
nNumberOfTools = 0;
initSketchViewAll();
}
// 初始化服务仪器串列表
void CServiceEditDlg::initListControl_Services()
{
/////////////////////////////////////////////////////////////////////////////////////
long dwStyle = m_list_services.GetExtendedStyle();
dwStyle |= LVS_EX_GRIDLINES | LVS_EX_FULLROWSELECT; //网格线(只适用与报表风格的listctrl)LVS_EX_CHECKBOXES
//m_list_services.ModifyStyle(0, LVS_REPORT); //LVS_REPORT LVS_LIST
m_list_services.SetExtendedStyle(dwStyle);
////////*********************************************////////////////////////////////////////////////////////
CRect lc_rect;
m_list_services.GetWindowRect(&lc_rect);
DWORD dwListLength = lc_rect.Width();
m_list_services.InsertColumn(0, _T("No"), LVCFMT_LEFT, dwListLength / 5); // LVCFMT_LEFT LVCFMT_IMAGE
m_list_services.InsertColumn(1, _T("ToolStrng Name"), LVCFMT_LEFT, dwListLength * 4 / 5);
//////////*********************************************////////////////////////////////////////////////////////TEXT("ADCOUNTER\0"), TEXT("AddCurve\0"), TEXT("AD\0"), TEXT("AMI\0"), TEXT("ATL\0"), TEXT("AUX\0"), TEXT("CALCULATE"), TEXT("COUNTER"), TEXT("DIGCBL"),
///TEXT("MIDK"), TEXT("OTHER"), TEXT("PNN"), TEXT("RUSPLT"), TEXT("SBT"), TEXT("TIMER"), TEXT("WR"), TEXT("WSCBUS"), TEXT("WTC"), TEXT("YHH")
// , TEXT("1417CBL.wmf"),
wchar_t *servics_array[] = { TEXT("BSW"), TEXT("BULL"), TEXT("CCL"), TEXT("CCL11"), TEXT("CFB"), TEXT("CHD"), TEXT("CTF"), TEXT("CTF02"),
TEXT("DRC"), TEXT("FDR"), TEXT("Flow"), TEXT("GAUGE"), TEXT("GCT04"), TEXT("GR"), TEXT("HCT"), TEXT("HTF"), TEXT("HTF01"),
TEXT("IFJM19"), TEXT("ILS"), TEXT("JAR"), TEXT("MCT24"), TEXT("MCT40"), TEXT("NST01"), TEXT("NST02"), TEXT("PKJ"),
TEXT("QPC"), TEXT("QPT"), TEXT("SBT"), TEXT("SF"), TEXT("SINKBAR1"), TEXT("SINKBAR2"), TEXT("SlipCenter"), TEXT("SlipCenter1"),
TEXT("SPRING_PRC"), TEXT("SPSJ"), TEXT("TEMP"), TEXT("TRACTOR"), TEXT("VDL"), TEXT("WHEEL_PRC"), TEXT("WSBUS") };
for (int i = 0; i < sizeof(servics_array) / sizeof(servics_array[0]); i++) {
CString strTemp;
int row = m_list_services.InsertItem(m_list_services.GetItemCount(), _T("什么是Label"));//设置第0行,第1列值
strTemp.Format(TEXT("%d"), row);
m_list_services.SetItemText(row, 0, strTemp.GetBuffer()); //设置第0行,第1列值
m_list_services.SetItemText(row, 1, servics_array[i]); //设置第0行,第1列值
}
//////////*********************************************////////////////////////////////////////////////////////
CFont * cFont = new CFont;
cFont->CreateFont(16, 0, 0, 0, FW_BOLD, FALSE, FALSE, 0,
ANSI_CHARSET, OUT_DEFAULT_PRECIS,
CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY,
DEFAULT_PITCH&FF_SWISS, _T("Arial"));
CHeaderCtrl *listControlHeader = NULL;
listControlHeader = m_list_services.GetHeaderCtrl();
listControlHeader->SetFont(cFont);
}
///////////////////////////////////////////////////////////////////////////////////////
//long dwStyle = m_list_services.GetExtendedStyle();
//
//dwStyle |= LVS_EX_GRIDLINES | LVS_EX_FULLROWSELECT | WS_CLIPCHILDREN; //网格线(只适用与报表风格的listctrl)LVS_EX_CHECKBOXES
//
////m_list_services.ModifyStyle(0, LVS_REPORT); //LVS_REPORT LVS_LIST
//m_list_services.SetExtendedStyle(dwStyle);
void CServiceEditDlg::OnPaint()
{
// 视图框架, 新增加的视图不在此处显示
initSketchViewAll();
drawAllSketchData();
CPaintDC dc(this); // device context for painting
// 不为绘图消息调用 CDialogEx::OnPaint()
}
void CServiceEditDlg::drawTextAlignCenter(int x, int y, int width, int height, CString strText) {
CPoint point;
point = pDC->GetTextExtent(strText);
pDC->TextOut(x + (width - point.x) / 2, y + (height - point.y) / 2, strText.GetString());
}
void CServiceEditDlg::OnLvnItemchangedListServices(NMHDR *pNMHDR, LRESULT *pResult)
{
LPNMLISTVIEW pNMLV = reinterpret_cast(pNMHDR);
// TODO: 在此添加控件通知处理程序代码
*pResult = 0;
if (nNumberOfTools >= 7) return;
NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
if (pNMListView->uChanged != LVIF_STATE)
return;
if (!(pNMListView->uNewState & LVIS_SELECTED))
return;
int row = m_list_services.GetNextItem(-1, LVNI_ALL | LVNI_SELECTED);
if (row < 0) return;
}
void CServiceEditDlg::drawAllSketchData()
{
CRect rect; //建立一个矩形(0,00, 10, 10)可实现上下翻转
rect.left = rectView.left + nSkectchX;
rect.top = rectView.top + nSkectchY + nHeaderHeight;
rect.right = nSkectchWidth - nSkectchX * 2;
rect.bottom = rectView.bottom - rect.top - nSkectchY;
double nSumLenght = 0.0;
for (int i = 0; i < nNumberOfTools; i++) {
nSumLenght += dSensorLengthArray[i];
}
dSumLength = 0.00, dSumWeight = 0.00;
for (int i = 0; i < nNumberOfTools; i++) {
nIndex = i;
rect.bottom = (int)(dSensorLengthArray[i] / nSumLenght * (rectView.bottom - rectView.top - nSkectchX - nSkectchY - nHeaderHeight));
readToolSketchFile(strFileNameArray[i].GetString(), rect);
//////////////////////////////////////////////////////
// 保存图像的水平位置
//////////////////////////////////////////
rectArray[i] = rect;
rectArray[i].top = rect.top - 1;
rectArray[i].left = rect.left + 10;
rectArray[i].right = rect.right;
rectArray[i].bottom = rect.top + rect.bottom - 1;
//////////////////////////////////////////
rect.top += rect.bottom;
TRACE("\n\r\n\r OnBnClickedButtonFind strFileNameArray[nNumberOfTools]= %s", strFileNameArray[i].GetString());
}
}
void CServiceEditDlg::insertOneTool(int indexTemp, CString strSketchFileName){
for (int i = 5; i >= indexTemp; i--){
LengthArray[i + 1] = LengthArray[i];
WeightArray[i + 1] = WeightArray[i];
ZeroLengthArray[i + 1] = ZeroLengthArray[i];
ODArray[i + 1] = ODArray[i];
DesciptionArray[i + 1] = DesciptionArray[i];
strFileNameArray[i + 1] = strFileNameArray[i];
dSensorLengthArray[i + 1] = dSensorLengthArray[i];
}
strFileNameArray[indexTemp] = strSketchFileName;
m_eidt_service_name.GetWindowTextW(strSketchFileName);
dSensorLengthArray[indexTemp] = _wtof(strSketchFileName.GetBuffer());
strSketchFileName.Format(TEXT("%.2f"), dSensorLengthArray[indexTemp]);
LengthArray[indexTemp] = strSketchFileName;
nNumberOfTools++;
// 清除所有
initSketchViewAll();
drawAllSketchData();
}
void CServiceEditDlg::deleteOneTool(int indexTemp ){
for (int i = indexTemp; i < 6; i++){
LengthArray[i] = LengthArray[i + 1];
WeightArray[i] = WeightArray[i + 1];
ZeroLengthArray[i] = ZeroLengthArray[i + 1];
ODArray[i ] = ODArray[i + 1];
DesciptionArray[i ] = DesciptionArray[i + 1];
strFileNameArray[i] = strFileNameArray[i + 1];
dSensorLengthArray[i] = dSensorLengthArray[i + 1];
}
nNumberOfTools--;
// 清除所有
nIndex = 0;
initSketchViewAll();
drawAllSketchData();
}
void CServiceEditDlg::OnBegindragTreeTools(NMHDR *pNMHDR, LRESULT *pResult)
{
// TODO: Add your control notification handler code here
LPNMTREEVIEW pNMTreeView = reinterpret_cast<LPNMTREEVIEW>(pNMHDR);
if (pNMTreeView == NULL)
return;
m_hTreeItemDrag = pNMTreeView->itemNew.hItem;
if (!m_hTreeItemDrag)
return;
HTREEITEM hTreeItem = m_tree_tools.GetParentItem(m_hTreeItemDrag);
if (!hTreeItem) return;
CString strTemp; // , strTemp0 = TEXT(".wmf");
strTemp = m_tree_tools.GetItemText(m_hTreeItemDrag).MakeLower().GetString();
//if (strTemp.Find(strTemp0) < 0) return;
//得到用于拖动时显示的图象列表
m_pImageList = m_tree_tools.CreateDragImage(m_hTreeItemDrag);
if (!m_pImageList)
return;
m_pImageList->BeginDrag(0, CPoint(8, 8));
CPoint pt = pNMTreeView->ptDrag;
ClientToScreen(&pt);
m_pImageList->DragEnter(this, pt); // "this"将拖动操作限制在该窗口
SetCapture();
m_bDragging = TRUE;
*pResult = 0;
}
void CServiceEditDlg::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: 在此添加消息处理程序代码和/或调用默认值
UINT flags;
HTREEITEM hItem;
if (!m_bDragging)
return;
m_pImageList->DragMove(point);
m_pImageList->DragShowNolock(true);
//鼠标经过时高亮显示
if ((hItem = m_tree_tools.HitTest(point, &flags)) != NULL)
m_tree_tools.SelectDropTarget(hItem);
CDialogEx::OnMouseMove(nFlags, point);
}
void CServiceEditDlg::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: 在此添加消息处理程序代码和/或调用默认值
CDialogEx::OnLButtonDown(nFlags, point);
}
void CServiceEditDlg::OnLButtonUp(UINT nFlags, CPoint point)
{
// TODO: 在此添加消息处理程序代码和/或调用默认值
CDialogEx::OnLButtonUp(nFlags, point);
if (!m_bDragging) {
return;
}
CDialogEx::OnLButtonUp(nFlags, point);
m_pImageList->DragLeave(this);
m_pImageList->EndDrag();
ReleaseCapture();
delete m_pImageList;
m_bDragging = FALSE;
m_tree_tools.SelectDropTarget(NULL);
m_tree_tools.SetRedraw();
if (!m_hTreeItemDrag) return;
////判断是哪一个Tool////////////////////////////////////////////////////////////////////////////////
CString strFileName;
CPoint m_mouse;
strFileName = m_tree_tools.GetItemText(m_hTreeItemDrag)+ TEXT(".wmf");
m_hTreeItemDrag = NULL;
GetCursorPos(&m_mouse);
m_static_drawning.ScreenToClient(&m_mouse);
//m_statinc_test.SetWindowTextW(m_tree_tools.GetItemText(m_hTreeItemDrag).GetString() + strTemp);
int indexTemp = -1;
for (int i = 0; i < nNumberOfTools; i++){
//strTemp1.Format(TEXT(" rectArray[i] = (%d, %d, %d, %d)"), rectArray[i].left, rectArray[i].top, rectArray[i].right, rectArray[i].bottom);
if (m_mouse.x > rectArray[i].left && m_mouse.x < rectArray[i].right)
if (m_mouse.y > rectArray[i].top && m_mouse.y < rectArray[i].bottom)
indexTemp = i;
}
if (!nNumberOfTools) indexTemp = 0;
if (indexTemp == -1) return;
insertOneTool(indexTemp, strFileName);
////////////////////////////////////////////////////////////////////////////////////
m_static_drawning.SetRedraw();
}
void CServiceEditDlg::OnClickedStaticSensorsPicture()
{
// TODO: Add your control notification handler code here
////判断是哪一个Tool////////////////////////////////////////////////////////////////////////////////
CPoint m_mouse, m_mouseScreen;
GetCursorPos(&m_mouse);
m_mouseScreen = m_mouse;
m_static_drawning.ScreenToClient(&m_mouse);
int indexTemp = -1;
for (int i = 0; i < nNumberOfTools; i++){
//strTemp1.Format(TEXT(" rectArray[i] = (%d, %d, %d, %d)"), rectArray[i].left, rectArray[i].top, rectArray[i].right, rectArray[i].bottom);
if (m_mouse.x > rectArray[i].left && m_mouse.x < rectArray[i].right)
if (m_mouse.y > rectArray[i].top && m_mouse.y < rectArray[i].bottom)
indexTemp = i;
}
if (!nNumberOfTools) return;
if (indexTemp < 0) return;
if (m_bHavingDash){
// 工作区(用户区)右键菜单:
CMenu menu;
menu.LoadMenu(IDR_MENU_DRAWINGPOP);
CMenu* pPopUp = menu.GetSubMenu(0);//获取菜单的第一个子菜单,序号为0 IDR_MENU_DRAWINGPOP IDR_MAINFRAME
nDraingSelected = indexTemp; //注意:以下语句会引起刷新
pPopUp->TrackPopupMenu(TPM_LEFTALIGN | TPM_TOPALIGN, m_mouseScreen.x, m_mouseScreen.y, this);
return;
}
// 外边框位虚线
CPen *pOldPen, pen(PS_DASH, 1, RGB(255, 0, 0)); // PS_SOLID PS_DASHDOT PS_DASH
pOldPen = pDC->SelectObject(&pen);
CBrush * pOldBrush = NULL;
CBrush * pBrush = CBrush::FromHandle((HBRUSH)GetStockObject(NULL_BRUSH)); //背景透明效果
pOldBrush = pDC->SelectObject(pBrush);
pDC->Rectangle(&rectArray[indexTemp]);
pDC->SelectObject(pOldPen);
pDC->SelectObject(pOldBrush);
pen.DeleteObject();
m_bHavingDash = TRUE;
SetTimer((UINT)m_hWnd, (UINT)1800, NULL);
}
void CServiceEditDlg::OnTimer(UINT_PTR nIDEvent)
{
//::InvalidateRect(m_static_drawning.GetSafeHwnd(), NULL, TRUE);
SendMessage(WM_PAINT, 0, 0);
m_bHavingDash = FALSE;
KillTimer(nIDEvent);
CDialogEx::OnTimer(nIDEvent);
}
void CServiceEditDlg::OnRButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
m_statinc_test.SetWindowTextW(TEXT(“OnRButtonDown”));
CDialogEx::OnRButtonDown(nFlags, point);
}
void CServiceEditDlg::OnDeleteDelete()
{
// TODO: Add your command handler code here
deleteOneTool(nDraingSelected);
}
//////////////////////////////////////////////////////////////////
//// ServiceEditDlg.h
//////////////////////////////////////////////////////////////////
#pragma once
#include “afxcmn.h”
#include “afxwin.h”
// CServiceEditDlg 对话框
#define DRAG_DELAY 50
class CServiceEditDlg : public CDialogEx
{
DECLARE_DYNAMIC(CServiceEditDlg)
public:
CServiceEditDlg(CWnd* pParent = NULL); // 标准构造函数
virtual ~CServiceEditDlg();
// 对话框数据
#ifdef AFX_DESIGN_TIME
enum { IDD = IDD_DIALOG_SERVICE};
#endif
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV 支持
void initListControl_Services();
BOOL m_bDragging = FALSE; // 标识是否正在拖动过程中
BOOL m_bHavingDash = FALSE; // 标识是否有虚框
CImageList* m_pImageList; // 拖动时显示的图象列表
HTREEITEM m_hTreeItemDrag ; // 被拖动的标签
int nDraingSelected = 0;
void initSketchViewAll() ;
CToolTipCtrl m_pToolTipCtrl ;
void initTreeView_Data() ;
void drawingSketchHeaderText( ) ;
void drawingSketchGrid() ;
void initOtherControlData();
bool showGraph_JpgGifBmpWmf(CDC* &pDC, CString strPath, int x, int y, int width, int height, COLORREF colorBack);
void drawToolSketchAll(CString strStetchFileName, CRect rect);
void readToolSketchFile(CString strStetchFileName, CRect &rect);
void drawTextAlignCenter(int x, int y, int width, int height, CString strText);
void drawAllSketchData();
void insertOneTool(int indexTemp, CString strFileName);
void deleteOneTool(int indexTemp);
// 视图边界nGridMargin, 图片(仪器串)所占视区宽度的比例nSkectchWidthRatio,视图表头高度nHeaderHeight, 图片(仪器串)所占视区宽度nSkectchWidth,图片(仪器串)参数所占视区宽度nDataColWidth
int nGridMargin = 2, nSkectchWidthRatio = 20, nHeaderHeight = 40, nSkectchWidth, nDataColWidth;
// 图片(仪器串)在视区开始位置X:nSkectchX,图片(仪器串)在视区开始位置Y:nSkectchY, 图片(仪器串)参数在视区位置X:nDataColFirstX,图片(仪器串)参数在视区位置Y:nDataColFirstY,
int nSkectchX = 8, nSkectchY = 8, nDataColFirstX = 0, nDataColFirstY = 0;
CString strFileNameArray[7];
double dSensorLengthArray[7], dSumLength = 0.00, dSumWeight = 0.00 ;
// 图片位置按图片顺序自动计算得到
CRect rectArray[7];
// 图片数量
int nNumberOfTools = 0, nIndex = 0;
//CString DesciptionArray[7] = { TEXT("RBT201"), TEXT("RBT131"), TEXT("RBT111"), TEXT("RBTA01"), TEXT("RBT10F"), TEXT("RBT10X"), TEXT("RBT10M") };
//CString LengthArray[7] = { TEXT("0.52"), TEXT("19.02"), TEXT("9.52"), TEXT("9.02"), TEXT("4.52"), TEXT("3.52"), TEXT("9.79") };
//CString ZeroLengthArray[7] = { TEXT("RBTWAVE3:8.77"), TEXT("RBTOTHER:5.32"), TEXT("RBTWAVE3:10.11"), TEXT("RBTWAVE5:3.99"), TEXT("RBTOTHER:4.07"), TEXT("RBTWAVE5:2.82"), TEXT("RBTWAVE5:5.15") };
//CString ODArray[7] = { TEXT("5.87"), TEXT("3.67"), TEXT("8.88"), TEXT("9.12"), TEXT("0.07"), TEXT("8.03"), TEXT("3.81") };
//CString WeightArray[7] = { TEXT("21.52"), TEXT("49.02"), TEXT("9.06"), TEXT("11.20"), TEXT("5.02"), TEXT("2.42"), TEXT("0.79") };
CString DesciptionArray[7] ;
CString LengthArray[7] ;
CString ZeroLengthArray[7];
CString ODArray[7];
CString WeightArray[7] ;
// 视图表头文字样式,颜色
CFont fontHeaderText, fontBodyTextNormal, *pFontBodyTextNormal, fontBodyTextSamll;
COLORREF colorHeaderText, colorBodyText;
// 视图背景色
COLORREF colorSkectchBackGround ;
DECLARE_MESSAGE_MAP()
public:
virtual BOOL OnInitDialog();
BOOL OnToolTipNotify(UINT id, NMHDR * pTTTStruct, LRESULT * pResult);
CTreeCtrl m_tree_tools;
CListCtrl m_list_services;
CEdit m_eidt_service_name;
CStatic m_static_drawning;
CDC* pDC;
CRect rectView;
afx_msg void OnBnClickedSave();
afx_msg void OnBnClickedButtonFind();
afx_msg void OnTvnSelchangedTreeTools(NMHDR *pNMHDR, LRESULT *pResult);
afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
afx_msg void OnMouseMove(UINT nFlags, CPoint point);
afx_msg void OnTimer(UINT_PTR nIDEvent);
afx_msg void OnBnClickedButtonAdd();
afx_msg void OnPaint();
afx_msg void OnLvnItemchangedListServices(NMHDR *pNMHDR, LRESULT *pResult);
afx_msg void OnBegindragTreeTools(NMHDR *pNMHDR, LRESULT *pResult);
CStatic m_statinc_test;
afx_msg void OnClickedStaticSensorsPicture();
afx_msg void OnRButtonDown(UINT nFlags, CPoint point);
afx_msg void OnDeleteDelete();
};