15 мая 2023 года "Исходники.РУ" отмечают своё 23-летие!
Поздравляем всех причастных и неравнодушных с этим событием!
И огромное спасибо всем, кто был и остаётся с нами все эти годы!

Главная Форум Журнал Wiki DRKB Discuz!ML Помощь проекту


AW: Property Sheet in OLE control

IT347
Monday, February 03, 1997

[Mini-digest: 4 responses]


Have you tried ensuring that the property sheet has the   =
 WS_EX_CONTROLPARENT style set? There was a bug (might be fixed now) that   =
=
used to screw up the hwnd if focus switched from an propertysheet and   =
then back again. This was fixed by setting the above style flag
hth

 ----------
Von:  Alan J. Livingston=5BSMTP:AlanLivingston=40acm.org=5D
Gesendet:  Freitag, 31. Januar 1997 18:39
An:  mfc-l=40netcom.com
Betreff:  Property Sheet in OLE control


Environment: VC++ 4.2b, Windows95
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D


I saw this problem posted on MS's newserver (microsoft.public.vc.mfc),   =
but
never saw a response.  I knew it was going to haunt me later.

I have an OLE control, created with the control wizard that pops up a
property sheet in response to a double click.  I use the following code:

void CCPropCtrl::OnLButtonDblClk(UINT nFlags, CPoint point)
=7B

 CPropertySheet sheet(=22title=22, this);
 CPropertyPage page (IDD_PROPPAGE_CPROP);

 sheet.AddPage(&page);
 sheet.DoModal();

=7D

Now, if I insert this control into the test container and double click on   =
it
the property sheet appears.  Then, if I tab to another app and tab back   =
to
this one and click on the OK button to close the proprty sheet, the app   =
crashes.

I've traced through the code and it crashes in CWnd::EnableWindow which   =
is
called from CPropertySheet::DoModal.  It appears as if the hWnd of the   =
safe
parent of the control is being munged somehow.  Help=21  Has anybody seen  =
 =
this?

 -Alan


-----From: "Achyuth Kumar .G S" 

Hi Alan,

I think your main problem is with not checking the return value of
'DoModal()' function. If it is 'IDOK' just return and everything works
fine.

>achyuth
>
>Environment: VC++ 4.2b, Windows95
>=================================
>
>
>I saw this problem posted on MS's newserver (microsoft.public.vc.mfc), but
>never saw a response.  I knew it was going to haunt me later.
>
>I have an OLE control, created with the control wizard that pops up a
>property sheet in response to a double click.  I use the following code:
>
>void CCPropCtrl::OnLButtonDblClk(UINT nFlags, CPoint point) 
>{
>
>	CPropertySheet sheet("title", this);
>	CPropertyPage page (IDD_PROPPAGE_CPROP);
>
>	sheet.AddPage(&page);
>	sheet.DoModal();
>
>}
>
>Now, if I insert this control into the test container and double click on it
>the property sheet appears.  Then, if I tab to another app and tab back to
>this one and click on the OK button to close the proprty sheet, the app
>crashes.
>
>I've traced through the code and it crashes in CWnd::EnableWindow which is
>called from CPropertySheet::DoModal.  It appears as if the hWnd of the safe
>parent of the control is being munged somehow.  Help!  Has anybody seen this?
>
>-Alan
>
>
-----From: "Dunphy, Michael" 

The HWND of the CWnd * returned by CWnd::GetSafeOwner(m_pParentWnd,   
&hWndTop); in CPropertySheet::DoModal
is not necessarily in the permanent handle map. (It seems like it is in   
the permanent map if you create a CPropertySheet from an exe, but not   
when you create one from an OCX).

You can work around this problem by deriving a class from CPropertySheet   
and overriding DoModal(). Here's what we do:

int CHOurPropertySheet::DoModal()
{
   //----------------------------------------------------------
   // make same call DoModal() makes, so we get the same CWnd*
   //----------------------------------------------------------
   HWND hWndTop;
   CWnd *pOwner = CWnd::GetSafeOwner(m_pParentWnd, &hWndTop);
   HWND h = pOwner->GetSafeHwnd();
   CWnd cPerm;
   if (h != NULL)
   {
      //-----------------------------------
      // is the hwnd in the permanent map?
      //-----------------------------------
      CWnd *pPerm = CWnd::FromHandlePermanent(h);
      if (pPerm == NULL)
      {
         //---------------------------------------------------------------  

         // hwnd isn't in the permanent map, so attach the hwnd to a CWnd
         //---------------------------------------------------------------  

         cPerm.Attach(pOwner->GetSafeHwnd());
      }
   }

   int rc = CPropertySheet::DoModal();

   //------------------------------------
   // if we attached the hwnd, detach it
   //------------------------------------
   if (cPerm.GetSafeHwnd() != NULL)
      cPerm.Detach();

   return rc;
}

