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

📄 statusbarmsgwnd.cpp

📁 visual c++ 实例编程
💻 CPP
📖 第 1 页 / 共 3 页
字号:
/*******************************************************************************
File:        StatusBarMsgWnd.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


Copyright (c) 2001, Centre for Development of Advanced Computing (C-DAC), Pune.
All rights Reserved.

The copyright to the computer program(s) herein is the property of C-DAC, Pune.
The program(s) may be used and/or copied only with the written permission of 
C-DAC, Pune or in accordance with the terms and conditions stipulated
in the agreement/contract under which the program(s) have been supplied.
********************************************************************************/

/********************************************************************************
类名:CStatusBarMsgWnd
功能:可建立象MSN一样的在状态条上自动弹出和消隐的信息窗口
用法:
  1、包含状态条弹出窗口的头文件
     #include "StatusBarMsgWnd.h"
  2、想调用时只需加入下面代码既可
   CStatusBarMsgWnd* t_MsgWnd = CStatusBarMsgWnd::CreateObject(
                                                       _T("Some idiot has signed in !!"), 
                                                       180, 
                                                       150, 
                                                       4000, 
                                                        10,
                                                        CRect(30, 30, 130, 110),
                                                       this);


	t_MsgWnd->PopMsg();
修改人:徐景周(jingzhou_xu@163.net)
组织:未来工作室(Future Studio)
日期:2001.12.1
*********************************************************************************/
#include "stdafx.h"
#include "StatusBarMsgWnd.h"

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

/*----------------------------------------------------------------------------
 Message map
----------------------------------------------------------------------------*/

BEGIN_MESSAGE_MAP(CStatusBarMsgWnd, 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)
END_MESSAGE_MAP()



/*-----------------------------------------------------------------------------
 Function : CStatusBarMsgWnd::CStatusBarMsgWnd()

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

 Abstract : Constructor

 Parameters : 
    1. strMsg     -> Message to be shown in the window
    2. nWndWidth  -> Width of the message window
    3. nWndHeight -> Height if the message window
    4. nMsgTimeOut -> Seconds the window remains stationary
    5. nMsgWndCreationDelay -> Seconds in which the window gets shown
    4. pParent    -> Pointer to the parent window
    5  rectMsgRect -> Rectangle in the window where the message will be

 Return Value : none

 Exceptions : none

 Revisions : none
----------------------------------------------------------------------------*/

CStatusBarMsgWnd::CStatusBarMsgWnd(
                      CString strMsg, 
                      unsigned int nWndWidth,
                      unsigned int nWndHeight,
                      unsigned int nMsgTimeOut,         
                      unsigned int nMsgWndCreationDelay, 
                      CRect rectMsgRect,
                      CWnd* pWndParent) : m_strMsg(strMsg), m_rectMsgRect(rectMsgRect)
{
    m_nWndWidth  = nWndWidth;
    m_nWndHeight = nWndHeight;

    m_pWndParent = pWndParent;

    m_nMsgTimeOut          = nMsgTimeOut;
    m_nMsgWndCreationDelay = nMsgWndCreationDelay;

    m_bMouseOverWnd = FALSE;

    m_hCursor = NULL;
}




/*-----------------------------------------------------------------------------
 Function : CStatusBarMsgWnd::~CStatusBarMsgWnd()

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

 Abstract : Destructor

 Parameters : none

 Return Value : none

 Exceptions : none

 Revisions : none
----------------------------------------------------------------------------*/

CStatusBarMsgWnd::~CStatusBarMsgWnd()
{
}



/*-----------------------------------------------------------------------------
 Function : CStatusBarMsgWnd::PopWndForLeftStatusBar()

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

 Abstract : Pops up a message window on the system tray when the status bar is
            is on the left side

 Parameters : none

 Return Value : void

 Exceptions : none

 Revisions : none
----------------------------------------------------------------------------*/

void CStatusBarMsgWnd::PopWndForLeftStatusBar()
{
    CRect t_rect(0, 0, 0, 0);
    Create(NULL, NULL, WS_VISIBLE | WS_OVERLAPPEDWINDOW, t_rect, m_pWndParent);
    
    CRect rectDesktopWithoutTaskbar;   // The desktop area 

    // Get the desktop area
    ::SystemParametersInfo(SPI_GETWORKAREA, 0, &rectDesktopWithoutTaskbar, 0);
    
    // Calculate the actual width of the Window and its position
    m_nWndLeft   = rectDesktopWithoutTaskbar.left;
    m_nWndTop    = rectDesktopWithoutTaskbar.bottom - m_nWndHeight;
    m_nWndRight  = m_nWndLeft + m_nWndWidth;
    m_nWndBottom = m_nWndTop + m_nWndHeight;
    
    m_nWndSize = 0; // The height of window is zero before showing

    SetTimer(IDT_POP_WINDOW_TIMER, m_nMsgWndCreationDelay, NULL);

}




