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

📄 taskbarmsgwnd.cpp

📁 vc++6.0开发网络典型应用实例导航 1. 本光盘提供了本书中所有的实例源程序文件。 2. 附录文件夹下是Winsock 函数参考以及错误码列表
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/*******************************************************************************
File:        TaskBarMsgWnd.cpp

Description: This file contains the module for creating a status bar message 
             window like MSN messenger

Created: Oct 13, 2001
Author:  Prateek Kaul
e-mail:  kaulpr@yahoo.com

Compiler with version number : Visual C++ 6.0

********************************************************************************/


/*********************************************************
	Original function comments removed from this file
	to make it easier to work with
	(more comments than code :P)
**********************************************************/

#include "stdafx.h"
#include "Resource.h"
#include "TaskBarMsgWnd.h"
#include "ContactView.h"
#include "Contact.h"
#include "Netmsg.h"

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

BEGIN_MESSAGE_MAP(CTaskBarMsgWnd, CFrameWnd)
    ON_WM_SIZE()
    ON_WM_CREATE()
    ON_WM_MOUSEMOVE()
    ON_WM_TIMER()
    ON_WM_SETCURSOR()
    ON_WM_DESTROY()
    ON_WM_PAINT()
    ON_WM_LBUTTONDOWN()
    ON_MESSAGE(WM_MOUSELEAVE, OnMouseLeave)
    ON_MESSAGE(WM_MOUSEHOVER, OnMouseHover)
	ON_WM_CTLCOLOR()
END_MESSAGE_MAP()

