Click here to Skip to main content
15,891,712 members
Articles / Desktop Programming / MFC
Article

Using the PSM_QUERYSIBLINGS message

Rate me:
Please Sign up or sign in to vote.
4.57/5 (10 votes)
17 Jul 2004CPOL 62.7K   551   19   9
Explains how to use the PSM_QUERYSIBLINGS message to share data between pages on a property sheet.

Introduction

The idea for this article came from a query in the VC++ forum. I hope someone does find this useful.

How to use PSM_QUERYSIBLINGS

If you want to know how to use the PSM_QUERYSIBLINGS message to send data between pages on a property sheet, the first step is to look at the CPropertyPage::QuerySiblings function.

LRESULT CPropertyPage::QuerySiblings(WPARAM wParam, LPARAM lParam)
{
   ASSERT(::IsWindow(m_hWnd));
   ASSERT(GetParent() != NULL);

   return GetParent()->SendMessage(PSM_QUERYSIBLINGS, wParam, lParam);
}

You will see all it does is sends a PSM_QUERYSIBLINGS message to the parent CPropertySheet. The property sheet's default behavior is to relay the PSM_QUERYSIBLINGS message to all of its child pages. So for each page, you would set up a message map entry to catch the PSM_QUERYSIBLINGS message, and add the function to handle it.

BEGIN_MESSAGE_MAP(CMyPropertyPage, CPropertyPage)
   ON_MESSAGE(PSM_QUERYSIBLINGS, OnQuerySiblings)
END_MESSAGE_MAP()

...

LRESULT CMyPropertyPage1::OnQuerySiblings(WPARAM wParam, LPARAM lParam)
{
   // Do whatever you want done here. The wParam and lParam
   // parameters will have the values you specified in the
   // call to CPropertyPage::QuerySiblings()

   return 0; // returning anything but 0 stops the PSM_QUERYSIBLINGS
             // message from being sent to any more pages.
}

If you want the property sheet to handle the message, you would set up the sheet's message map to also catch the PSM_QUERYSIBLINGS message. Just be sure to call Default() so that the default handler gets called.

LRESULT CMyPropertySheet::OnQuerySiblings(WPARAM wParam, LPARAM lParam)
{
   // Do what ever you want on the property sheet when the PSM_QUERYSIBLINGS
   // message is being handled. The wParam and lParam parameters will have
   // the values you specified in the call to CPropertyPage::QuerySiblings()

   return Default();
}

If you want to change the wParam and lParam values when your sheet handles the message, and pass the changed values onto the property pages, you will have to send the PSM_QUERYSIBLINGS message to each window yourself.

LRESULT CMyPropertySheet::OnQuerySiblings(WPARAM wParam, LPARAM lParam)
{
   // change the wParam and/or lParam values

   int nPages = GetPageCount();
   LRESULT result = 0;
   for (int page = 0; page < nPages && result == 0; ++page)
      result = GetPage(page)->SendMessage(PSM_QUERYSIBLINGS, wParam, lParam);

   return result;
}

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
President
Canada Canada
Father of two, brother of two, child of two.
Spouse to one, uncle to many, friend to lots.
Farmer, carpenter, mechanic, electrician, but definitely not a plumber.
Likes walks with the wife, board games, card games, travel, and camping in the summer.
High school graduate, college drop-out.
Hobby programmer who knows C++ with MFC and the STL.
Has dabbled with BASIC, Pascal, Fortran, COBOL, C#, SQL, ASM, and HTML.
Realized long ago that programming is fun when there is nobody pressuring you with schedules and timelines.

Comments and Discussions

 
QuestionDynamically added pages don't receive message Pin
Mike Pulice19-Sep-05 13:03
Mike Pulice19-Sep-05 13:03 
GeneralRefreshing property pages Pin
monimicki30-Nov-04 22:59
monimicki30-Nov-04 22:59 
Thanks heaps for the article... But as usual, I wanted to do something different that wasn't explained in the article!!

In one of my property pages, I allow the user to change some parts of a database. In the other property page, I had a view of that database. I wanted to know how to use querysiblings (or anything else) to send the message to the proppage with the view so that it would update that view when the database was changed.... Sounds easy, but for me, not!

Anyway, I finally worked it out, and here's what I had to do (hope it helps someone):

In the page that I wanted to refresh:

LRESULT Cpage1::OnQuerySiblings(WPARAM wParam, LPARAM lParam)
{
m_gsemlist.ResetContent(); // A listbox to clear
m_GlanceList.DeleteAllItems(); // CListCtrl to clear
reset=TRUE; // BOOL member variable

return 0;
}


BOOL Cpage1::OnSetActive()
{
if(reset==TRUE)
{
restart(); // Function to refill listbox/clistctrl
reset=FALSE;
}
return CPropertyPage::OnSetActive();
}


If I had the restart() function call in the OnQuerySiblings function, it did not work. But it was very weird, because when I debugged, the listbox did actually clear, and then the correct strings were added, however, they didn't actually show up until the next QuerySiblings message was sent (but sending two in a row didn't help either).

So again, I'm not sure why it works like this, but it does.



GeneralNote: Transfering CStrings Pin
ColinDavies18-Jul-04 13:40
ColinDavies18-Jul-04 13:40 
GeneralRe: Note: Transfering CStrings Pin
Steve Mayfield19-Jul-04 12:31
Steve Mayfield19-Jul-04 12:31 
GeneralRe: Note: Transfering CStrings Pin
Blake Miller20-Jul-04 4:47
Blake Miller20-Jul-04 4:47 
Generalaltering message parameters Pin
Paolo Messina18-Jul-04 6:45
professionalPaolo Messina18-Jul-04 6:45 
GeneralRe: altering message parameters Pin
PJ Arends18-Jul-04 9:00
professionalPJ Arends18-Jul-04 9:00 
GeneralBelieve me it is useful. Pin
ColinDavies17-Jul-04 20:28
ColinDavies17-Jul-04 20:28 
GeneralRe: Believe me it is useful. Pin
PJ Arends17-Jul-04 20:33
professionalPJ Arends17-Jul-04 20:33 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.