Mike Dunphy
Programmer Analyst
Honeywell, Inc.

AlanLivingston@acm.org wrote:
> Environment: VC++ 4.2b, Windows95
>
>    I saw this problem posted on MS's newserver   
(microsoft.public.vc.mfc), but
>  never saw a response.  I knew it was going to haunt me later.
>   I have an OLE control, created with the control wizard that pops up a
>  property sheet in response to a double click.  I use the following   
code:
>   void CCPropCtrl::OnLButtonDblClk(UINT nFlags, CPoint point)  {
>    CPropertySheet sheet("title", this);
>   CPropertyPage page (IDD_PROPPAGE_CPROP);
>    sheet.AddPage(&page);
>   sheet.DoModal();
>   }
>   Now, if I insert this control into the test container and double   
click on it
>  the property sheet appears.  Then, if I tab to another app and tab   
back to
>  this one and click on the OK button to close the proprty sheet, the   
app
> crashes.
>   I've traced through the code and it crashes in CWnd::EnableWindow   
which is
>  called from CPropertySheet::DoModal.  It appears as if the hWnd of the   
safe
>  parent of the control is being munged somehow.  Help!  Has anybody   
seen this?


-----From: jeremy@omsys.com (Jeremy H. Griffith)

On Fri, 31 Jan 1997 12:39:04 -0500, "Alan J. Livingston"
 wrote:

>
>Environment: VC++ 4.2b, Windows95
>=================================

>I have an OLE control, created with the control wizard that pops up a
>property sheet in response to a double click.  I use the following code:
>
>void CCPropCtrl::OnLButtonDblClk(UINT nFlags, CPoint point) 
>{
>
>	CPropertySheet sheet("title", this);
>	CPropertyPage page (IDD_PROPPAGE_CPROP);
>
>	sheet.AddPage(&page);
>	sheet.DoModal();
>
>}
>
>Now, if I insert this control into the test container and double click on it
>the property sheet appears.  Then, if I tab to another app and tab back to
>this one and click on the OK button to close the proprty sheet, the app crashes.
>
>I've traced through the code and it crashes in CWnd::EnableWindow which is
>called from CPropertySheet::DoModal.  It appears as if the hWnd of the safe
>parent of the control is being munged somehow.  Help!  Has anybody seen this?

I also have an Ole Control with property pages, and it's a good bit more
complicated than that...  To begin with, you need to derive your own property
page from COlePropertyPage, not CPropertyPage; I used ClassWizard.  Actually,
you should have gotten the first one for free, from the Control Wizard... I
needed to add several more.

After you have your derived OlePropertyPage, you need to define a string
resource for the property page caption, and plug the ID into the constructor
that CW wrote for you (the second arg to the base class ctor):

EvGraphPpg::EvGraphPpg() :
	COlePropertyPage(IDD, IDS_EVGRAPH_PPG_CAPTION)
{...

In your main control class (derived from COleControl) you'll find lines like
this:

/////////////////////////////////////////////////////////////////////////////
// Property pages

BEGIN_PROPPAGEIDS(EvGraphCtl, 1)
  PROPPAGEID(EvGraphPpg::guid)
END_PROPPAGEIDS(EvGraphCtl)

This shows what's needed for one property page; if you have more, add their
PROPPAGEIDs too and increase the number in the first line accordingly.  The
stuff so far is all in the online docs, BTW.  (I'm using VC++ 4.0, NT 3.51.)

Now, the hard part; to get the prop page to show up from a doubleclick:

void EvGraphCtl::OnLButtonDblClk(UINT nFlags, CPoint point) 
{
	CWnd* pWnd = GetParent();
	if (!pWnd)
		return;
	HWND hParent = pWnd->GetSafeHwnd();
	if (!hParent)
		return;
	OnProperties(NULL, hParent, NULL);
	Refresh();
}

I worked this out through lengthy study of the MFC source... ;-)
and it works perfectly well with my control.  Sure wish the docs
had given *some* clue, though... for a while, I wasn't sure it
could be done at all...

--Jeremy



Mike Blaszczak -- mikeblas@nwlink.com
Tuesday, February 04, 1997

>Von:  Alan J. Livingston[SMTP:AlanLivingston@acm.org]

>I have an OLE control, created with the control wizard that pops up a
>property sheet in response to a double click.  I use the following code:

>Now, if I insert this control into the test container and double click on
 it
>the property sheet appears.  Then, if I tab to another app and tab back   to
>this one and click on the OK button to close the proprty sheet, the app
crashes.

This was a bug in MFC, unfortunately.  It'll be fixed in the next version.


.B ekiM
http://www.nwlink.com/~mikeblas/
These words are my own. I do not speak on behalf of Microsoft.
           This performance was not lip-synched.





| Вернуться в корень Архива |