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

📄 statusbarmsgwnd.cpp

📁 visual c++ 实例编程
💻 CPP
📖 第 1 页 / 共 3 页
字号:
----------------------------------------------------------------------------*/

BOOL CStatusBarMsgWnd::CheckIfStatusBarLeft()
{
    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_nStatusBarPos = STP_LEFT;
        return TRUE;
    }
    else
    {
        return FALSE;
    }
}




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

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

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

 Parameters : none

 Return Value : BOOL (TRUE or FALSE)

 Exceptions : none

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

BOOL CStatusBarMsgWnd::CheckIfStatusBarRight()
{
    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_nStatusBarPos = STP_RIGHT;
        return TRUE;
    }
    else
    {
        return FALSE;
    }
}



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

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

 Abstract : Checks if the status bar is on the top

 Parameters : none

 Return Value : BOOL (TRUE or FALSE)

 Exceptions : none

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

BOOL CStatusBarMsgWnd::CheckIfStatusBarTop()
{
    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_nStatusBarPos = STP_TOP;
        return TRUE;
    }
    else
    {
        return FALSE;
    }
}




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

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

 Abstract : Checks if the status bar is at the bottom

 Parameters : none

 Return Value : BOOL (TRUE or FALSE)

 Exceptions : none

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

BOOL CStatusBarMsgWnd::CheckIfStatusBarBottom()
{
    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_nStatusBarPos = STP_BOTTOM;
        return TRUE;
    }
    else
    {
        return FALSE;
    }
}



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

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

 Abstract : Called by MFC when the window is resize message is received

 Parameters : Look in MFC documentation

 Return Value : void

 Exceptions : none

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

void CStatusBarMsgWnd::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);
    }

    // Show with the message with the new font
    dc.DrawText(m_strMsg, &m_rectMsgRect, DT_WORDBREAK | DT_CENTER);
    dc.SelectObject(pFont);

    //dc.DrawText(m_strMsg, &m_rectMsgRect, DT_WORDBREAK | DT_CENTER);
}




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

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

 Abstract : Called by MFC when the window is created but not shown.

 Parameters : Look in MFC documentation

 Return Value : void

 Exceptions : none

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

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

	ModifyStyle(WS_CAPTION, 0, SWP_FRAMECHANGED); // removes title bar
    
    // Start creating two fonts, one underlined , other non underlined
    //
    // LOGFONT structure for font properties
    LOGFONT lf;
    ::ZeroMemory (&lf, sizeof (lf));
    lf.lfHeight = 100;
    lf.lfWeight = FW_BOLD;
    lf.lfUnderline = TRUE;

    ::strcpy (lf.lfFaceName, _T("Arial"));

    // Prepare for an underlined font
    m_fontMessageUnderline.CreatePointFontIndirect(&lf);

    // Prepare  an non undelined font
    lf.lfUnderline = FALSE;
    m_fontMessageNoUnderline.CreatePointFontIndirect(&lf);

    // Initialize the cursor.
    m_hCursor = ::LoadCursor(NULL, IDC_ARROW); // Use IDC_HAND if it compiles
    	
    return 0;
}




/*-----------------------------------------------------------------------------
 Function : CStatusBarMsgWnd::OnMouseMove(UNIT nFlags, CPoint point)

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

 Abstract : Called by MFC when the mouse is moved.

 Parameters : Look in MFC documentation

 Return Value : void

 Exceptions : none

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

void CStatusBarMsgWnd::OnMouseMove(UINT nFlags, CPoint point)
{
    // Register the tracking of Mouse entering and leaveing the window
    // for WM_MOUSEHOVER and WM_MOUSELEAVE
    TRACKMOUSEEVENT t_MouseEvent;
    t_MouseEvent.cbSize      = sizeof(TRACKMOUSEEVENT);
    t_MouseEvent.dwFlags     = TME_LEAVE | TME_HOVER;
    t_MouseEvent.hwndTrack   = m_hWnd;
    t_MouseEvent.dwHoverTime = 1;

    ::_TrackMouseEvent(&t_MouseEvent);
}




/*-----------------------------------------------------------------------------
 Function : CStatusBarMsgWnd::OnTimer(UNIT nFlags, CPoint point)

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

 Abstract : Called by MFC when a TIMER message is generated

 Parameters : Look in MFC documentation

 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::OnTimer(UINT nIDEvent)
{
    switch (nIDEvent)
    {
        case IDT_POP_WINDOW_TIMER:    // When the window comes up
        {
            switch (m_nStatusBarPos)
            {
                case STP_BOTTOM:
                case STP_RIGHT:
                {
                    ++m_nWndSize;
                    if (m_nWndSize > m_nWndHeight)
                    {
                        KillTimer(IDT_POP_WINDOW_TIMER);
                        SetTimer(IDT_SHOW_WINDOW_TIMER, m_nMsgTimeOut, NULL);
                    }
                    else
                    {
                        // Keep sizing the window, show it
                        SetWindowPos(
                            &wndTopMost,
                            m_nWndLeft,
                            m_nWndBottom - m_nWndSize -5, 
                            m_nWndWidth - 10,
                            m_nWndSize,
                            SWP_SHOWWINDOW
                        );
                    }
                }
                break;

                case STP_TOP:
                {
                    ++m_nWndSize;
                    if (m_nWndSize > m_nWndHeight)
                    {
                        KillTimer(IDT_POP_WINDOW_TIMER);
                        SetTimer(IDT_SHOW_WINDOW_TIMER, m_nMsgTimeOut, NULL);
                    }
                    else
                    {
                        // Keep sizing the window, collapse it
                        SetWindowPos(
                            &wndTopMost,
                            m_nWndLeft,
                            m_nWndTop, 
                            m_nWndWidth - 10,
                            m_nWndSize,
                            SWP_SHOWWINDOW
                        );

⌨️ 快捷键说明

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