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

📄 tipwnd.cpp

📁 vc编写的精灵显示源码
💻 CPP
字号:
// TipWnd.cpp: implementation of the CTipWnd class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "..\resource.h"
#include "TipWnd.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

#pragma warning ( disable : 4244 )
#define IDT_AUTOHIDE 999
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CTipWnd::CTipWnd()
{
	m_aAtom = NULL;
	m_nMargin = 5;
}

CTipWnd::~CTipWnd()
{

}

BEGIN_MESSAGE_MAP(CTipWnd, CWnd)
	//{{AFX_MSG_MAP(CTipWnd)
	ON_WM_PAINT()
	ON_WM_LBUTTONDOWN()
	ON_WM_TIMER()
	//}}AFX_MSG_MAP
	ON_WM_DESTROY()
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CInputBalloon message handlers

BOOL CTipWnd::Create(LPCTSTR strTitle, pTip Tip, long lExtra, long lExtra2, CWnd* pParent) 
{
	// Register
	WNDCLASSEX wcx; 

    // Fill in the window class structure with parameters 
    // that describe the tip window. 

	//if ( !pParent ) pParent = AfxGetMainWnd();

	wcx.cbSize = sizeof(wcx);                 // size of structure 
    wcx.style = CS_SAVEBITS;				  // save screen under
    wcx.lpfnWndProc = AfxWndProc;             // points to window procedure 
    wcx.cbClsExtra = 0;                       // no extra class memory 
    wcx.cbWndExtra = 0;                       // no extra window memory 
    wcx.hInstance = AfxGetInstanceHandle();   // handle to instance 
    wcx.hIcon = NULL;                         // no app. icon 
    wcx.hCursor = LoadCursor(NULL, IDC_ARROW); // predefined arrow 
    wcx.hbrBackground = ::GetSysColorBrush(COLOR_WINDOW);                 // no background brush 
    wcx.lpszMenuName =  NULL;                 // no menu resource 
    wcx.lpszClassName = "TipWnd";   // name of window class 
    wcx.hIconSm = NULL;                      // no small class icon
	
    // Register the window class. 
    if ( !m_aAtom )
	{
		m_aAtom = RegisterClassEx(&wcx);
		if ( !m_aAtom )
		{
			// Try to get atom
			if ( !GetClassInfoEx( AfxGetInstanceHandle(), _T("TipWnd"), &wcx ) )
				return FALSE;
		}
			
	}

	if ( !CreateEx( WS_EX_PALETTEWINDOW, _T("TipWnd"), strTitle, WS_POPUP, CRect(100,100, 200, 200), pParent, 0, NULL) )
      return FALSE;

	// Now rest of the initialization
	////////////////////////////////////
	// Store callback pointer && data
	this->Tip = Tip;
	m_lExtra = lExtra;
	m_lExtra2 = lExtra2;

	// Load tip bitmap
	
	if ( !m_cBitmap.LoadBitmap( IDB_TIP ) ) 
	{
		DestroyWindow();
		return FALSE;
	}
	
	// Create Rgn
	m_cBitmap.GetBitmap( &m_bitmapInfo );
	
	// Resize window
	SetWindowPos( &wndTopMost, 0, 0, m_bitmapInfo.bmWidth, m_bitmapInfo.bmHeight, SWP_NOMOVE );

	CRgn rgn;
	m_dcBitmap.CreateCompatibleDC ( NULL ) ;
	m_dcBitmap.SelectObject( m_cBitmap );


	for (int i=0; i< m_bitmapInfo.bmWidth; i++)
	{
		for (int j=0; j< m_bitmapInfo.bmHeight; j++)
		{
			COLORREF crPixel = m_dcBitmap.GetPixel( i, j );
			if ( crPixel != RGB (255, 0, 255) )
			{
				rgn.DeleteObject();
				rgn.CreateRectRgn( i, j, i+1, j+1 );
				if ( m_rgnTip.m_hObject )
					m_rgnTip.CombineRgn( &m_rgnTip, &rgn, RGN_OR );
				else
					m_rgnTip.CreateRectRgn( i, j, i, j );
			}
		}
	}

	SetWindowRgn( m_rgnTip, FALSE );

	return TRUE;
}

void CTipWnd::ShowTip( BOOL bShow, long lMaxTime )
{
	HWND hWnd = ::GetFocus();
	ShowWindow( bShow ? SW_SHOW : SW_HIDE );
	if ( bShow && lMaxTime != INFINITE )
		SetTimer( IDT_AUTOHIDE, lMaxTime * 1000, NULL );
	else
		KillTimer( IDT_AUTOHIDE );

	::SetFocus ( hWnd );
}

void CTipWnd::OnPaint() 
{
	CPaintDC dc(this); // device context for painting
	CWnd::OnPaint();

	dc.BitBlt(0, 0, m_bitmapInfo.bmWidth, m_bitmapInfo.bmHeight, &m_dcBitmap, 0, 0, SRCCOPY);
}

void CTipWnd::Move ( RECT rectParent )
{
	int x, y;

	x = rectParent.left + ( rectParent.right - rectParent.left - m_bitmapInfo.bmWidth ) * 0.5;
	y = rectParent.top - m_bitmapInfo.bmHeight - m_nMargin;

	SetWindowPos( &wndTopMost , x, y, m_bitmapInfo.bmWidth, m_bitmapInfo.bmHeight, SWP_NOSIZE );
}


void CTipWnd::OnLButtonDown(UINT nFlags, CPoint point) 
{
	ShowWindow( SW_HIDE );
	if (Tip)
		Tip( TIP_CLK, m_lExtra, m_lExtra2 );
	
	CWnd::OnLButtonDown( nFlags, point );
}

void CTipWnd::OnTimer(UINT nIDEvent) 
{
	if ( IDT_AUTOHIDE )
	{
		ShowTip( FALSE );
		if ( Tip )
			Tip( TIP_AUTOHIDE, m_lExtra, m_lExtra2 );
	}
}

⌨️ 快捷键说明

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