One of the interesting things I found in the recent times about Windows programming was the
popping up of status bar message windows when somebody logs in MSN messenger. Here is the code I would like to share with
anyone out there who would also like to use it, but was not able to do so because of no direct API help
for the following task.
How to use the source code
Include the following files in your project.
Following lines show how to create an object of
CStatusBarMsgWnd and use it to pop up
a window. We use a pseudo contructor called
CreateObject() because we want to force heap
creation. For making the normal constructor unavailable we make it "private".
We want to make the object on the heap because the
PopMsg() function will trigger timers
and animate the popping up and collapsing of the window even after it has returned.
So the message window should remain in memory till all timers subside and the window
collapses. This even makes the parent application more responsive than using
which I had used earlier. Using
Sleep() made the application block till the window got
CStatusBarMsgWnd* t_MsgWnd = CStatusBarMsgWnd::CreateObject(
_T("Some idiot has signed in !!"), 180, 150, 4000, 10, CRect(30, 30, 130, 110), this );
PopMsg() function first checks, where is the status bar on the desktop?
There are only four cases
- Status bar at the bottom of the screen.
- Status bar at top of the screen.
- Status bar at the left of the screen
- Status bar at the right of the screen.
The following code of
PopMsg() function is shown
SystemParatmeterInfo() APIs to calculate the full screen area and the area on the screen
minus the status bar. Then with some elementary high school mathematics we calculate where exactly the status bar
is (bottom, top, left or right) and appropriately show the message window with some animation.
The real action occurs in the
OnTimer() function which gets triggered because of
messages. There are three timers
IDT_POP_WINDOW_TIMER -> Gets triggered for animating popup
IDT_SHOW_WINDOW_TIMER -> Gets triggered for showing and keeping the window in position for some time
IDT_COLLAPSE_WINDOW_TIMER -> Gets triggered for animating window collapse
There are three other constants namely
STP_LEFT which represent where the status bar position is. These are used in
OnTimer) for the appropriate animation calculations.
The window is automatically deleted after collapsing in the
delete this. That's the reason we force this window's
creation on heap
CStatusBarMsgWnd is derived from
CFrameWnd. The title bar is removed in the
OnCreate() member function. Two
CFont objects are created, one underlined font and the other
non-underlined. We show the underlined font when mouse is above the window using
WM_MOUSEHOVER message). Similarly we use the non-underlined font when the mouse leaves the window with
WM_MOUSELEAVE message). Initialize a "hand" cursor
m_hCursor for showing the mouse when it is over the window.
OnLButtonDown() for the
WM_LBUTTONDOWN message to suit any thing you would like to do. At this point
only shows a message box. You can change and do anything to suit your needs.
int CStatusBarMsgWnd::OnCreate( LPCREATESTRUCT lpCreateStruct )
if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
::ZeroMemory (&lf, sizeof (lf));
lf.lfHeight = 100;
lf.lfWeight = FW_BOLD;
lf.lfUnderline = TRUE;
::strcpy (lf.lfFaceName, _T("Arial"));
lf.lfUnderline = FALSE;
m_hCursor = ::LoadCursor(NULL, IDC_HAND);
How to use the demo project exe
Double click the popwnd.exe and use the "Message Menu" to pop up a message window
Future Work to be done, in progress...
- MSN messenger uses color scheme in the message box taking the color
from the active title bar.