How to Add 'No Selection' property page on a modeless proper
Roger Onslow -- Roger_Onslow@compsys.com.au
Wednesday, June 12, 1996
Environment: MFC 4.0 Win32 (NT/95)
MSVC/Developer Studio uses property sheets (or inspectors) to
display properties of selected objects. When no object is displayed
the tabs disappear and a "No Selection" message appears.
We mortals can also create modeless property sheets, but how
does one display the "No Selection" message when all the tabs
are removed?
Here's how...
(1) Create a modeless property sheet (using component gallery)
(2) add a CStatic member to the sheet class
CStatic m_static;
(3) Write a member function to show or hide the m_static as appropriate
void CMyPropertySheet::ShowMessageIfNoPages() {
if (m_static.GetSafeHwnd()) {
m_static.ShowWindow(0==m_pages.GetSize());
// NB: cannot use GetPageCount because
// tab control may not exist yet
}
}
(4) Use class wizard to handle WM_CREATE (OnCreate)
which creates the "No Selection" m_static (in centre)
int CMyPropertySheet::OnCreate(LPCREATESTRUCT lpCreateStruct) {
if (CPropertySheet::OnCreate(lpCreateStruct) == -1) return -1;
m_static.Create("No Selection",WS_CHILD|SS_CENTER,CRect(0,0,120,20),this);
m_static.CenterWindow();
ShowMessageIfNoPages();
return 0;
}
(5) Provide you own AddPage and RemovePage functions which call
the base class and update the m_static appropriately
(Don't forget to declare them in the .h)
void CMyPropertySheet::AddPage(CPropertyPage* pPage) {
ShowMessageIfNoPages();
CPropertySheet::AddPage(pPage);
}
void CMyPropertySheet::RemovePage(CPropertyPage* pPage) {
CPropertySheet::RemovePage(pPage);
ShowMessageIfNoPages();
}
void CMyPropertySheet::RemovePage(int nPage) {
CPropertySheet::RemovePage(nPage);
ShowMessageIfNoPages();
}
Now, if you remove all the pages from a dialog, the message
"No Selection" appears -- just like MSVC/Developer Studio !!
Sneaky, hey???
Tada.wav!!
Roger Onslow
Senior Software Engineer
Computer Systems Australia
Ph: +61 49 577155
Fax: +61 49 675554
eMail: RogerO@compsys.com.au
Roger Onslow -- Roger_Onslow@compsys.com.au
Wednesday, June 12, 1996
Environment: MFC 4.0 Win32 (NT/95)
MSVC/Developer Studio uses property sheets (or inspectors) to
display properties of selected objects. When no object is displayed
the tabs disappear and a "No Selection" message appears.
We mortals can also create modeless property sheets, but how
does one display the "No Selection" message when all the tabs
are removed?
Here's how...
(1) Create a modeless property sheet (using component gallery)
(2) add a CStatic member to the sheet class
CStatic m_static;
(3) Write a member function to show or hide the m_static as appropriate
void CMyPropertySheet::ShowMessageIfNoPages() {
if (m_static.GetSafeHwnd()) {
m_static.ShowWindow(0==m_pages.GetSize());
// NB: cannot use GetPageCount because
// tab control may not exist yet
}
}
(4) Use class wizard to handle WM_CREATE (OnCreate)
which creates the "No Selection" m_static (in centre)
int CMyPropertySheet::OnCreate(LPCREATESTRUCT lpCreateStruct) {
if (CPropertySheet::OnCreate(lpCreateStruct) == -1) return -1;
m_static.Create("No Selection",WS_CHILD|SS_CENTER,CRect(0,0,120,20),this);
m_static.CenterWindow();
ShowMessageIfNoPages();
return 0;
}
(5) Provide you own AddPage and RemovePage functions which call
the base class and update the m_static appropriately
(Don't forget to declare them in the .h)
void CMyPropertySheet::AddPage(CPropertyPage* pPage) {
ShowMessageIfNoPages();
CPropertySheet::AddPage(pPage);
}
void CMyPropertySheet::RemovePage(CPropertyPage* pPage) {
CPropertySheet::RemovePage(pPage);
ShowMessageIfNoPages();
}
void CMyPropertySheet::RemovePage(int nPage) {
CPropertySheet::RemovePage(nPage);
ShowMessageIfNoPages();
}
Now, if you remove all the pages from a dialog, the message
"No Selection" appears -- just like MSVC/Developer Studio !!
Sneaky, hey???
Tada.wav!!
Roger Onslow
Senior Software Engineer
Computer Systems Australia
Ph: +61 49 577155
Fax: +61 49 675554
eMail: RogerO@compsys.com.au
| Вернуться в корень Архива
|