⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 balloonhelp.cpp

📁 实时监控
💻 CPP
📖 第 1 页 / 共 4 页
字号:
   ON_WM_TIMER()   ON_WM_NCHITTEST()   ON_WM_MOUSEMOVE()   ON_WM_DESTROY()
   ON_WM_CLOSE()
   ON_WM_SHOWWINDOW()
   ON_MESSAGE(WM_PRINT, OnPrint)
   ON_MESSAGE(WM_PRINTCLIENT, OnPrintClient)
END_MESSAGE_MAP()void CBalloonHelp::OnShowWindow(BOOL bShow, UINT)
{
   if ( NULL != m_fnAnimateWindow )
   {
      if ( bShow && !(m_unOptions&unDISABLE_FADEIN) )
         m_fnAnimateWindow( m_hWnd, 200, AW_BLEND);
      else if ( !bShow && !(m_unOptions&unDISABLE_FADEOUT) )
         m_fnAnimateWindow( m_hWnd, 200, AW_HIDE | AW_BLEND );
   }
}
// Erase client area of balloonBOOL CBalloonHelp::OnEraseBkgnd(CDC* pDC) {   CRect rect;   GetClientRect(&rect);   pDC->FillSolidRect(&rect, m_crBackground);   return TRUE;}// draw balloon client area (title & contents)void CBalloonHelp::OnPaint() {   CPaintDC dc(this); // device context for painting   DrawClientArea(&dc);}// draw balloon shape & bordervoid CBalloonHelp::OnNcPaint() {
   CWindowDC dc(this);   DrawNonClientArea(&dc);}// draw the window into the specified device contextLRESULT CBalloonHelp::OnPrint(WPARAM wParam, LPARAM lParam)
{
   CDC* pDC = CDC::FromHandle((HDC)wParam);
   if ( lParam & PRF_NONCLIENT  ) 
      DrawNonClientArea(pDC);
   return Default();
}