/*-----------------------------------------------------------------------------
 Function : CStatusBarMsgWnd::PopWndForRightStatusBar()

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

 Abstract : Pops up a message window on the system tray when the status bar is
            is on the right side

 Parameters : none

 Return Value : none

 Exceptions : none

 Revisions : The previous version used ::Sleep API for animation and display
             which blocked the application, i.e the parent window.
             Now we use WM_TIMER messages for animation and display so
             the application remains responsive in between WM_TIMER
             messages
----------------------------------------------------------------------------*/

void CStatusBarMsgWnd::PopWndForRightStatusBar()
{
    PopWndForBottomStatusBar();
}




/*-----------------------------------------------------------------------------
Function : CStatusBarMsgWnd::PopWndForTopStatusBar()

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

 Abstract : Pops up a message window on the system tray when the status bar is
            is on the top. 

 Parameters : none

 Return Value : void

 Exceptions : none

 Revisions : The previous version used ::Sleep API for animation and display
             which blocked the application, i.e the parent window.
             Now we use WM_TIMER messages for animation and display so
             the application remains responsive in between WM_TIMER
             messages
----------------------------------------------------------------------------*/

void CStatusBarMsgWnd::PopWndForTopStatusBar()
{
    CRect t_rect(0, 0, 0, 0);
    Create(NULL, NULL, WS_VISIBLE | WS_OVERLAPPEDWINDOW, t_rect, m_pWndParent);
    
    CRect rectDesktopWithoutTaskbar;   // The desktop area 

    // Get the desktop area
    ::SystemParametersInfo(SPI_GETWORKAREA, 0, &rectDesktopWithoutTaskbar, 0);
    
    // 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;

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

    SetTimer(IDT_POP_WINDOW_TIMER, m_nMsgWndCreationDelay, NULL);
}




/*-----------------------------------------------------------------------------
 Function : CStatusBarMsgWnd::PopWndForBottomStatusBar()

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

 Abstract : Pops up a message window on the system tray when the status bar is
            is at the bottom

 Parameters : none

 Return Value : void

 Exceptions : none

 Revisions : The previous version used ::Sleep API for animation and display
             which blocked the application, i.e the parent window.
             Now we use WM_TIMER messages for animation and display so
             the application remains responsive in between WM_TIMER
             messages
----------------------------------------------------------------------------*/

void CStatusBarMsgWnd::PopWndForBottomStatusBar()
{
    CRect t_rect(0, 0, 0, 0);
    
    Create(NULL, NULL, WS_VISIBLE | WS_OVERLAPPEDWINDOW, t_rect, m_pWndParent); 
    
    CRect rectDesktopWithoutTaskbar;   // The desktop area 

    // Get the desktop area
    ::SystemParametersInfo(SPI_GETWORKAREA, 0, &rectDesktopWithoutTaskbar, 0);
    
    // 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;
    
    m_nWndSize = 0; // The height of window is zero before showing

    SetTimer(IDT_POP_WINDOW_TIMER, m_nMsgWndCreationDelay, NULL);
}



/*-----------------------------------------------------------------------------
 Function : CStatusBarMsgWnd::PopMsg()

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

 Abstract : Pops a message window above the system tray

 Parameters : none

 Return Value : void

 Exceptions : none

 Revisions : none
----------------------------------------------------------------------------*/

void CStatusBarMsgWnd::PopMsg()
{
    if (CheckIfStatusBarBottom())  // Most frequent case is status bar at bottom
    {
        PopWndForBottomStatusBar();
    }
    else
    {
        if (CheckIfStatusBarTop())
        {
            PopWndForTopStatusBar();
        }
        else
        {
            if (CheckIfStatusBarLeft())
            {
                PopWndForLeftStatusBar();
            }
            else
            {
                m_nStatusBarPos = STP_RIGHT; // Force it, as no need for calling "CheckIfStatusBarRight()
                PopWndForRightStatusBar();
            }
        }
    }
}



/*-----------------------------------------------------------------------------
 Function : CStatusBarMsgWnd::CheckIfStatusBarLeft()

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

 Abstract : Checks if the status bar is on the left side

 Parameters : none

 Return Value : BOOL (TRUE or FALSE)

 Exceptions : none

 Revisions : none

⌨️ 快捷键说明

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