CTaskBarMsgWnd::CTaskBarMsgWnd(
                      CString strMsg, 
                      unsigned int nWndWidth,
                      unsigned int nWndHeight,
                      unsigned int nMsgTimeOut,         
                      unsigned int nMsgWndCreationDelay, 
                      CRect rectMsgRect,
                      COLORREF clrBox,
                      COLORREF clrText,
				   CContactView *ContactView,
				   CContact *With,
				   CTaskBarMsgWnd *pLast //pass a pointer to the last one so we know where it was to stack it.

                  ) : m_strMsg(strMsg), m_rectMsgRect(rectMsgRect)
{
    m_nWndWidth  = nWndWidth;
    m_nWndHeight = nWndHeight;

    m_nMsgTimeOut          = nMsgTimeOut;
    m_nMsgWndCreationDelay = nMsgWndCreationDelay;

    m_bMouseOverWnd = FALSE;
	View = ContactView;
	Contact = With;
	Last = pLast;
    m_hCursor = NULL;

    m_clrBox  = clrBox;
    m_clrText = clrText;
	Top = 0;
	bmBack = (HBITMAP)::LoadImage(0, "frame.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
	icBack = (HICON)AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

CTaskBarMsgWnd::~CTaskBarMsgWnd()
{
//	::FreeResource(m_icBack);
}

void CTaskBarMsgWnd::PopWndForLeftTaskBar()
{
    // Create a specific new window class
    HCURSOR hCursor = ::LoadCursor(NULL, IDC_APPSTARTING);
    HBRUSH hBrush   = ::CreateSolidBrush(m_clrBox); 

	CString strWndClass = ::AfxRegisterWndClass(
                                CS_DBLCLKS,
                                hCursor,
                                hBrush
                            );

    CRect t_rect(0, 0, 0, 0);
    Create(strWndClass, NULL, WS_VISIBLE | WS_OVERLAPPEDWINDOW, t_rect);
    
    CRect rectDesktopWithoutTaskbar;   // The desktop area 

    // Get the desktop area
    ::SystemParametersInfo(SPI_GETWORKAREA, 0, &rectDesktopWithoutTaskbar, 0);
    
	//// Added - Matthew Millman ////
    // Calculate the actual width of the Window and its position
	if (Last)
	{
		m_nWndLeft   = rectDesktopWithoutTaskbar.left;
		m_nWndTop    = rectDesktopWithoutTaskbar.bottom - (rectDesktopWithoutTaskbar.bottom - Last->Top) - m_nWndHeight;
		m_nWndRight  = m_nWndLeft + m_nWndWidth;
		m_nWndBottom = m_nWndTop + m_nWndHeight;
	}
	else
	{
		m_nWndLeft   = rectDesktopWithoutTaskbar.left;
		m_nWndTop    = rectDesktopWithoutTaskbar.bottom - m_nWndHeight;
		m_nWndRight  = m_nWndLeft + m_nWndWidth;
		m_nWndBottom = m_nWndTop + m_nWndHeight;
	}
	
	Top = m_nWndTop;

	/////////////////////////////////

	m_nWndSize = 0; // The height of window is zero before showing

    SetTimer(IDT_POP_WINDOW_TIMER, m_nMsgWndCreationDelay, NULL);

}

void CTaskBarMsgWnd::PopWndForRightTaskBar()
{
    PopWndForBottomTaskBar();
}


void CTaskBarMsgWnd::PopWndForTopTaskBar()
{
    // Create a specific new window class
    HCURSOR hCursor = ::LoadCursor(NULL, IDC_APPSTARTING);
    HBRUSH hBrush   = ::CreateSolidBrush(m_clrBox); 

	CString strWndClass = ::AfxRegisterWndClass(
                                CS_DBLCLKS,
                                hCursor,
                                hBrush
                            );

    CRect t_rect(0, 0, 0, 0);
    Create(strWndClass, NULL, WS_VISIBLE | WS_OVERLAPPEDWINDOW, t_rect);
    
    CRect rectDesktopWithoutTaskbar;   // The desktop area 

    // Get the desktop area
    ::SystemParametersInfo(SPI_GETWORKAREA, 0, &rectDesktopWithoutTaskbar, 0);
    
	//// Added - Matthew Millman ////
	if (Last)
	{
		m_nWndLeft   = rectDesktopWithoutTaskbar.right - m_nWndWidth;
		m_nWndTop    = rectDesktopWithoutTaskbar.top + Last->Top - rectDesktopWithoutTaskbar.top;
		m_nWndRight  = m_nWndLeft + m_nWndWidth;
		m_nWndBottom = m_nWndTop + m_nWndHeight;
	}

	else
	{
    // Calculate the actual width of the Window and its position in screen co-ordinates
		m_nWndLeft   = rectDesktopWithoutTaskbar.right - m_nWndWidth;
		m_nWndTop    = rectDesktopWithoutTaskbar.top;
		m_nWndRight  = m_nWndLeft + m_nWndWidth;
		m_nWndBottom = m_nWndTop + m_nWndHeight;
	}

	Top = m_nWndBottom;

	/////////////////////////////////

    m_nWndSize = 0; // The height of window is zero before showing

    SetTimer(IDT_POP_WINDOW_TIMER, m_nMsgWndCreationDelay, NULL);
}

void CTaskBarMsgWnd::PopWndForBottomTaskBar()
{
    // Create a specific new window class
    HCURSOR hCursor = ::LoadCursor(NULL, IDC_APPSTARTING);
    HBRUSH hBrush   = ::CreateSolidBrush(m_clrBox); 

	CString strWndClass = ::AfxRegisterWndClass(
                                CS_DBLCLKS,
                                hCursor,
                                hBrush
                            );
    
    // Create the window with the registered class
    CRect t_rect(0, 0, 0, 0);
    Create(strWndClass, NULL, WS_EX_TOOLWINDOW | WS_VISIBLE | WS_OVERLAPPEDWINDOW, t_rect); 
    
    CRect rectDesktopWithoutTaskbar;   // The desktop area 

    // Get the desktop area
    ::SystemParametersInfo(SPI_GETWORKAREA, 0, &rectDesktopWithoutTaskbar, 0);
    
	//// Added - Matthew Millman ////

	if (Last)
	{
		m_nWndLeft   = rectDesktopWithoutTaskbar.right - m_nWndWidth;
		m_nWndTop    = rectDesktopWithoutTaskbar.bottom - (rectDesktopWithoutTaskbar.bottom - Last->Top) - m_nWndHeight;
		m_nWndRight  = m_nWndLeft + m_nWndWidth;
		m_nWndBottom = m_nWndTop + m_nWndHeight;
	}
	else
	{
    // Calculate the actual width of the Window and its position in screen co-ordinates
		m_nWndLeft   = rectDesktopWithoutTaskbar.right - m_nWndWidth;
		m_nWndTop    = rectDesktopWithoutTaskbar.bottom - m_nWndHeight;
		m_nWndRight  = m_nWndLeft + m_nWndWidth;
		m_nWndBottom = m_nWndTop + m_nWndHeight;
	}

    Top = m_nWndTop;

	/////////////////////////////////


    m_nWndSize = 0; // The height of window is zero before showing

    SetTimer(IDT_POP_WINDOW_TIMER, m_nMsgWndCreationDelay, NULL);
}

void CTaskBarMsgWnd::PopMsg()
{
    if (CheckIfTaskBarBottom())  // Most frequent case is status bar at bottom
    {
        PopWndForBottomTaskBar();
    }
    else
    {
        if (CheckIfTaskBarTop())
        {
            PopWndForTopTaskBar();
        }
        else
        {
            if (CheckIfTaskBarLeft())
            {
                PopWndForLeftTaskBar();
            }
            else
            {
                m_nTaskBarPos = STP_RIGHT; // Force it, as no need for calling "CheckIfTaskBarRight()
                PopWndForRightTaskBar();
            }
        }
    }
}

BOOL CTaskBarMsgWnd::CheckIfTaskBarLeft()
{
    unsigned int nAvailableScreenTop;
    unsigned int nAvailableScreenLeft;
    
    CRect rectDesktopWithoutTaskbar;   // The desktop area without status bar
    
    // Get the desktop area minus the status
    ::SystemParametersInfo(SPI_GETWORKAREA, 0, &rectDesktopWithoutTaskbar, 0);
    nAvailableScreenLeft  = rectDesktopWithoutTaskbar.left;
    nAvailableScreenTop = rectDesktopWithoutTaskbar.top;

    if ((nAvailableScreenLeft > 0) && (nAvailableScreenTop == 0))
    {
        m_nTaskBarPos = STP_LEFT;
        return TRUE;
    }
    else
    {
        return FALSE;
    }
}

BOOL CTaskBarMsgWnd::CheckIfTaskBarRight()
{
    unsigned int nAvailableScreenWidth;
    unsigned int nAvailableScreenHeight;
    unsigned int nActualScreenWidth;
    unsigned int nActualScreenHeight;

    // Calculate the actual screen height and width
    nActualScreenWidth  = ::GetSystemMetrics(SM_CXFULLSCREEN);
    nActualScreenHeight = ::GetSystemMetrics(SM_CYFULLSCREEN);

  
    CRect rectDesktopWithoutTaskbar;   // The desktop area without status bar
    
    // Get the desktop area minus the status
    ::SystemParametersInfo(SPI_GETWORKAREA, 0, &rectDesktopWithoutTaskbar, 0);
    nAvailableScreenWidth  = rectDesktopWithoutTaskbar.Width();
    nAvailableScreenHeight = rectDesktopWithoutTaskbar.Height();

    if ((nAvailableScreenWidth != nActualScreenWidth) &&
        (nAvailableScreenHeight == nActualScreenHeight))
    {
        m_nTaskBarPos = STP_RIGHT;
        return TRUE;
    }
    else
    {
        return FALSE;
    }
}

BOOL CTaskBarMsgWnd::CheckIfTaskBarTop()
{
    unsigned int nAvailableScreenTop;
    unsigned int nAvailableScreenLeft;
    
    CRect rectDesktopWithoutTaskbar;   // The desktop area without status bar
    
    // Get the desktop area minus the status
    ::SystemParametersInfo(SPI_GETWORKAREA, 0, &rectDesktopWithoutTaskbar, 0);
    nAvailableScreenLeft  = rectDesktopWithoutTaskbar.left;
    nAvailableScreenTop = rectDesktopWithoutTaskbar.top;

    if ((nAvailableScreenLeft == 0) && (nAvailableScreenTop > 0))
    {
        m_nTaskBarPos = STP_TOP;
        return TRUE;
    }
    else
    {
        return FALSE;
    }
}

BOOL CTaskBarMsgWnd::CheckIfTaskBarBottom()
{
    unsigned int nAvailableScreenWidth;
    unsigned int nAvailableScreenBottom;
    unsigned int nActualScreenWidth;
    unsigned int nActualScreenBottom;

    // Calculate the actual screen height and width
    nActualScreenWidth  = ::GetSystemMetrics(SM_CXSCREEN);
    nActualScreenBottom = ::GetSystemMetrics(SM_CYSCREEN);

  
    CRect rectDesktopWithoutTaskbar;   // The desktop area without status bar
    
    // Get the desktop area minus the status
    ::SystemParametersInfo(SPI_GETWORKAREA, 0, &rectDesktopWithoutTaskbar, 0);
    nAvailableScreenWidth  = rectDesktopWithoutTaskbar.Width();
    nAvailableScreenBottom = rectDesktopWithoutTaskbar.bottom;

    if ((nAvailableScreenWidth == nActualScreenWidth) &&
        (nAvailableScreenBottom < nActualScreenBottom))
    {
        m_nTaskBarPos = STP_BOTTOM;
        return TRUE;
    }
    else
    {
        return FALSE;
    }
}

void CTaskBarMsgWnd::OnSize(unsigned int nType, int cx, int cy)
{
    CFrameWnd::OnSize(nType, cx, cy);

    //SendMessage(WM_MOUSEMOVE, 0);
    CFont* pFont = NULL;
    CClientDC dc(this);

    if (m_bMouseOverWnd)
    {
        pFont = dc.SelectObject(&m_fontMessageUnderline);
    }
    else
    {
        pFont = dc.SelectObject(&m_fontMessageNoUnderline);
    }

    COLORREF clrPreviousBkColor = dc.SetBkColor(m_clrBox); 
    COLORREF clrPreviousTextColor = dc.SetTextColor(m_clrText);
    
    // Show with the message with the new font
	dc.SetBkMode(TRANSPARENT);
	dc.DrawState(CPoint(0, 0), CSize(130, 105), bmBack, NULL, NULL);
	dc.DrawIcon(CPoint(94, 68), icBack);
    dc.DrawText(m_strMsg, &m_rectMsgRect, DT_VCENTER | DT_CENTER | DT_WORDBREAK | DT_END_ELLIPSIS);

    dc.SelectObject(pFont);
    dc.SetBkColor(clrPreviousBkColor);
    dc.SetTextColor(clrPreviousTextColor);
}

int CTaskBarMsgWnd::OnCreate( LPCREATESTRUCT lpCreateStruct )
{
    if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
		return -1;

	ModifyStyle(WS_CAPTION, 0, SWP_FRAMECHANGED); // removes title bar

⌨️ 快捷键说明

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