// draw the client area into the specified device contextLRESULT CBalloonHelp::OnPrintClient(WPARAM wParam, LPARAM lParam)
{
   CDC* pDC = CDC::FromHandle((HDC)wParam);
   if ( lParam & PRF_ERASEBKGND ) 
      SendMessage( WM_ERASEBKGND, wParam );
   if ( lParam & PRF_CLIENT ) 
      DrawClientArea(pDC);
   return 0;
}
// Close button handlervoid CBalloonHelp::OnLButtonDown(UINT, CPoint point) {   if (m_unOptions & unSHOW_CLOSE_BUTTON)   {      CRect rect;      GetClientRect(&rect);      rect.left = rect.right-::GetSystemMetrics(SM_CXSIZE);      rect.bottom = rect.top+::GetSystemMetrics(SM_CYSIZE);      if ( rect.PtInRect(point) )      {         m_uCloseState |= DFCS_PUSHED;         SetCapture();         OnMouseMove(0, point);      }   }}// Close button handler,// URL handlervoid CBalloonHelp::OnLButtonUp(UINT, CPoint point) {   if ( (m_unOptions & unSHOW_CLOSE_BUTTON) && (m_uCloseState & DFCS_PUSHED) )   {      ReleaseCapture();      m_uCloseState &= ~DFCS_PUSHED;      CRect rect;      GetClientRect(&rect);      rect.left = rect.right-::GetSystemMetrics(SM_CXSIZE);      rect.bottom = rect.top+::GetSystemMetrics(SM_CYSIZE);      if ( rect.PtInRect(point) )         HideBalloon();   }   else if ( !m_strURL.IsEmpty() )   {      CRect rect;      GetClientRect(&rect);      if ( rect.PtInRect(point) )      {         ::ShellExecute(NULL, NULL, m_strURL, NULL, NULL, SW_SHOWNORMAL);         HideBalloon();      }   }}//// Ensure WM_MOUSEMOVE messages are sent for the entire window//UINT CBalloonHelp::OnNcHitTest(CPoint){   return HTCLIENT;}//// do mouse tracking://   Tracking for close button;//void CBalloonHelp::OnMouseMove(UINT, CPoint point){   if (m_unOptions & unSHOW_CLOSE_BUTTON)   {      CRect rect;      GetClientRect(&rect);      rect.left = rect.right-::GetSystemMetrics(SM_CXSIZE);      rect.bottom = rect.top+::GetSystemMetrics(SM_CYSIZE);      CClientDC dc(this);      UINT uState = DFCS_CAPTIONCLOSE;      BOOL bPushed = m_uCloseState&DFCS_PUSHED;      m_uCloseState &= ~DFCS_PUSHED;      if ( rect.PtInRect(point) )      {         uState |= DFCS_HOT;         if ( bPushed )            uState |= DFCS_PUSHED;      }      else      {         uState |= DFCS_FLAT;      }      if ( uState != m_uCloseState )      {         dc.DrawFrameControl(&rect, DFC_CAPTION, uState);         m_uCloseState = uState;      }      if ( bPushed )         m_uCloseState |= DFCS_PUSHED;   }}// Ensures client area is the correct size relative to window size,// presearves client contents if possible when moving.void CBalloonHelp::OnNcCalcSize(BOOL bCalcValidRects, NCCALCSIZE_PARAMS FAR* lpncsp) {
   // nTIP_MARGIN pixel margin on all sides
   ::InflateRect(&lpncsp->rgrc[0], -nTIP_MARGIN,-nTIP_MARGIN);

   // nTIP_TAIL pixel "tail" on side closest to anchor
   switch ( GetBalloonQuadrant() )
   {
   case BQ_TOPRIGHT:
   case BQ_TOPLEFT:
      lpncsp->rgrc[0].top += nTIP_TAIL;
      break;
   case BQ_BOTTOMRIGHT:
   case BQ_BOTTOMLEFT:
      lpncsp->rgrc[0].bottom -= nTIP_TAIL;
      break;
   }

   // sanity: ensure rect does not have negative size
   if ( lpncsp->rgrc[0].right < lpncsp->rgrc[0].left )
      lpncsp->rgrc[0].right = lpncsp->rgrc[0].left;
   if ( lpncsp->rgrc[0].bottom < lpncsp->rgrc[0].top )
      lpncsp->rgrc[0].bottom = lpncsp->rgrc[0].top;

   if ( bCalcValidRects )
   {
      // determine if client position has changed relative to the window position
      // if so, don't bother presearving anything.
      if ( !::EqualRect(&lpncsp->rgrc[0], &lpncsp->rgrc[2]) )
      {
         ::SetRectEmpty(&lpncsp->rgrc[2]);
      }
   }
}// handle kill timervoid CBalloonHelp::OnTimer(UINT nIDEvent) {   // really shouldn't be any other timers firing, but might as well make sure   if ( nIDEvent == ID_TIMER_CLOSE )   {      KillTimer(m_unTimerClose);      HideBalloon();   }}// Called as the window is being destroyed.  Completes destruction after removing keyboard hook.void CBalloonHelp::OnDestroy()
{
   // remove hooks
   RemoveMouseHook();
   RemoveKeyboardHook();
   RemoveCallWndRetHook();

   // destroy
   CWnd::OnDestroy();
}

// close the balloon, performing any set transition effect.
void CBalloonHelp::OnClose()
{
   HideBalloon();
}

// Called after window has been destroyed.  Destroys the object if option is set.
void CBalloonHelp::PostNcDestroy()
{
   CWnd::PostNcDestroy();
  
   // free object if requested
   // be careful with this one :D
   if ( m_unOptions & unDELETE_THIS_ON_CLOSE )
      delete this;
}

// Keyboard hook: used to implement the unCLOSE_ON_KEYPRESS option
LRESULT CBalloonHelp::KeyboardHookProc( int code, WPARAM wParam, LPARAM lParam){
   // Skip if the key was released or if it's a repeat
   // Bit 31:  Specifies the transition state. The value is 0 if the key  
   //       is being pressed and 1 if it is being released (see MSDN).
   if ( code>=0 && !(lParam&0x80000000) && NULL != m_hWnd )
   {
      PostMessage(WM_CLOSE);
   }
   return ::CallNextHookEx(m_hKeyboardHook, code, wParam, lParam);
}

