Transferring data between property page & property sheet.

I have three property pages & each of them needs to send data back to propery sheet. The common property sheet has a list box which displays certain information send by these property pages. Is there any way to send data through a function to the property sheet so that it automatically updates the list box?

I thought of using the ontimer() function in the propertysheet & updating the list box variable. However, how do you pass information from the property page to this list box variable which is a aprt of property sheet...

Any help in this matter is appreciated.
Thanks,
Nilesh
Nilesh_PowarAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jaime OlivaresSoftware ArchitectCommented:
you can use something like:
((CYourPropSheetClass *)GetParent())->UpdateLBFunc(somedata)  
from every property page
Nilesh_PowarAuthor Commented:
My property page has the class named DB_Init_ Dlg & the Property sheet has class by CDatabaseManagerDlg.
I tried accessing the function using the getparent approach, it compiles but when I try running it, it crashes.
Is there something that i am doing wrong??? I am trying to update the list box with the temp variable value.
Below is the code...

void DB_Init_Dlg::OnBnClickedSchemaChanges()
{      
      CWnd *parent = GetParent();
      BOOL result = parent->ModifyStyle( WS_CHILD, WS_POPUP);
      int i=ADD_COLUMN_VER_1_1();
      if (i!=E_OK)
      {
            CString temp=DB_Go_Error();
            ((CDatabaseManagerDlg*)GetParent())->Show(temp);
                        
      }
}


int CDatabaseManagerDlg::Show(CString temp)
{
      CListBox* m_ListBox= (CListBox*)GetDlgItem( IDC_LIST2 );
      m_ListBox->AddString(temp);
      return 0;
}

Thanks
Nilesh
Nilesh_PowarAuthor Commented:
((CYourPropSheetClass *)GetParent())->UpdateLBFunc(somedata)  helps in accessing the function but may be i have to
do something special to update the list box in the property sheet.
Any comments.

Expert Spotlight: Joe Anderson (DatabaseMX)

We’ve posted a new Expert Spotlight!  Joe Anderson (DatabaseMX) has been on Experts Exchange since 2006. Learn more about this database architect, guitar aficionado, and Microsoft MVP.

Nilesh_PowarAuthor Commented:
I have been trying many things including the ontimer() ,etc to update the listbox, but nothing seems to work.

Any ideas,
Nilesh
Jaime OlivaresSoftware ArchitectCommented:
Really strange, try to create a user-define messsage in parent and use PostMessage() to send a message from propertysheet.
Jaime OlivaresSoftware ArchitectCommented:
Sorry, I mean, try to  post a messsage from propertypage
Nilesh_PowarAuthor Commented:
How do you create a user-define message in parent?could you provide a little bit of code on how to do the message thing?

Jaime OlivaresSoftware ArchitectCommented:
create a PreTranslateMessage event at parent
from child use PostMessage to send a user message (could be WM_USER or WM_USER+1) to the parent
at PreTranslateMessage evaluate message code and show a MessageBox if arrives.

There are other ways but I think this is a simple one.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Nilesh_PowarAuthor Commented:
Ur suggestion works & the code is below, so from any property page will I have to use the postmessage(WM_User,0,0)?
What does the postmessage exactly do? Because from another property page i did not use the post message statement & still it works. Irrespective of the postmessage(), the parent runs the pretranslate message??? how is it possible? I was under the assumption that the postmessage will put the message on a window's message queue & the pretranslate message will take care of it.


void DB_Init_Dlg::OnBnClickedSchemaChanges()
{      
      CWnd *parent = GetParent();
      BOOL result = parent->ModifyStyle( WS_CHILD, WS_POPUP);
      int i=ADD_COLUMN_VER_1_1();
      if (i!=E_OK)
      {
            temp=DB_Go_Error();
            ((CDatabaseManagerDlg*)GetParent())->Show(temp);            
            PostMessage(WM_USER,0,0);
      }
}



BOOL CDatabaseManagerDlg::PreTranslateMessage(MSG* pMsg)
{
      CListBox* m_ListBox= (CListBox*)GetDlgItem( IDC_LIST2 );
      if(flag==1)
      {      
            m_ListBox->AddString(mem);
            flag=0;
      }
      return CDialog::PreTranslateMessage(pMsg);
}
Jaime OlivaresSoftware ArchitectCommented:
Pretranslatemessage is an MFC event where you have the opportunity to process a message before it is processed by window or any child control, even you can discard or modify message at this point. It is a "catch-all event"
The WM_USER message is a standard message, so you can write an individual message handler function for it. Also you can use SendMessage instead of PostMessage, but PostMessage works better in some situations because a return value is not required.
Your PreTranslateMessage is not well implemented, it will be activated with EVERY message that arrives to the window, you need to "filter" it this way:

BOOL CDatabaseManagerDlg::PreTranslateMessage(MSG* pMsg)
{
     if (pMsg->msg==WM_USER) {   // FILTER MESSAGE
         CListBox* m_ListBox= (CListBox*)GetDlgItem( IDC_LIST2 );
         // etcetera
     }
     return CDialog::PreTranslateMessage(pMsg);
}
Nilesh_PowarAuthor Commented:
That makes lot of sense, I realised that every message was going through the pretranslate message, but now everything works great... That was immense help from you ...Thanks so much...
Thanks for all the suggesions & prompt replies...

Nilesh...
Nilesh_PowarAuthor Commented:
I had a follow up question to the above topic. I can use WM_USER message, but rather than using the preTranslateMEssage to trap the message, I have been trying to use the ON_MESSAGE(WM_USER+7, On_Error).
I am trying to handle the WM_USER+7 in the following function. But it never enters the On_Error(WPARAM wParam, LPARAM lParam). Am i missing something here?

LRESULT CDatabaseManagerDlg::On_Error(WPARAM wParam, LPARAM lParam)
{
            CListBox* m_ListBox= (CListBox*)GetDlgItem( IDC_LIST2 );
            if(flag==1)
            {      
                  m_ListBox->AddString(mem);
                  flag=0;
            }
return 0;
}

I am using the postmessage() in the following function in the property page.

void DB_Init_Dlg::OnBnClickedSchemaChanges()
{    
     CWnd *parent = GetParent();
     BOOL result = parent->ModifyStyle( WS_CHILD, WS_POPUP);
     int i=ADD_COLUMN_VER_1_1();
     if (i!=E_OK)
     {
          temp=DB_Go_Error();
          ((CDatabaseManagerDlg*)GetParent())->Show(temp);          
          PostMessage(WM_USER+7,0,0);
     }
}

Thanks,
Nilesh...
Jaime OlivaresSoftware ArchitectCommented:
>          PostMessage(WM_USER+7,0,0);
 
Are you sending the message to the self object?
I guess you want to do something like:

((CDatabaseManagerDlg*)GetParent())->PostMessage(WM_USER+7,0,0);
Nilesh_PowarAuthor Commented:
I had tried doing that, it didn't help.
It does not enter the On_Error(WPARAM wParam, LPARAM lParam) function at all.
Jaime OlivaresSoftware ArchitectCommented:
>I had tried doing that, it didn't help
Not a try, it is mandatory

Maybe you are processing the message inside PreTranslateMessage() too?
Nilesh_PowarAuthor Commented:
I completely accept that it is mandatory to use the Getparent() thing...

NO I commented PretranslateMessage totally.

I declare the function in DatabasemanagerDlg.h as follows:
      afx_msg LRESULT On_Error(WPARAM wParam, LPARAM lParam);

I do it exactly as described in MSDN or anywhere in the book, but still doesnot work....
Jaime OlivaresSoftware ArchitectCommented:
I don't see your message map, could you post it?

It should be something like:

BEGIN_MESSAGE_MAP(CDatabaseManagerDlg, CDialog)
  //{{AFX_MSG_MAP(CDatabaseManagerDlg)
  //...
  ON_MESSAGE(WM_USER+7, On_Error)
 //}}AFX_MSG_MAP
END_MESSAGE_MAP()

Nilesh_PowarAuthor Commented:
BEGIN_MESSAGE_MAP(CDatabaseManagerDlg, CDialog)
      ON_WM_SYSCOMMAND()
      ON_WM_PAINT()
      ON_WM_QUERYDRAGICON()
      //}}AFX_MSG_MAP

      ON_MESSAGE(WM_USER+7, On_Error)
      ON_BN_CLICKED(IDOK, OnBnClickedOk)
      ON_WM_TIMER()
      ON_WM_DESTROY()
END_MESSAGE_MAP()


// CDatabaseManagerDlg message handlers
Nilesh_PowarAuthor Commented:
I am still stuck with the same problem, I have tried bunch of different things but it does not go into the On_Error message handler.
any suggestions are welcome.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.