📄 statusbarmsgwnd.cpp
字号:
}
}
break;
case STP_LEFT:
{
++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, collpase it
SetWindowPos(
&wndTopMost,
m_nWndLeft + 10,
m_nWndBottom - m_nWndSize - 5,
m_nWndWidth,
m_nWndSize,
SWP_SHOWWINDOW
);
}
}
break;
}
}
break;
case IDT_SHOW_WINDOW_TIMER:
{
KillTimer(IDT_SHOW_WINDOW_TIMER);
SetTimer(IDT_COLLAPSE_WINDOW_TIMER, m_nMsgWndCreationDelay, NULL);
}
break;
case IDT_COLLAPSE_WINDOW_TIMER:
{
switch (m_nStatusBarPos)
{
case STP_BOTTOM:
case STP_RIGHT:
{
--m_nWndSize;
if (m_nWndSize <= 0)
{
KillTimer(IDT_COLLAPSE_WINDOW_TIMER);
m_nWndSize = 0;
delete this;
}
else
{
// Keep showing the window, collapse 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 <= 0)
{
KillTimer(IDT_COLLAPSE_WINDOW_TIMER);
m_nWndSize = 0;
delete this;
}
else
{
SetWindowPos(
&wndTopMost,
m_nWndLeft,
m_nWndTop,
m_nWndWidth - 10,
m_nWndSize,
SWP_SHOWWINDOW
);
}
}
break;
case STP_LEFT:
{
--m_nWndSize;
if (m_nWndSize <= 0)
{
KillTimer(IDT_COLLAPSE_WINDOW_TIMER);
m_nWndSize = 0;
delete this;
}
else
{
SetWindowPos(
&wndTopMost,
m_nWndLeft + 10,
m_nWndBottom - m_nWndSize - 5,
m_nWndWidth,
m_nWndSize,
SWP_SHOWWINDOW
);
}
}
break;
}
}
break;
}
}
/*-----------------------------------------------------------------------------
Function : CStatusBarMsgWnd::OnMouseHover(WPARAM, LPARAM)
Created: Oct 17, 2001
Author: Prateek Kaul
e-mail: kaulpr@yahoo.com
Abstract : Called by MFC when mouse is above a window
Parameters : Look in MFC documentation
Return Value : void
Exceptions : none
Revisions : none
----------------------------------------------------------------------------*/
LRESULT CStatusBarMsgWnd::OnMouseHover(WPARAM w, LPARAM l)
{
if (m_bMouseOverWnd == FALSE) // Mouse was not on window
{
CClientDC dc(this);
CFont* pFont = dc.SelectObject(&m_fontMessageUnderline);
// Show with the message with the new font
dc.DrawText(m_strMsg, &m_rectMsgRect, DT_WORDBREAK | DT_CENTER);
dc.SelectObject(pFont); // restore the DC to its original state
m_bMouseOverWnd = TRUE; // Mouse is now over window
}
return 0;
}
/*-----------------------------------------------------------------------------
Function : CStatusBarMsgWnd::OnMouseLeaves(WPARAM, LPARAM)
Created: Oct 17, 2001
Author: Prateek Kaul
e-mail: kaulpr@yahoo.com
Abstract : Called by MFC when mouse is leaves a window
Parameters : Look in MFC documentation
Return Value : LRESULT
Exceptions : none
Revisions : none
----------------------------------------------------------------------------*/
LRESULT CStatusBarMsgWnd::OnMouseLeave(WPARAM w, LPARAM l)
{
if (m_bMouseOverWnd) // Mouse was over window, now it is leaving
{
CClientDC dc(this);
CFont* 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); // Restore DC back to its original state
m_bMouseOverWnd = FALSE; // Mouse is not over window
}
return 0;
}
/*-----------------------------------------------------------------------------
Function : CStatusBarMsgWnd::OnSetCursor(WPARAM, LPARAM)
Created: Oct 17, 2001
Author: Prateek Kaul
e-mail: kaulpr@yahoo.com
Abstract : Called by MFC when mouse is moved on a window
Parameters : Look in MFC documentation
Return Value : BOOL
Exceptions : none
Revisions : none
----------------------------------------------------------------------------*/
BOOL CStatusBarMsgWnd::OnSetCursor(CWnd* pWnd , UINT nHitTest , UINT message)
{
if (nHitTest == HTCLIENT)
{
::SetCursor(m_hCursor); // Set cursor to HAND type when mouse is over window
return TRUE;
}
return CFrameWnd::OnSetCursor (pWnd, nHitTest, message);
}
/*-----------------------------------------------------------------------------
Function : CStatusBarMsgWnd::OnDestroy()
Created: Oct 17, 2001
Author: Prateek Kaul
e-mail: kaulpr@yahoo.com
Abstract : Called by MFC when window is about to be destroyed and it becomes
already invisible
Parameters : Look in MFC documentation
Return Value : void
Exceptions : none
Revisions : none
----------------------------------------------------------------------------*/
void CStatusBarMsgWnd::OnDestroy(void)
{
::CloseHandle(m_hCursor); // Free the cursor as it is a shared resource..
CFrameWnd::OnDestroy();
}
/*-----------------------------------------------------------------------------
Function : CStatusBarMsgWnd::OnPaint()
Created: Oct 17, 2001
Author: Prateek Kaul
e-mail: kaulpr@yahoo.com
Abstract : Called by MFC when a window recives a WM_PAINT message
Parameters : Look in MFC documentation
Return Value : void
Exceptions : none
Revisions : none
----------------------------------------------------------------------------*/
void CStatusBarMsgWnd::OnPaint()
{
CFont* pFont = NULL;
CPaintDC 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); // restore the DC to its original state
}
/*-----------------------------------------------------------------------------
Function : CStatusBarMsgWnd::OnLButtonDown(UINT, CPoint)
Created: Oct 17, 2001
Author: Prateek Kaul
e-mail: kaulpr@yahoo.com
Abstract : Called by MFC when a window recives a WM_LBUTTONDOWN message
Parameters : Look in MFC documentation
Return Value : void
Exceptions : none
Revisions : none
----------------------------------------------------------------------------*/
void CStatusBarMsgWnd::OnLButtonDown(UINT nFlags, CPoint point)
{
::AfxMessageBox(_T("Hi boss"));
}
/*-----------------------------------------------------------------------------
Function : CStatusBarMsgWnd::CreateObject()
Created: Oct 13, 2001
Author: Prateek Kaul
e-mail: kaulpr@yahoo.com
Abstract : Creates an CStatusBarMsgWnd, constructor is not public because we
want to force heap creation for better response for the
parent window. So we use SetTimer in PopWnd() and return.
So no blocking with Sleep() API.
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::CreateObject(CString strMsg,
unsigned int nWndWidth,
unsigned int nWndHeight,
unsigned int nMsgTimeOut,
unsigned int nMsgWndCreationDelay,
CRect rectMsgRect,
CWnd* pWndParent)
{
CStatusBarMsgWnd* t_StatusBarMsgWnd = new CStatusBarMsgWnd(
strMsg,
nWndWidth,
nWndHeight,
nMsgTimeOut,
nMsgWndCreationDelay,
rectMsgRect,
pWndParent
);
return (t_StatusBarMsgWnd);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -