OleCreatePropertyFrame 
Author Message
 OleCreatePropertyFrame

Hi,

Does anyone have any idea why "Apply" is called when switching between
property pages?

I am using "OleCreatePropertyFrame" to display the property pages for my
objects, and everything is working exacly as I would expect, except for
one thing... "IpropertyPage::Apply" is called for the page that loses
focus whenver the active page changes.

If I could either find out how to prevent this from occurring, or detect
whether the user changed pages or actually clicked "Apply", I would be
very happy...

Thanks,

Dan.



Thu, 15 Jan 2004 03:17:36 GMT  
 OleCreatePropertyFrame
Hi Dan,

This is the default behaviour of the Ole property frames. He can avoid this
by hooking into the window proc of the property sheet and handling the
TCN_SELCHANGE yourself. Here is the workaround code. Note the code in
OnInitDialog, Apply and OnChange. OnChange is the command handler that
catches changes made in the property page.

WNDPROC gOldFrameProc = 0;
BOOL   gbApply = FALSE;
BOOL   gbDirty = FALSE;
LRESULT CALLBACK FrameWndProc (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM
lParam)
{
        if (WM_COMMAND == uMsg && ( ID_APPLY_NOW == LOWORD(wParam) || IDOK ==
LOWORD(wParam)) )
         gbApply = TRUE;
        else if (WM_NOTIFY == uMsg && TCN_SELCHANGE == ((LPNMHDR)lParam)->code )     {
                EnableWindow (GetDlgItem (hWnd, ID_APPLY_NOW), gbDirty);
                gbApply = FALSE;
        }
        return CallWindowProc (gOldFrameProc, hWnd, uMsg, wParam, lParam);}

Hook into the property sheet's window procedure in the OnInitDialog of the
first property page.

BEGIN_MSG_MAP(CMyAtlPropPage1)
  MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog)
  COMMAND_HANDLER(IDC_EDIT1, EN_CHANGE, OnChange)
  CHAIN_MSG_MAP(IPropertyPageImpl<CMyAtlPropPage1>)
END_MSG_MAP()

LRESULT OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL&
bHandled)
{      
      gOldFrameProc = (WNDPROC)::SetWindowLong(::GetParent(GetParent()),
GWL_WNDPROC,    LONG)FrameWndProc);
       bHandled = FALSE;
      return TRUE;

Quote:
}

        // Respond to changes to update the dirty status of the page
        LRESULT OnChange(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
        {
                SetDirty(true);
                gbDirty = TRUE;
                return 0;
        }
        STDMETHOD(Apply)(void)  {
                if (gbApply && m_bDirty)
                {
                        for (UINT i = 0; i < m_nObjects; i++)
                        {
                                // Do something interesting here
                                // ICircCtl* pCirc;
                                // m_ppUnk[i]->QueryInterface(IID_ICircCtl, (void**)&pCirc);
                                // pCirc->put_Caption(CComBSTR("something special"));
                                // pCirc->Release();
                        }
                        gbDirty = FALSE;
                        m_bDirty = FALSE;
                }
                return S_OK;
        }

Regards,
Leo



Fri, 16 Jan 2004 17:14:35 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. OleCreatePropertyFrame

2. OleCreatePropertyFrame()

3. OleCreatePropertyFrame() Fails with 80004005

4. How to change the whole title (caption) of a PropertyFrame created with OleCreatePropertyFrame

5. How can I set a PropertyFrame created with OleCreatePropertyFrame always on top of the z-order

6. OleCreatePropertyFrame function, help needed

7. OleCreatePropertyFrame() fails to create propertysheet, help!

8. BUG in OleCreatePropertyFrame API: No way to trap OK or Cancel

9. OleCreatePropertyFrame(...)

10. Why OleCreatePropertyFrame() fails in test computer but OK in development computer?

 

 
Powered by phpBB® Forum Software