// Mouse hook: used to implement un-obtrusive mouse tracking
LRESULT CBalloonHelp::MouseHookProc(int code, WPARAM wParam, LPARAM lParam)
{
   if (code>=0 && NULL != m_hWnd )
   {
      switch ( (UINT)wParam )
      {
      case WM_NCMOUSEMOVE:
      case WM_MOUSEMOVE:
         if ((m_unOptions & unCLOSE_ON_MOUSE_MOVE))
         {
            CPoint pt;
            ::GetCursorPos(&pt);
            if ((abs(pt.x-m_ptMouseOrig.x) > m_nMouseMoveTolerance || abs(pt.y-m_ptMouseOrig.y) > m_nMouseMoveTolerance) )
               PostMessage(WM_CLOSE);
         }
         break;
      case WM_NCLBUTTONDOWN:
      case WM_LBUTTONDOWN:
         if ((m_unOptions & unCLOSE_ON_LBUTTON_DOWN))
            PostMessage(WM_CLOSE);
         break;
      case WM_NCMBUTTONDOWN:
      case WM_MBUTTONDOWN:
         if ((m_unOptions & unCLOSE_ON_MBUTTON_DOWN))
            PostMessage(WM_CLOSE);
         break;
      case WM_NCRBUTTONDOWN:
      case WM_RBUTTONDOWN:
         if ((m_unOptions& unCLOSE_ON_RBUTTON_DOWN))
            PostMessage(WM_CLOSE);
         break;
      case WM_NCLBUTTONUP:
      case WM_LBUTTONUP:
         if ((m_unOptions & unCLOSE_ON_LBUTTON_UP))
            PostMessage(WM_CLOSE);
         break;
      case WM_NCMBUTTONUP:
      case WM_MBUTTONUP:
         if ((m_unOptions & unCLOSE_ON_MBUTTON_UP))
            PostMessage(WM_CLOSE);
         break;
      case WM_NCRBUTTONUP:
      case WM_RBUTTONUP:
         if ((m_unOptions & unCLOSE_ON_RBUTTON_UP))
            PostMessage(WM_CLOSE);
         break;
      }
   }
   return ::CallNextHookEx(m_hMouseHook, code, wParam, lParam);
}

// Window Return hook: used to implement window following
LRESULT CBalloonHelp::CallWndRetProc(int code, WPARAM wParam, LPARAM lParam)
{
   if (code>=0 && NULL != m_hWnd )
   {
      CWPRETSTRUCT* pcwpr = (CWPRETSTRUCT*)lParam;
      if ( WM_MOVE == pcwpr->message && pcwpr->hwnd == m_hwndAnchor )
         PositionWindow();
   }

   return ::CallNextHookEx(m_hCallWndRetHook, code, wParam, lParam);
}

#include "../Resource.h"
void info_balloon(LPCTSTR content, DWORD timeout)
{
	balloon_txt* b = new balloon_txt;
	b->title.LoadString(IDS_INFO);
	b->content = content;
	b->icon = IDI_INFORMATION;
	b->timeout = timeout;
	b->options = CBalloonHelp::unSHOW_INNER_SHADOW;

	if( timeout == -1 )
	{
		b->timeout = 0;	
		b->options |= CBalloonHelp::unCLOSE_ON_LBUTTON_DOWN;
	}
	AfxGetMainWnd()->PostMessage(WM_BALLOON, (WPARAM)b);
}

void warning_balloon(LPCTSTR content, DWORD timeout)
{
	balloon_txt* b = new balloon_txt;
	b->title.LoadString(IDS_WARNING);
	b->content = content;
	b->icon = IDI_WARNING;
	b->timeout = timeout;

	b->options = CBalloonHelp::unSHOW_INNER_SHADOW;

	if( timeout == -1 )
	{
		b->timeout = 0;	
		b->options |= CBalloonHelp::unCLOSE_ON_LBUTTON_DOWN;
	}
	AfxGetMainWnd()->PostMessage(WM_BALLOON, (WPARAM)b);
}

void info_balloon(UINT c, DWORD timeout)
{
	CString str;
	if( str.LoadString(c) )
		info_balloon(str, timeout);
}

void warning_balloon(UINT c, DWORD timeout)
{
	CString str;
	if(str.LoadString(c))
		warning_balloon(str, timeout);

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -