Re: how to switch between property pages using another application?
<email@example.com> wrote in message
I have an applications A which consists 4 property pages. I want to
write another application to switch the property pages in application
A. How to do it?
Property sheets switch pages in response to PSM_SETCURSEL. Therefore, just
// nPage is desired page; 0 <= nPage < 4
::SendMessage (hwndPropSheet, PSM_SETCURSEL, nPage, 0);
In fact, the MFC code is this:
BOOL CPropertySheet::SetActivePage(int nPage)
if (m_hWnd == NULL)
m_psh.nStartPage = nPage;
return (BOOL)SendMessage(PSM_SETCURSEL, nPage);
Of course, all the rules about sending a message to a HWND of a different
process apply. I would replace SendMessage with PostMessage to avoid
hanging problems if App A is hung, you don't want to hang the app that is
trying to change the pages too:
::PostMessage (hwndPropSheet, PSM_SETCURSEL, nPage, 0);
But as the MFC code shows, the return value from SendMessage is a BOOL
whether it succeeded or not. If this is important to you, you need to keep
the SendMessage in order to get a return value. You can use
SendMessageAsync() instead to at least not infinitely hang if app A is hung.