| ¶Ô±ÈÐÂÎļþ |
| | |
| | | // CPanelAttributes.cpp: å®ç°æä»¶ |
| | | // |
| | | |
| | | #include "stdafx.h" |
| | | #include "Servo.h" |
| | | #include "CPanelAttributes.h" |
| | | #include "afxdialogex.h" |
| | | #include "common.h" |
| | | #include "VerticalLine.h" |
| | | |
| | | |
| | | // CPanelAttributes å¯¹è¯æ¡ |
| | | |
| | | IMPLEMENT_DYNAMIC(CPanelAttributes, CDialogEx) |
| | | |
| | | CPanelAttributes::CPanelAttributes(CWnd* pParent /*=nullptr*/) |
| | | : CDialogEx(IDD_PANEL_ATTRIBUTES, pParent) |
| | | { |
| | | m_crBkgnd = PANEL_ATTRIBUTES_BACKGROUND_COLOR; |
| | | m_hbrBkgnd = nullptr; |
| | | m_nPanelWidth = 188; |
| | | } |
| | | |
| | | CPanelAttributes::~CPanelAttributes() |
| | | { |
| | | } |
| | | |
| | | void CPanelAttributes::DoDataExchange(CDataExchange* pDX) |
| | | { |
| | | CDialogEx::DoDataExchange(pDX); |
| | | DDX_Control(pDX, IDC_MFCPROPERTYGRID1, m_gridCtrl); |
| | | } |
| | | |
| | | |
| | | BEGIN_MESSAGE_MAP(CPanelAttributes, CDialogEx) |
| | | ON_WM_CTLCOLOR() |
| | | ON_WM_DESTROY() |
| | | ON_WM_SIZE() |
| | | ON_NOTIFY(BYVERTICALLINE_MOVEX, IDC_LINE1, &CPanelAttributes::OnVLineMoveX) |
| | | ON_BN_CLICKED(IDC_BUTTON_CLOSE, &CPanelAttributes::OnBnClickedButtonClose) |
| | | END_MESSAGE_MAP() |
| | | |
| | | |
| | | // CPanelAttributes æ¶æ¯å¤çç¨åº |
| | | |
| | | |
| | | int CPanelAttributes::getPanelWidth() |
| | | { |
| | | return m_nPanelWidth; |
| | | } |
| | | |
| | | void CPanelAttributes::loadDataFromStep(SERVO::CStep* pStep) |
| | | { |
| | | // å
æ¸
ç©ºææ |
| | | m_gridCtrl.RemoveAll(); |
| | | |
| | | |
| | | // å è½½æ°æ® |
| | | SetDlgItemText(IDC_LABEL_TITLE, pStep->getName().c_str()); |
| | | SERVO::CAttributeVector attrubutes; |
| | | pStep->getAttributeVector(attrubutes); |
| | | unsigned int nSize = attrubutes.size(); |
| | | for (unsigned int i = 0; i < nSize; i++) { |
| | | SERVO::CAttribute* pAttribute = attrubutes.getAttribute(i); |
| | | CMFCPropertyGridProperty* pProperty = new CMFCPropertyGridProperty( |
| | | pAttribute->getName().c_str(), |
| | | pAttribute->getValue().c_str(), |
| | | pAttribute->getDescription().c_str()); |
| | | pProperty->AllowEdit(TRUE); |
| | | m_gridCtrl.AddProperty(pProperty); |
| | | } |
| | | } |
| | | |
| | | BOOL CPanelAttributes::OnInitDialog() |
| | | { |
| | | CDialogEx::OnInitDialog(); |
| | | |
| | | |
| | | // å
³éæé® |
| | | CString strIcon1; |
| | | strIcon1.Format(_T("%s\\Res\\panel_close_24_b.ico"), theApp.m_strAppDir); |
| | | HICON hIcon1 = (HICON)::LoadImage(AfxGetInstanceHandle(), |
| | | strIcon1, IMAGE_ICON, 24, 24, |
| | | LR_LOADFROMFILE | LR_DEFAULTCOLOR | LR_CREATEDIBSECTION | LR_DEFAULTSIZE); |
| | | m_btnClose.SubclassDlgItem(IDC_BUTTON_CLOSE, this); |
| | | m_btnClose.SetIcon(hIcon1, hIcon1, 24); |
| | | m_btnClose.SetFaceColor(m_crBkgnd); |
| | | m_btnClose.SetFrameColor(m_crBkgnd); |
| | | m_btnClose.SetFrameColor(BS_HOVER, RGB(218, 218, 218)); |
| | | m_btnClose.SetFrameColor(BS_PRESS, RGB(168, 168, 168)); |
| | | |
| | | CVerticalLine* pLine1 = CVerticalLine::Hook(GetDlgItem(IDC_LINE1)->GetSafeHwnd()); |
| | | pLine1->SetBkgndColor(RGB(225, 225, 225)); |
| | | pLine1->SetLineColor(RGB(198, 198, 198)); |
| | | pLine1->EnableResize(); |
| | | |
| | | |
| | | // 读å颿¿å®½ |
| | | CString strIniFile; |
| | | strIniFile.Format(_T("%s\\%s.ini"), (LPTSTR)(LPCTSTR)theApp.m_strAppDir, (LPTSTR)(LPCTSTR)theApp.m_strAppFile); |
| | | m_nPanelWidth = GetPrivateProfileInt(_T("App"), _T("AttributesPanelWidth"), |
| | | int((double)GetSystemMetrics(SM_CXSCREEN) * 0.25), (LPTSTR)(LPCTSTR)strIniFile); |
| | | |
| | | |
| | | |
| | | |
| | | return TRUE; // return TRUE unless you set the focus to a control |
| | | // å¼å¸¸: OCX 屿§é¡µåºè¿å FALSE |
| | | } |
| | | |
| | | |
| | | HBRUSH CPanelAttributes::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) |
| | | { |
| | | HBRUSH hbr = CDialogEx::OnCtlColor(pDC, pWnd, nCtlColor); |
| | | |
| | | if (nCtlColor == CTLCOLOR_STATIC) { |
| | | pDC->SetBkColor(m_crBkgnd); |
| | | pDC->SetTextColor(RGB(0, 0, 0)); |
| | | } |
| | | |
| | | if (m_hbrBkgnd == nullptr) { |
| | | m_hbrBkgnd = CreateSolidBrush(m_crBkgnd); |
| | | } |
| | | |
| | | return m_hbrBkgnd; |
| | | } |
| | | |
| | | void CPanelAttributes::OnDestroy() |
| | | { |
| | | CDialogEx::OnDestroy(); |
| | | |
| | | if (m_hbrBkgnd != nullptr) { |
| | | ::DeleteObject(m_hbrBkgnd); |
| | | } |
| | | } |
| | | |
| | | void CPanelAttributes::OnSize(UINT nType, int cx, int cy) |
| | | { |
| | | CDialogEx::OnSize(nType, cx, cy); |
| | | if (GetDlgItem(IDC_LINE1) == nullptr) return; |
| | | |
| | | CWnd* pItem; |
| | | CRect rcClient, rcItem; |
| | | |
| | | GetClientRect(&rcClient); |
| | | pItem = GetDlgItem(IDC_LINE1); |
| | | pItem->MoveWindow(rcClient.right - 3, 0, 3, rcClient.Height()); |
| | | |
| | | int x2 = rcClient.right - 6; |
| | | int y = 3; |
| | | pItem = GetDlgItem(IDC_BUTTON_CLOSE); |
| | | pItem->GetWindowRect(&rcItem); |
| | | pItem->MoveWindow(x2 - rcItem.Width(), y, rcItem.Width(), rcItem.Height()); |
| | | x2 -= rcItem.Width(); |
| | | x2 -= 3; |
| | | |
| | | pItem = GetDlgItem(IDC_LABEL_TITLE); |
| | | pItem->GetWindowRect(&rcItem); |
| | | pItem->MoveWindow(5, y, x2 - 5, rcItem.Height()); |
| | | y += rcItem.Height(); |
| | | y += 8; |
| | | |
| | | |
| | | GetDlgItem(IDC_MFCPROPERTYGRID1)->MoveWindow(5, y, rcClient.Width() - 13, rcClient.Height() - 3 - y); |
| | | } |
| | | |
| | | #define ATTRIBUTES_PANEL_MIN_WIDTH 88 |
| | | #define ATTRIBUTES_PANEL_MAX_WIDTH 588 |
| | | void CPanelAttributes::OnVLineMoveX(NMHDR* nmhdr, LRESULT* result) |
| | | { |
| | | BYVERTICALLINE_NMHDR* pNmhdrex = (BYVERTICALLINE_NMHDR*)nmhdr; |
| | | int x = pNmhdrex->dwData; |
| | | m_nPanelWidth += x; |
| | | m_nPanelWidth = max(m_nPanelWidth, ATTRIBUTES_PANEL_MIN_WIDTH); |
| | | m_nPanelWidth = min(m_nPanelWidth, ATTRIBUTES_PANEL_MAX_WIDTH); |
| | | GetParent()->SendMessage(ID_MSG_PANEL_RESIZE, m_nPanelWidth, 0); |
| | | |
| | | CString strIniFile, strValue; |
| | | strIniFile.Format(_T("%s\\%s.ini"), (LPTSTR)(LPCTSTR)theApp.m_strAppDir, (LPTSTR)(LPCTSTR)theApp.m_strAppFile); |
| | | strValue.Format(_T("%d"), m_nPanelWidth); |
| | | WritePrivateProfileString(_T("App"), _T("AttributesPanelWidth"), |
| | | (LPTSTR)(LPCTSTR)strValue, (LPTSTR)(LPCTSTR)strIniFile); |
| | | OnSize(0, 0, 0); |
| | | |
| | | *result = 0; |
| | | } |
| | | |
| | | void CPanelAttributes::OnBnClickedButtonClose() |
| | | { |
| | | ShowWindow(SW_HIDE); |
| | | GetParent()->SendMessage(ID_MSG_PANEL_RESIZE, m_nPanelWidth, 0); |
| | | } |