|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Announcements
Chapters
Services
Feature Zones
|
IntroductionThis article explains how to use WTL's Status BarAll of the relevant code for using the status bar is contained in the
BasicsA status bar provides users with various types of feedback and information as they use an application. WTL wizard-generated applications define a single pane status bar. It handles the basic functions of showing "Ready" and is switched to simple mode to display menu tips. Multipane status bars, on the other hand, are divided into multiple, independently controlled segments. InitializationPlease note that you must include the The following steps are needed to define and initialize a multipane status bar control for an application:
The following resource definitions from #define IDR_DEFAULT 201 #define IDR_DATE 202 #define IDR_TIME 203 In addition, WTL defines a default pane identifier, Here is the LRESULT OnCreate(UINT, WPARAM, LPARAM, BOOL&)
{
CreateSimpleStatusBar();
// subclass the status bar as multipane
m_status.SubclassWindow(m_hWndStatusBar);
// set status bar panes. ID_DEFAULT_PANE is defined by WTL
int arrPanes[] = { ID_DEFAULT_PANE, IDR_DATE, IDR_TIME };
m_status.SetPanes(arrPanes,
sizeof(arrPanes) / sizeof(int), false);
// set status bar pane widths using local workaround
int arrWidths[] = { 0, 90, 60 };
SetPaneWidths(arrWidths, sizeof(arrWidths) / sizeof(int));
// set the status bar pane icons
m_status.SetPaneIcon(ID_DEFAULT_PANE,
AtlLoadIconImage(IDR_DEFAULT, LR_DEFAULTCOLOR));
m_status.SetPaneIcon(IDR_DATE,
AtlLoadIconImage(IDR_DATE, LR_DEFAULTCOLOR));
m_status.SetPaneIcon(IDR_TIME,
AtlLoadIconImage(IDR_TIME, LR_DEFAULTCOLOR));
// initialize date/time and start a 1 second timer
OnTimer(0, 0, 0, bHandled);
SetTimer(1, 1000);
return 0;
}
Workaround
void SetPaneWidths(int* arrWidths, int nPanes)
{
// find the size of the borders
int arrBorders[3];
m_status.GetBorders(arrBorders);
// calculate right edge of default pane (0)
arrWidths[0] += arrBorders[2];
for (int i = 1; i < nPanes; i++)
arrWidths[0] += arrWidths[i];
// calculate right edge of remaining panes (1 thru nPanes-1)
for (int j = 1; j < nPanes; j++)
arrWidths[j] += arrBorders[2] + arrWidths[j - 1];
// set the pane widths
m_status.SetParts(m_status.m_nPanes, arrWidths);
}
Timer HandlerHere is the code for the timer handler. You must also create a message map
entry for the LRESULT OnTimer(UINT, WPARAM, LPARAM, BOOL&)
{
// get the current date and time
SYSTEMTIME st;
::GetLocalTime(&st);
CString str;
// Pane 1: Display the date
str.Format("%i/%i/%i", st.wMonth, st.wDay, st.wYear);
m_status.SetPaneText(IDR_DATE, str);
// Pane 2: Display the time
str.Format("%i:%02i", st.wHour, st.wMinute);
m_status.SetPaneText(IDR_TIME, str);
return 0;
}
Terms Of UseThe sample application available with this article is free for any purpose. THIS SOFTWARE IS DISTRIBUTED AS-IS, WITHOUT WARRANTIES OF ANY KIND.
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||