// 设置Tooltip void CControlBase::SetTooltip(CControlBase* pControl, CString strTooltip, CRect rect, BOOL bControlWidth, int nTipWidth) { // 如果找到了父对话框,则调用对话框的设置Tooltip函数 CDlgBase* pDlg = GetParentDialog(); if(pDlg) { pDlg->SetTooltip(pControl, strTooltip, rect, bControlWidth, nTipWidth); return; } // 如果找到父Popup窗口,则调用Popup窗口的设置Tooltip函数 // 如果找到插件HostWnd,则调用插件HostWnd接口的设置Tooltip函数 IDuiHostWnd* pIDuiHostWnd = GetParentIDuiHostWnd(); if(pIDuiHostWnd) { int _nTipWidth = nTipWidth; if(bControlWidth) { _nTipWidth = pControl->GetRect().Width(); } pIDuiHostWnd->SetTooltip(pControl->GetID(), strTooltip, rect, _nTipWidth); return; } }
// 从XML设置plugin属性,加载界面插件文件动态库 HRESULT CDuiPanel::OnAttributePlugin(const CString& strValue, BOOL bLoading) { if (strValue.IsEmpty()) return E_FAIL; HINSTANCE hPluginHandle = NULL; LPVOID pPluginObj = NULL; //if(DuiSystem::Instance()->LoadPluginFile(strValue, CEncodingUtil::AnsiToUnicode(IID_IDuiPluginPanel), hPluginHandle, pPluginObj)) if(DuiSystem::Instance()->LoadPluginFile(strValue, IID_IDuiPluginPanel, hPluginHandle, pPluginObj)) { m_strPluginFile = strValue; m_hPluginHandle = hPluginHandle; m_pDuiPluginObject = (IDuiPluginPanel*)pPluginObj; // 初始化界面插件 UINT nIDTemplate = 0; HWND hWnd = NULL; CDlgBase* pParentDlg = GetParentDialog(); if(pParentDlg != NULL) { nIDTemplate = pParentDlg->GetIDTemplate(); hWnd = pParentDlg->GetSafeHwnd(); } //m_pDuiPluginObject->OnInit(nIDTemplate, hWnd, CEncodingUtil::UnicodeToAnsi(GetName()), m_rc); m_pDuiPluginObject->OnInit(nIDTemplate, hWnd, GetName(), m_rc, &m_xDuiPanel); } return bLoading?S_FALSE:S_OK; }
// 清除指定名字的子控件 BOOL CControlBase::RemoveControl(CString strControlName, UINT uControlID) { vector<CControlBase*>::iterator it; for(it=m_vecControl.begin();it!=m_vecControl.end();++it) { CControlBase* pControlBase = *it; if (pControlBase && pControlBase->IsThisObject(uControlID, strControlName)) { // 如果是焦点控件,则需要先将焦点设置为空 if(pControlBase->IsFocusControl()) { CDlgBase* pDlg = GetParentDialog(FALSE); if(pDlg) { pDlg->SetFocusControlPtr(NULL); } } m_vecControl.erase(it); delete pControlBase; return TRUE; } } return FALSE; }
// 清除指定的子控件 BOOL CControlBase::RemoveControl(CControlBase* pControl) { vector<CControlBase*>::iterator it; for(it=m_vecControl.begin();it!=m_vecControl.end();++it) { CControlBase* pControlBase = *it; if (pControlBase == pControl) { // 如果是焦点控件,则需要先将焦点设置为空 if(IsFocusControl()) { CDlgBase* pDlg = GetParentDialog(FALSE); if(pDlg) { pDlg->SetFocusControlPtr(NULL); } } m_vecControl.erase(it); delete pControlBase; return TRUE; } } return FALSE; }
// 设置当前焦点控件 void CDuiWkeView::SetCurrentFocusControl(BOOL bFocus) { CDlgBase* pDlg = GetParentDialog(FALSE); if(pDlg) { pDlg->SetFocusControl(bFocus ? this : NULL); } }
// 鼠标左键按下事件处理 BOOL CControlBase::OnLButtonDown(UINT nFlags, CPoint point) { if(!m_bIsVisible || !m_bRresponse) return false; // 保存原始的鼠标位置,并进行位置变换 CPoint oldPoint = point; OnMousePointChange(point); m_bMouseDown = m_rc.PtInRect(point); // 查找鼠标是否在某个内部控件位置,如果是的话就更新当前子控件(按照反向顺序查找,因为定义在后面的控件是优先级更高的) // 找到第一个符合条件的就结束查找 for (int i = m_vecControl.size()-1; i >= 0; i--) { CControlBase * pControlBase = m_vecControl.at(i); if (pControlBase && pControlBase->PtInRect(point)) { if(pControlBase->GetVisible() && !pControlBase->GetDisable() && pControlBase->GetRresponse()) { m_pControl = pControlBase; break; } } } if(m_pControl != NULL) { // 如果是控件内置滚动条子控件,则不进行位置变换,因为滚动条位置是不需要变换的 UINT uControlID = m_pControl->GetControlID(); if((SCROLL_V == uControlID) || (SCROLL_H == uControlID)) { point = oldPoint; } if(m_pControl->OnLButtonDown(nFlags, point)) { return true; } } else { // 切换对话框中的当前焦点控件(暂不处理Popup窗口的切换) CDlgBase* pDlg = GetParentDialog(FALSE); if(pDlg) { pDlg->SetFocusControl(this); } // 发送鼠标左键按下DUI消息 if(m_bDuiMsgMouseLDown && m_rc.PtInRect(point)) { SendMessage(MSG_MOUSE_LDOWN, (WPARAM)nFlags, (LPARAM)(&point)); } return OnControlLButtonDown(nFlags, point); } return false; }
// 清除Tooltip void CDuiTabCtrl::ClearTabTooltip() { CDlgBase* pDlg = GetParentDialog(); if(pDlg) { pDlg->ClearTooltip(); m_nTipItem = -1; } }
// 判断当前是否在主线程 void CControlBase::TestMainThread() { // 调用所在对话框的测试函数 CDlgBase* pDlg = GetParentDialog(); if(pDlg) { pDlg->TestMainThread(); } }
// 清除Tooltip void CDuiListCtrl::ClearRowTooltip() { CDlgBase* pDlg = GetParentDialog(); if(pDlg) { pDlg->ClearTooltip(); m_nTipRow = -1; m_nTipVirtualTop = 0; } }
// 清除Tooltip void CDuiGridCtrl::ClearGridTooltip() { CDlgBase* pDlg = GetParentDialog(); if(pDlg) { pDlg->ClearTooltip(); m_nTipRow = -1; m_nTipItem = -1; m_nTipVirtualTop = 0; } }
// 设置焦点 BOOL CControlBase::SetWindowFocus() { CDlgBase* pDlg = GetParentDialog(); if(pDlg) { pDlg->SetFocus(); return TRUE; } return FALSE; }
// 判断当前控件是否焦点控件 BOOL CControlBase::IsFocusControl() { CDlgBase* pDlg = GetParentDialog(FALSE); if(pDlg) { if(pDlg->GetFocusControl() == this) { return TRUE; } } return FALSE; }
// 清空Combo下拉项 void CDuiComboBox::ClearItems() { m_vecItem.clear(); // 关闭popuplist窗口 CDlgBase* pDlg = GetParentDialog(); if(pDlg) { m_buttonState = enBSNormal; m_EditState = enBSNormal; InvalidateRect(GetRect()); pDlg->CloseDlgPopup(); m_pPopupList = NULL; } }
// 刷新父控件下面所有同一个组的RadioButton控件的状态 BOOL CMenuItem::ResetGroupCheck() { CDuiObject* pParentObj = GetParent(); if(pParentObj == NULL) { return FALSE; } vector<CControlBase*>* pvecControl = NULL; if(pParentObj->IsClass(_T("dlg"))) { CDlgBase* pDlg = static_cast<CDlgBase*>(pParentObj); pvecControl = pDlg->GetControls(); }else if(pParentObj->IsClass(_T("popup"))) { CDlgPopup* pDlg = static_cast<CDlgPopup*>(pParentObj); pvecControl = pDlg->GetControls(); }else { CControlBase* pControlBase = static_cast<CControlBase*>(pParentObj); pvecControl = pControlBase->GetControls(); } if(pvecControl == NULL) { return FALSE; } for(int i=0; i<(int)pvecControl->size(); i++) { CControlBase* pControlBase = pvecControl->at(i); if(pControlBase->IsClass(CMenuItem::GetClassName()) && pControlBase->GetVisible() && !pControlBase->GetDisable()) { CMenuItem* pControl = static_cast<CMenuItem*>(pControlBase); if((pControl->GetGroupName() == m_strGroupName) && (pControl != this)) { // 重置控件状态 pControl->SetControlCheck(FALSE); } } } return TRUE; }
// 获取所在Radio组选择的控件的值 CString CMenuItem::GetGroupValue() { CDuiObject* pParentObj = GetParent(); if(pParentObj == NULL) { return _T(""); } vector<CControlBase*>* pvecControl = NULL; if(pParentObj->IsClass(_T("dlg"))) { CDlgBase* pDlg = static_cast<CDlgBase*>(pParentObj); pvecControl = pDlg->GetControls(); }else if(pParentObj->IsClass(_T("popup"))) { CDlgPopup* pDlg = static_cast<CDlgPopup*>(pParentObj); pvecControl = pDlg->GetControls(); }else { CControlBase* pControlBase = static_cast<CControlBase*>(pParentObj); pvecControl = pControlBase->GetControls(); } if(pvecControl == NULL) { return _T(""); } for(int i=0; i<(int)pvecControl->size(); i++) { CControlBase* pControlBase = pvecControl->at(i); if(pControlBase->IsClass(CMenuItem::GetClassName()) && pControlBase->GetVisible() && !pControlBase->GetDisable()) { CMenuItem* pControl = static_cast<CMenuItem*>(pControlBase); if((pControl->GetGroupName() == m_strGroupName) && pControl->GetCheck()) { return pControl->GetValue(); } } } return _T(""); }
// 设置Tab页签的Tooltip void CDuiTabCtrl::SetTabTooltip(int nItem, CString strTooltip) { CDlgBase* pDlg = GetParentDialog(); if(pDlg && (m_nTipItem != nItem)) { TabItemInfo* pTabInfo = GetItemInfo(nItem); BOOL bHaveDivTip = ((pTabInfo->pControl != NULL) && !pTabInfo->pControl->GetTooltip().IsEmpty()); if(pTabInfo && (pTabInfo->bNeedTextTip || bHaveDivTip)) { CRect rc = pTabInfo->rc; pDlg->SetTooltip(this, strTooltip, rc, TRUE); }else { pDlg->ClearTooltip(); } m_nTipItem = nItem; } }
// 鼠标左键事件处理 BOOL CControlBase::OnLButtonDown(UINT nFlags, CPoint point) { if(!m_bIsVisible || !m_bRresponse) return false; OnMousePointChange(point); m_bMouseDown = m_rc.PtInRect(point); // 查找鼠标是否在某个内部控件位置,如果是的话就更新当前子控件 for (size_t i = 0; i < m_vecControl.size(); i++) { CControlBase * pControlBase = m_vecControl.at(i); if (pControlBase && pControlBase->PtInRect(point)) { if(pControlBase->GetVisible() && !pControlBase->GetDisable() && pControlBase->GetRresponse()) { m_pControl = pControlBase; } } } if(m_pControl != NULL) { if(m_pControl->OnLButtonDown(nFlags, point)) { return true; } } else { // 切换对话框中的当前焦点控件(暂不处理Popup窗口的切换) CDlgBase* pDlg = GetParentDialog(FALSE); if(pDlg) { pDlg->SetFocusControl(this); } return OnControlLButtonDown(nFlags, point); } return false; }
// 清除Tooltip void CControlBase::ClearTooltip() { // 如果找到了父对话框,则调用对话框的清除Tooltip函数 CDlgBase* pDlg = GetParentDialog(); if(pDlg) { pDlg->ClearTooltip(); return; } // 如果找到父Popup窗口,则调用Popup窗口的清除Tooltip函数 // 如果找到插件HostWnd,则调用插件HostWnd接口的清除Tooltip函数 IDuiHostWnd* pIDuiHostWnd = GetParentIDuiHostWnd(); if(pIDuiHostWnd) { pIDuiHostWnd->ClearTooltip(); return; } }
// 获取当前Tooltip控件ID int CControlBase::GetTooltipCtrlID() { // 如果找到了父对话框,则调用对话框的获取Tooltip控件ID函数 CDlgBase* pDlg = GetParentDialog(); if(pDlg) { return pDlg->GetTooltipCtrlID(); } // 如果找到父Popup窗口,则调用Popup窗口的获取Tooltip控件ID函数 // 如果找到插件HostWnd,则调用插件HostWnd接口的获取Tooltip控件ID函数 IDuiHostWnd* pIDuiHostWnd = GetParentIDuiHostWnd(); if(pIDuiHostWnd) { return pIDuiHostWnd->GetTooltipCtrlID(); } return 0; }
// 设置当前Tooltip控件ID void CControlBase::SetTooltipCtrlID(int nTooltipCtrlID) { // 如果找到了父对话框,则调用对话框的设置Tooltip控件ID函数 CDlgBase* pDlg = GetParentDialog(); if(pDlg) { pDlg->SetTooltipCtrlID(nTooltipCtrlID); return; } // 如果找到父Popup窗口,则调用Popup窗口的设置Tooltip控件ID函数 // 如果找到插件HostWnd,则调用插件HostWnd接口的设置Tooltip控件ID函数 IDuiHostWnd* pIDuiHostWnd = GetParentIDuiHostWnd(); if(pIDuiHostWnd) { pIDuiHostWnd->SetTooltipCtrlID(nTooltipCtrlID); return; } }
// 设置行的Tooltip void CDuiListCtrl::SetRowTooltip(int nRow, CString strTooltip) { if((nRow < 0) || (nRow >= (int)m_vecRowInfo.size())) { return; } CDlgBase* pDlg = GetParentDialog(); if(pDlg && ((m_nTipRow != nRow) || (m_nTipVirtualTop != m_nVirtualTop))) { ListRowInfo &rowInfo = m_vecRowInfo.at(nRow); if(rowInfo.bNeedTitleTip || rowInfo.bNeedContentTip) { CRect rc = rowInfo.rcRow; rc.OffsetRect(m_rc.left, m_rc.top-m_nVirtualTop); pDlg->SetTooltip(this, strTooltip, rc, TRUE); } m_nTipRow = nRow; m_nTipVirtualTop = m_nVirtualTop; } }
// 清除Tooltip void CDuiGridCtrl::ClearGridTooltip() { CDlgBase* pDlg = GetParentDialog(); if(pDlg) { pDlg->ClearTooltip(); m_nTipRow = -1; m_nTipItem = -1; m_nTipVirtualTop = 0; return; } IDuiHostWnd* pIDuiHostWnd = GetParentIDuiHostWnd(); if(pIDuiHostWnd) { pIDuiHostWnd->ClearTooltip(); m_nTipRow = -1; m_nTipItem = -1; m_nTipVirtualTop = 0; return; } }
__forceinline HINSTANCE getInst() const { return pDialog->GetInst(); }
// 鼠标移动事件处理 BOOL CControlBase::OnMouseMove(UINT nFlags, CPoint point) { if(!m_bIsVisible || !m_bRresponse) return false; OnMousePointChange(point); BOOL bRresponse = false; if(m_pControl) { if((m_pControl->PtInRect(point) && m_pControl->OnCheckMouseResponse(nFlags, point)) || m_bMouseDown) { if(m_pControl->OnMouseMove(nFlags, point)) { return true; } return false; } } CControlBase * pOldControl = m_pControl; m_pControl = NULL; if(!m_strTooltip.IsEmpty() && PtInRect(point) && OnCheckMouseResponse(nFlags, point)) { // 如果当前控件有Tooltip,则添加一个Tooltip CDlgBase* pDlg = GetParentDialog(); if(pDlg && (pDlg->GetTooltipCtrlID() != GetID())) { pDlg->SetTooltip(this, m_strTooltip, m_rc); pDlg->SetTooltipCtrlID(GetID()); } } bRresponse = OnControlMouseMove(nFlags, point); if(!m_bMouseDown) { for (size_t i = 0; i < m_vecControl.size(); i++) { CControlBase * pControlBase = m_vecControl.at(i); if (pControlBase) { if(pControlBase->OnMouseMove(nFlags, point)) { if(pControlBase->PtInRect(point)) { m_pControl = pControlBase; } bRresponse = true; } } } if (pOldControl) { bRresponse = true; } if (m_pControl) { bRresponse = true; } } return bRresponse; }
// 消息处理 LRESULT CDuiComboBox::OnMessage(UINT uID, UINT uMsg, WPARAM wParam, LPARAM lParam) { if((BUTTOM == wParam) && (BUTTOM_DOWN == lParam) && (m_pPopupList == NULL)) // 鼠标点击了编辑框的下拉按钮 { CPopupList *pPopupList = new CPopupList; m_pPopupList = pPopupList; pPopupList->SetParent(this); // 将PopupList的父控件指向combobox pPopupList->SetWidth(m_nWidth); if(m_nResourceIDHeadBitmap != 0) { pPopupList->SetHeadBitmap(m_nResourceIDHeadBitmap); }else if(!m_strImageHeadBitmap.IsEmpty()) { pPopupList->SetHeadBitmap(m_strImageHeadBitmap); } if(m_nResourceIDDeleteBitmap != 0) { pPopupList->SetCloseBitmap(m_nResourceIDDeleteBitmap); }else if(!m_strImageDeleteBitmap.IsEmpty()) { pPopupList->SetCloseBitmap(m_strImageDeleteBitmap); } CRect rcClient = GetRect(); rcClient.top = rcClient.bottom; CDlgBase* pDlg = GetParentDialog(); if(pDlg) { pDlg->OpenDlgPopup(pPopupList, rcClient, GetID()); } // 必须窗口创建之后才能加载内容 for (size_t i = 0; i < m_vecItem.size(); i++) { ComboListItem* pItem = &(m_vecItem.at(i)); pPopupList->AddItem(pItem->strName, pItem->strDesc, pItem->strValue, pItem->nResourceID, pItem->strImageFile); } if(!m_strXmlFile.IsEmpty()) { pPopupList->LoadXmlFile(m_strXmlFile); } // 设置选择的项 SetComboValue(m_strComboValue); }else if((SELECT_ITEM == wParam) && m_pPopupList) // 下拉框选择 { CString strName; m_pPopupList->GetItemName(lParam, strName); m_pPopupList->GetItemValue(lParam, m_strComboValue); SetTitle(strName); CDlgBase* pDlg = GetParentDialog(); if(pDlg) { m_buttonState = enBSNormal; m_EditState = enBSNormal; InvalidateRect(GetRect()); pDlg->CloseDlgPopup(); m_pPopupList = NULL; } }else if((DELETE_ITEM == wParam) && m_pPopupList) // 删除下拉框列表项 { // 如果设置了删除按钮图片,才可以进行删除 if(!m_strImageDeleteBitmap.IsEmpty() || (m_nResourceIDDeleteBitmap != 0)) { m_pPopupList->DeleteItem(lParam); } } return __super::OnMessage(uID, uMsg, wParam, lParam); }
// 消息处理 LRESULT CControlBase::OnMessage(UINT uID, UINT uMsg, WPARAM wParam, LPARAM lParam) { if(m_bTaskMsg) { // 如果设置了任务方式发消息的属性,则添加一个任务消息 CString strControlName = GetName(); CString strAction = GetAction(); CDlgBase* pParentDlg = GetParentDialog(); DuiSystem::Instance()->AddDuiActionTask(uID, uMsg, wParam, lParam, strControlName, strAction, pParentDlg); return 0; } if(m_strAction.Find(_T("dlg:")) == 0) // 动作:打开一个对话框,有内存泄漏,改为通过DuiSystem创建和管理 { if(uMsg == BUTTOM_UP) // 鼠标放开事件才处理 { CString strXmlFile = m_strAction; strXmlFile.Delete(0, 4); DuiSystem::ShowDuiDialog(strXmlFile, GetParentDialog()); } }else if(m_strAction.Find(_T("popup:")) == 0) // 动作:打开一个Popup对话框 { if(uMsg == BUTTOM_UP) // 鼠标放开事件才处理 { /*UINT nIDTemplate = 0; CDlgBase* pParentDlg = GetParentDialog(); if(pParentDlg != NULL) { nIDTemplate = pParentDlg->GetIDTemplate(); } CDlgPopup* pPopup = new CDlgPopup; pPopup->SetParent(this); CString strXmlFile = m_strAction; strXmlFile.Delete(0, 6); pPopup->SetXmlFile(_T("xml:") +strXmlFile ); CRect rc = pControlBase->GetRect(); rc.OffsetRect(-95, rc.Height()); ClientToScreen(&rc); pPopup->Create(this, rc, WM_SKIN); pPopup->ShowWindow(SW_SHOW);*/ } }else if(m_strAction.Find(_T("menu:")) == 0) // 动作:打开一个菜单 { CDuiMenu *pDuiMenu = new CDuiMenu( DuiSystem::GetDefaultFont(), 12); // 可以考虑改为通过DuiSystem创建和管理 pDuiMenu->SetParent(this); CPoint point; CRect rc = GetRect(); point.SetPoint(rc.left + rc.Width() / 2, rc.bottom); CDlgBase* pParentDlg = GetParentDialog(); if(pParentDlg != NULL) { pParentDlg->ClientToScreen(&point); } CString strXmlFile = m_strAction; strXmlFile.Delete(0, 5); pDuiMenu->LoadXmlFile(strXmlFile, pParentDlg, point, WM_DUI_MENU); pDuiMenu->ShowWindow(SW_SHOW); }else if(m_strAction.Find(_T("link:")) == 0) // 动作:打开一个页面链接 { if(uMsg == BUTTOM_UP) // 鼠标放开事件才处理 { CString strLink = m_strAction; strLink.Delete(0, 5); if(!strLink.IsEmpty()) { ShellExecute(NULL, TEXT("open"), strLink, NULL,NULL,SW_NORMAL); } } }else if(m_strAction.Find(_T("run:")) == 0) // 动作:执行一个进程 { if(uMsg == BUTTOM_UP) // 鼠标放开事件才处理 { CString strProcess = m_strAction; strProcess.Delete(0, 4); strProcess.MakeLower(); if(!strProcess.IsEmpty()) { strProcess.MakeLower(); BOOL bForceAdmin = FALSE; if(strProcess.Find(_T("admin@")) == 0) { bForceAdmin = TRUE; strProcess.Delete(0, 6); } BOOL bWaitProcess = FALSE; if(strProcess.Find(_T("&")) == (strProcess.GetLength()-1)) { bWaitProcess = TRUE; strProcess.Delete(strProcess.GetLength()-1, 1); } if(strProcess.Find(_T(".exe")) == -1) { strProcess = DuiSystem::Instance()->GetString(CEncodingUtil::UnicodeToAnsi(strProcess)); } if(strProcess.Find(_T("{platpath}")) == 0) { strProcess.Delete(0, 10); strProcess = DuiSystem::GetExePath() + strProcess; } CString strCmdLine = _T(""); int nPos = strProcess.Find(_T("|")); if(nPos != -1) { strCmdLine = strProcess; strCmdLine.Delete(0, nPos+1); strProcess = strProcess.Left(nPos); } DuiSystem::PathCanonicalize(strProcess); // 路径标准化 DuiSystem::ExecuteProcess(strProcess, strCmdLine, bForceAdmin, bWaitProcess); } } }else if(m_strAction.Find(ACTION_CLOSE_WINDOW) == 0) // 动作:关闭指定的窗口 { if(uMsg == BUTTOM_UP) // 鼠标放开事件才处理 { CString strWndName = m_strAction; strWndName.Delete(0, 13); if(!strWndName.IsEmpty()) { CDlgBase* pDlg = DuiSystem::Instance()->GetDuiDialog(strWndName); if(pDlg != NULL) { //pDlg->DoClose(); pDlg->PostMessage(WM_QUIT, 0, 0); } } } }else { // 首先判断如果是几个默认按钮,则直接做相应的处理 CDlgBase* pParentDlg = GetParentDialog(); if(IsThisObject(BT_OK, NAME_BT_OK)) { if((BUTTOM_UP == uMsg) && (pParentDlg != NULL)) { pParentDlg->DoOK(); } }else if(IsThisObject(BT_CANCEL, NAME_BT_CANCEL)) { if((BUTTOM_UP == uMsg) && (pParentDlg != NULL)) { pParentDlg->DoCancel(); } }else if(IsThisObject(BT_YES, NAME_BT_YES)) { if((BUTTOM_UP == uMsg) && (pParentDlg != NULL)) { pParentDlg->DoYes(); } }else if(IsThisObject(BT_NO, NAME_BT_NO)) { if((BUTTOM_UP == uMsg) && (pParentDlg != NULL)) { pParentDlg->DoNo(); } }else { // 调用控件的DUI事件处理对象 CallDuiHandler(uMsg, wParam, lParam); } } return 0; }
BOOL CDuiTabCtrl::OnControlLButtonDown(UINT nFlags, CPoint point) { if(m_nHoverItem != -1) { TabItemInfo &itemInfo = m_vecItemInfo.at(m_nHoverItem); if(itemInfo.rc.PtInRect(point)) { if(m_nDownItem != m_nHoverItem) { int nDownItem = m_nHoverItem; if(!itemInfo.strAction.IsEmpty()) { // 如果action非空,则执行动作 DuiSystem::AddDuiActionTask(GetID(), MSG_BUTTON_UP, nDownItem, 0, GetName(), itemInfo.strAction, GetParent()); } if(itemInfo.bOutLink) // 外部链接 { m_nHoverItem = -1; SendMessage(MSG_BUTTON_DOWN, nDownItem, 0); }else { m_nOldItem = m_nDownItem; // 保存切换前的页面索引,用于切换动画 m_nDownItem = m_nHoverItem; m_nHoverItem = -1; // 删除旧的Tooltip CDlgBase* pDlg = GetParentDialog(); if(pDlg) { pDlg->ClearTooltip(); } // 点击事件消息 SendMessage(MSG_BUTTON_DOWN, m_nDownItem, 0); // 只显示当前活动的tab页对应的Panel对象,其他页面的Panel对象都隐藏 for(size_t i = 0; i < m_vecItemInfo.size(); i++) { TabItemInfo &itemInfo = m_vecItemInfo.at(i); if(itemInfo.pControl != NULL) { if(i == m_nDownItem) { itemInfo.pControl->SetVisible(TRUE); SetWindowFocus(); }else { itemInfo.pControl->SetVisible(FALSE); } } // 如果启用了动画,则启动切换动画定时器 if(m_bAnimateChangeTab) { m_nCurXPos = 0; m_bRunTime = true; } } } UpdateControl(); return true; } } } return false; }
BOOL CDuiVisionDemoApp::InitInstance() { CWinApp::InitInstance(); AfxEnableControlContainer(); // TODO: 应适当修改该字符串, // 例如修改为公司或组织名 SetRegistryKey(_T("Blueant")); // 初始化DuiVision界面库,可以指定语言,dwLangID为0表示自动判断当前语言 // 1116是应用程序ID,每个DUI应用程序应该使用不同的ID,ID主要用于进程间通信传递命令行时候区分应用 DWORD dwLangID = 0; new DuiSystem(m_hInstance, dwLangID, _T("DuiVisionDemo.ui"), 1116, IDD_DUIVISIONDEMO_DIALOG, _T("")); // 检查是否已经有进程在运行 CString strAppMutex = DuiSystem::Instance()->GetConfig(_T("appMutex")); // 从配置文件中获取互斥量名字 if(!strAppMutex.IsEmpty()) { ::CreateMutex(NULL,TRUE, _T("Global\\") + strAppMutex); if(ERROR_ALREADY_EXISTS == GetLastError() || ERROR_ACCESS_DENIED == GetLastError()) { // 读取命令行参数,如果不需要处理命令行可以直接退出 CString strCmd = L""; if(__argc > 0) { strCmd = __targv[0]; DuiSystem::LogEvent(LOG_LEVEL_DEBUG, L"Command line:%s", strCmd); } // 发送进程间消息(lParam为1表示不显示界面,信息参数传递命令行参数) DuiSystem::Instance()->SendInterprocessMessage(0, DuiSystem::Instance()->GetAppID(), 1, strCmd); return FALSE; // Here we quit this application } } // 创建主窗口 CDlgBase* pMainDlg = DuiSystem::CreateDuiDialog(_T("dlg_main"), NULL, _T(""), TRUE); // 给主窗口注册事件处理对象 CDuiHandlerMain* pHandler = new CDuiHandlerMain(); pHandler->SetDialog(pMainDlg); DuiSystem::RegisterHandler(pMainDlg, pHandler); // 初始化提示信息窗口 DuiSystem::Instance()->CreateNotifyMsgBox(_T("dlg_notifymsg")); // 按照非模式对话框创建主窗口,可以默认隐藏 pMainDlg->Create(pMainDlg->GetIDTemplate(), NULL); //pMainDlg->ShowWindow(SW_HIDE); INT_PTR nResponse = pMainDlg->RunModalLoop(); // 如果是按照模式对话框运行主窗口,只要改为如下代码就可以 //INT_PTR nResponse = pMainDlg->DoModal(); // 释放DuiVision界面库的资源 DuiSystem::Release(); // 由于对话框已关闭,所以将返回 FALSE 以便退出应用程序, // 而不是启动应用程序的消息泵。 return FALSE; }
__forceinline HWND getHwnd() const { return pDialog->GetHwnd(); }