📄 popupwnd.cpp
字号:
//活动子窗口指针
// m_map.GetStartPosition;
if(m_hCurWnd==NULL)//当前工具窗口为空
{
if(m_map.Lookup(lpMsg->hwnd,(void*&)pText))//鼠标在工具窗口内
{
//设置初始化Timer和m_hCurWnd
m_hCurWnd=lpMsg->hwnd;
SetTimer(TIMER_INITIAL,m_nTimeInitial,NULL);
m_bTimerInitial=TRUE;
}
}
else
{
if(m_hCurWnd==lpMsg->hwnd)
{
//在当前工具窗口内移动
if(!m_bTimerInitial)//还没有显示
{
//则重置初始化Timer
KillTimer(TIMER_INITIAL);
SetTimer(TIMER_INITIAL,m_nTimeInitial,NULL);
}
//否则已显示则不做任何动作
}
else
{
//移到当前工具窗口外则重置
Hide();
m_hCurWnd=NULL;
}
}
}
break;
default:
break;
}
ptLast=lpMsg->pt;
}
void CPopupWnd::Hide()
{
CMDIFrameWnd * nowframe = (CMDIFrameWnd*)AfxGetApp()->m_pMainWnd;
CMDIChildWnd *nowchild = nowframe->MDIGetActive();
// CChildFrame *nowchild = (CChildFrame *)nowframe->MDIGetActive();
CCrystalTextView *m_pchildview = (CCrystalTextView *)nowchild->GetActiveView();
CCrystalEditView *m_pchildeditview = (CCrystalEditView *)nowchild->GetActiveView();
CPoint mpt;
GetCursorPos(&mpt);
CRect m_rect(0,0,0,0);
GetWindowRect(m_rect);
if(
m_rect.PtInRect(mpt))
return;
if(m_bTimerInitial)//OnTimer(1)还未执行
{
KillTimer(TIMER_INITIAL);
m_bTimerInitial=FALSE;
}
if(IsWindowVisible())
{
ShowWindow(SW_HIDE);
KillTimer(TIMER_AUTOPOP);
m_bTimerPop=FALSE;//m_bTimerPop为True必在OnTimer(TIMER_INITIAL)之后
//窗口必然可见
}
}
void CPopupWnd::SetDelayTime(UINT nDelay)
{
m_nTimeAutoPop=nDelay;
m_nTimeReShow=nDelay;
m_nTimeInitial=nDelay;
}
void CPopupWnd::SetDelayTime(DWORD dwDuration, int iTime)
{
switch(dwDuration)
{
case TTDT_AUTOPOP:
m_nTimeAutoPop=iTime;
break;
case TTDT_RESHOW:
m_nTimeReShow=iTime;
break;
case TTDT_INITIAL:
m_nTimeInitial=iTime;
break;
}
}
BOOL CPopupWnd::AddTool(CWnd *pWnd, LPCTSTR lpszText)
{
char *pText;
if(m_map.Lookup(pWnd->GetSafeHwnd(),(void*&)pText))
{
m_map.RemoveKey(pWnd->GetSafeHwnd());
if(pText!=LPSTR_TEXTCALLBACK)
delete []pText;
}
if(lpszText==LPSTR_TEXTCALLBACK)
{
m_map.SetAt(pWnd->GetSafeHwnd(),(void*)lpszText);
}
else
{
pText=new char[strlen(lpszText)+1];
ASSERT(pText);
strcpy(pText,lpszText);
m_map.SetAt(pWnd->GetSafeHwnd(),pText);
}
return TRUE;
}
int CPopupWnd::GetDelayTime(DWORD dwDuration) const
{
switch(dwDuration)
{
case TTDT_AUTOPOP:
return m_nTimeAutoPop;
break;
case TTDT_RESHOW:
return m_nTimeReShow;
break;
case TTDT_INITIAL:
return m_nTimeInitial;
default:
return 0;
break;
}
}
void CPopupWnd::OnDestroy()
{
if(m_bTimerInitial)
KillTimer(TIMER_INITIAL);
if(m_bTimerPop)
KillTimer(TIMER_AUTOPOP);
char *pText;
HWND hwnd;
for (POSITION pos = m_map.GetStartPosition(); pos != NULL;)
{
m_map.GetNextAssoc(pos,(void*&)hwnd,(void*&)pText);
if(pText!=LPSTR_TEXTCALLBACK)
{
delete []pText;
}
}
m_map.RemoveAll();
CWnd::OnDestroy();
// TODO: Add your message handler code here
}
void CPopupWnd::DelTool(CWnd *pWnd)
{
char *pText;
if(m_map.Lookup(pWnd->GetSafeHwnd(),(void*&)pText))
{
m_map.RemoveKey(pWnd->GetSafeHwnd());
if(pText!=LPSTR_TEXTCALLBACK)
delete []pText;
if(pWnd->GetSafeHwnd()==m_hCurWnd)
Hide();
}
}
void CPopupWnd::SetTipTextColor(COLORREF clr)
{
m_crText=clr;
}
void CPopupWnd::SetTipBkColor(COLORREF clr)
{
m_crBg=clr;
}
COLORREF CPopupWnd::GetTipBkColor() const
{
return m_crBg;
}
COLORREF CPopupWnd::GetTipTextColor() const
{
return m_crText;
}
void CPopupWnd::SetMargin(LPRECT lprc)
{
m_rcMargin.CopyRect(lprc);
}
void CPopupWnd::GetMargin(LPRECT lprc) const
{
::CopyRect(lprc,&m_rcMargin);
}
CSize CPopupWnd::GetMessageSize()
{
CDC cDC;
CSize cSize, cSizeFinal;
CString csTemp;
int nLen, nLenTrim, nLines;
cDC.CreateIC(_T("DISPLAY"), NULL, NULL, NULL);
// === these two functions only work for simple strings w/o line breaks ===
// cSize = cDC.GetTextExtent( m_csMessage ); // get a size for the string
// cSize = cDC.GetOutputTextExtent( m_csMessage );
// === this routine will calculate a rectangle for a formatted display ===
nLines = 0;
nLenTrim = 0;
cSizeFinal.cx = 0;
cSizeFinal.cy = 0;
csTemp = m_csMessage;
do
{
nLen = csTemp.Find( "\r\n" );
if( nLen >= 0 )
{
csTemp = csTemp.Left( nLen );
nLenTrim += ( nLen + 2 );
nLines++;
cSize = cDC.GetTextExtent( csTemp );
csTemp = m_csMessage.Right( m_csMessage.GetLength() - nLenTrim );
}
else
{
nLines++;
cSize = cDC.GetTextExtent( csTemp );
}
cSizeFinal.cy = cSize.cy; // all heights should be the same
cSizeFinal.cx = max( cSizeFinal.cx, cSize.cx ); // keep the longest string
}
while( nLen >= 0 );
cSizeFinal.cy = cSizeFinal.cy * nLines;
return cSizeFinal;
}
void CPopupWnd::OnTimer(UINT nIDEvent)
{
// Shutdown();
TRACE("\nnIDEvent:%d",nIDEvent);
switch(nIDEvent)
{
case TIMER_INITIAL:
Show();
KillTimer(TIMER_INITIAL);
m_bTimerInitial=FALSE;
SetTimer(TIMER_AUTOPOP,m_nTimeAutoPop,NULL);
m_bTimerPop=TRUE;
break;
case TIMER_AUTOPOP:
Hide();
break;
}
CWnd::OnTimer(nIDEvent);
}
void CPopupWnd::Shutdown()
{/*
if( m_nIDTimer )
KillTimer( m_nIDTimer );
PostMessage( WM_CLOSE );
ReleaseCapture();*/
}
void CPopupWnd::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
{
CWnd::OnKeyDown(nChar, nRepCnt, nFlags);
}
void CPopupWnd::OnSysKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
{
CWnd::OnSysKeyDown(nChar, nRepCnt, nFlags);
}
void CPopupWnd::OnLButtonDown(UINT nFlags, CPoint point)
{
CWnd::OnLButtonDown(nFlags, point);
}
void CPopupWnd::OnNcLButtonDown(UINT nHitTest, CPoint point)
{
CWnd::OnNcLButtonDown(nHitTest, point);
}
void CPopupWnd::OnMButtonDown(UINT nFlags, CPoint point)
{
CWnd::OnMButtonDown(nFlags, point);
}
void CPopupWnd::OnNcMButtonDown(UINT nHitTest, CPoint point)
{
CWnd::OnNcMButtonDown(nHitTest, point);
}
void CPopupWnd::OnRButtonDown(UINT nFlags, CPoint point)
{
CWnd::OnRButtonDown(nFlags, point);
}
void CPopupWnd::OnNcRButtonDown(UINT nHitTest, CPoint point)
{
CWnd::OnNcRButtonDown(nHitTest, point);
}
void CPopupWnd::OnCmdTip()
{
// ShellExecute(NULL, _T("open"), "http://xiaoyueer.top263.net", NULL,NULL, SW_SHOWNORMAL);
}
/////////////////////////////////////////////////////////////////////////////
// PopupWnd
/////////////////////////////////////////////////////////////////////////////
// CPopupWnd message handlers
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -