CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Feb 2001
    Posts
    342

    Weird ActiveX problem - doesn't always display

    I'm using an ActiveX control that displays text in a container (like IE).

    To optimize it's drawing, I turned off the OLEMISC_ACTIVATEWHENVISIBLE flag (per MSDN) so that the control doesn't activate until the user does something with it. This definitely speeded it up.

    However, in some cases the control (and I have about 100 of them on a web page) doesn't draw itself (the text) with this flag turned off...

    Anyone have any ideas why this may be? I do my drawing code in the OnDraw(...) function.

    Here's the bulk of the code for the control:
    Code:
    // SdxCellRendererCtl.cpp : Implementation of the CSdxCellRendererCtrl ActiveX Control class.
    
    #include "stdafx.h"
    #include "SdxCellRenderer.h"
    #include "SdxCellRendererCtl.h"
    #include "SdxCellRendererPpg.h"
    #include "Mapi.h"
    #include "CMapi.h"
    #include <SypODLAll.h>
    
    
    #ifdef _DEBUG
    #define new DEBUG_NEW
    #undef THIS_FILE
    static char THIS_FILE[] = __FILE__;
    #endif
    
    IMPLEMENT_DYNCREATE(CSdxCellRendererCtrl, COleControl)
    
    char vp[256]; char vs[256]; char vu[256]; char vw[256]; char vc[256];
    
    /////////////////////////////////////////////////////////////////////////////
    // Message map
    
    BEGIN_MESSAGE_MAP(CSdxCellRendererCtrl, COleControl)
    	//{{AFX_MSG_MAP(CSdxCellRendererCtrl)
    	ON_WM_LBUTTONDBLCLK()
    	ON_WM_CONTEXTMENU()
    	ON_WM_LBUTTONUP()
    	ON_COMMAND(IDM_CXEDIT, OnCXEdit)
    	ON_COMMAND(IDM_CXCUT, OnCXCut)
    	ON_COMMAND(IDM_CXCOPY, OnCXCopy)
    	ON_COMMAND(IDM_CXDELETE, OnCXDelete)
    	ON_COMMAND(IDM_CXPASTE, OnCXPaste)
    	ON_COMMAND(IDM_CXCLOSE, OnCXClose)
    	ON_COMMAND(IDM_CXNOTIFY, OnCXNotify)
    	ON_COMMAND(IDM_CXPRINT, OnCXPrint)
    	ON_COMMAND(IDM_CXCUSTOMERINFO, OnCXCustomerinformation)
    	ON_COMMAND(IDM_CXONLINESERVICE, OnCXOnlineservice)
    /*	ON_UPDATE_COMMAND(IDM_CXCOPY, OnUpdateCXCopy)
    	ON_UPDATE_COMMAND(IDM_CXDELETE, OnUpdateCXDelete)
    	ON_UPDATE_COMMAND(IDM_CXPASTE, OnUpdateCXPaste)
    	ON_UPDATE_COMMAND(IDM_CXCLOSE, OnUpdateCXClose)
    	ON_UPDATE_COMMAND(IDM_CXNOTIFY, OnUpdateCXNotify)
    	ON_UPDATE_COMMAND(IDM_CXPRINT, OnUpdateCXPrint)
    	ON_UPDATE_COMMAND(IDM_CXCUSTOMERINFO, OnUpdateCXCustomerinformation)
    	ON_UPDATE_COMMAND(IDM_CXONLINESERVICE, OnUpdateCXOnUpdatelineservice)*/
    	//}}AFX_MSG_MAP
    	ON_MESSAGE(OCM_COMMAND, OnOcmCommand)
    	ON_OLEVERB(AFX_IDS_VERB_PROPERTIES, OnProperties)
    END_MESSAGE_MAP()
    
    
    /////////////////////////////////////////////////////////////////////////////
    // Dispatch map
    
    BEGIN_DISPATCH_MAP(CSdxCellRendererCtrl, COleControl)
    	//{{AFX_DISPATCH_MAP(CSdxCellRendererCtrl)
    	DISP_PROPERTY_NOTIFY(CSdxCellRendererCtrl, "label", m_label, OnLabelChanged, VT_BSTR)
    	DISP_PROPERTY_NOTIFY(CSdxCellRendererCtrl, "id", m_id, OnIdChanged, VT_I4)
    	DISP_PROPERTY_NOTIFY(CSdxCellRendererCtrl, "type", m_type, OnTypeChanged, VT_BSTR)
    	DISP_PROPERTY_NOTIFY(CSdxCellRendererCtrl, "com", m_com, OnComChanged, VT_BOOL)
    	//}}AFX_DISPATCH_MAP
    END_DISPATCH_MAP()
    
    
    /////////////////////////////////////////////////////////////////////////////
    // Event map
    
    BEGIN_EVENT_MAP(CSdxCellRendererCtrl, COleControl)
    	//{{AFX_EVENT_MAP(CSdxCellRendererCtrl)
    	// NOTE - ClassWizard will add and remove event map entries
    	//    DO NOT EDIT what you see in these blocks of generated code !
    	//}}AFX_EVENT_MAP
    END_EVENT_MAP()
    
    
    /////////////////////////////////////////////////////////////////////////////
    // Property pages
    
    // TODO: Add more property pages as needed.  Remember to increase the count!
    BEGIN_PROPPAGEIDS(CSdxCellRendererCtrl, 1)
    	PROPPAGEID(CSdxCellRendererPropPage::guid)
    END_PROPPAGEIDS(CSdxCellRendererCtrl)
    
    
    /////////////////////////////////////////////////////////////////////////////
    // Initialize class factory and guid
    
    IMPLEMENT_OLECREATE_EX(CSdxCellRendererCtrl, "SDXCELLRENDERER.SdxCellRendererCtrl.1",
    	0xa5c1fef, 0xa4f5, 0x4a1d, 0x9c, 0xf4, 0xc6, 0xc6, 0x59, 0x3, 0xbd, 0x15)
    
    
    /////////////////////////////////////////////////////////////////////////////
    // Type library ID and version
    
    IMPLEMENT_OLETYPELIB(CSdxCellRendererCtrl, _tlid, _wVerMajor, _wVerMinor)
    
    
    /////////////////////////////////////////////////////////////////////////////
    // Interface IDs
    
    const IID BASED_CODE IID_DSdxCellRenderer =
    		{ 0x9a4236f0, 0x6765, 0x4f75, { 0xa3, 0x64, 0xfd, 0x11, 0x14, 0x70, 0xe, 0xe5 } };
    const IID BASED_CODE IID_DSdxCellRendererEvents =
    		{ 0xc7d8fc01, 0xdee2, 0x4326, { 0xbd, 0x94, 0x7a, 0x3c, 0xe6, 0x85, 0x7, 0x42 } };
    
    
    /////////////////////////////////////////////////////////////////////////////
    // Control type information
    
    static const DWORD BASED_CODE _dwSdxCellRendererOleMisc =
    	OLEMISC_ACTIVATEWHENVISIBLE |
    	OLEMISC_SETCLIENTSITEFIRST |
    	OLEMISC_INSIDEOUT |
    	OLEMISC_CANTLINKINSIDE |
    	OLEMISC_RECOMPOSEONRESIZE;
    
    IMPLEMENT_OLECTLTYPE(CSdxCellRendererCtrl, IDS_SDXCELLRENDERER, _dwSdxCellRendererOleMisc)
    
    
    /////////////////////////////////////////////////////////////////////////////
    // CSdxCellRendererCtrl::CSdxCellRendererCtrlFactory::UpdateRegistry -
    // Adds or removes system registry entries for CSdxCellRendererCtrl
    
    BOOL CSdxCellRendererCtrl::CSdxCellRendererCtrlFactory::UpdateRegistry(BOOL bRegister)
    {
    	// TODO: Verify that your control follows apartment-model threading rules.
    	// Refer to MFC TechNote 64 for more information.
    	// If your control does not conform to the apartment-model rules, then
    	// you must modify the code below, changing the 6th parameter from
    	// afxRegApartmentThreading to 0.
    
    	if (bRegister)
    		return AfxOleRegisterControlClass(
    			AfxGetInstanceHandle(),
    			m_clsid,
    			m_lpszProgID,
    			IDS_SDXCELLRENDERER,
    			IDB_SDXCELLRENDERER,
    			afxRegApartmentThreading,
    			_dwSdxCellRendererOleMisc,
    			_tlid,
    			_wVerMajor,
    			_wVerMinor);
    	else
    		return AfxOleUnregisterClass(m_clsid, m_lpszProgID);
    }
    
    
    /////////////////////////////////////////////////////////////////////////////
    // CSdxCellRendererCtrl::CSdxCellRendererCtrl - Constructor
    
    CSdxCellRendererCtrl::CSdxCellRendererCtrl()
    {
    	InitializeIIDs(&IID_DSdxCellRenderer, &IID_DSdxCellRendererEvents);
    
    	// TODO: Initialize your control's instance data here.
    }
    
    
    /////////////////////////////////////////////////////////////////////////////
    // CSdxCellRendererCtrl::~CSdxCellRendererCtrl - Destructor
    
    CSdxCellRendererCtrl::~CSdxCellRendererCtrl()
    {
    	// TODO: Cleanup your control's instance data here.
    }
    
    
    /////////////////////////////////////////////////////////////////////////////
    // CSdxCellRendererCtrl::OnDraw - Drawing function
    
    void CSdxCellRendererCtrl::OnDraw(
    			CDC* pdc, const CRect& rcBounds, const CRect& rcInvalid)
    {
    	DoSuperclassPaint(pdc, rcBounds);
    	CFont *font = new CFont();
    	font->CreateFont(13.5,5,0,0,FW_NORMAL,FALSE,FALSE,m_com,ANSI_CHARSET,OUT_TT_PRECIS,CLIP_TT_ALWAYS,PROOF_QUALITY,DEFAULT_PITCH,"Arial");
    	pdc->SelectObject(font);
    
    	// font color
    	if(m_type == "Emergency") pdc->SetTextColor(RGB(238,44,44));
    	if(m_type == "Preventive Maintenance") pdc->SetTextColor(RGB(34,139,34));
    	if(m_type == "Installed") pdc->SetTextColor(RGB(0,0,238));
    	if(m_type == "Holiday") pdc->SetTextColor(RGB(238,173,14));
    	if(m_type == "Floating Holiday") pdc->SetTextColor(RGB(238,173,14));
    	if(m_type == "Unavailable") pdc->SetTextColor(RGB(238,173,14));
    	if(m_type == "Sick") pdc->SetTextColor(RGB(205,205,0));
    	if(m_type == "Vacation") pdc->SetTextColor(RGB(205,205,0));
    	if(m_type == "System Report") pdc->SetTextColor(RGB(199,21,133));
    	pdc->TextOut(0,0,m_label);
    	delete font;
    }
    
    
    /////////////////////////////////////////////////////////////////////////////
    // CSdxCellRendererCtrl::DoPropExchange - Persistence support
    
    void CSdxCellRendererCtrl::DoPropExchange(CPropExchange* pPX)
    {
    	ExchangeVersion(pPX, MAKELONG(_wVerMinor, _wVerMajor));
    	COleControl::DoPropExchange(pPX);
    
    	// TODO: Call PX_ functions for each persistent custom property.
    	PX_String(pPX,"label",m_label);
    	PX_Long(pPX,"id",m_id);
    	PX_String(pPX,"type",m_type);
    	PX_Bool(pPX,"com",m_com);
    }
    
    
    /////////////////////////////////////////////////////////////////////////////
    // CSdxCellRendererCtrl::GetControlFlags -
    // Flags to customize MFC's implementation of ActiveX controls.
    //
    // For information on using these flags, please see MFC technical note
    // #nnn, "Optimizing an ActiveX Control".
    DWORD CSdxCellRendererCtrl::GetControlFlags()
    {
    	DWORD dwFlags = COleControl::GetControlFlags();
    
    
    	// The control will not be redrawn when making the transition
    	// between the active and inactivate state.
    	dwFlags |= noFlickerActivate;
    	return dwFlags;
    }
    
    
    /////////////////////////////////////////////////////////////////////////////
    // CSdxCellRendererCtrl::OnResetState - Reset control to default state
    
    void CSdxCellRendererCtrl::OnResetState()
    {
    	COleControl::OnResetState();  // Resets defaults found in DoPropExchange
    
    	// TODO: Reset any other control state here.
    }
    
    
    /////////////////////////////////////////////////////////////////////////////
    // CSdxCellRendererCtrl::PreCreateWindow - Modify parameters for CreateWindowEx
    
    BOOL CSdxCellRendererCtrl::PreCreateWindow(CREATESTRUCT& cs)
    {
    	cs.lpszClass = _T("EDIT");
    	return COleControl::PreCreateWindow(cs);
    }
    
    
    /////////////////////////////////////////////////////////////////////////////
    // CSdxCellRendererCtrl::IsSubclassedControl - This is a subclassed control
    
    BOOL CSdxCellRendererCtrl::IsSubclassedControl()
    {
    	return TRUE;
    }

  2. #2
    Join Date
    Apr 2002
    Location
    Romania, Bucharest
    Posts
    105
    try this:

    Code:
    CFont *old_font;
    CFont *font = new CFont();
    font->CreateFont(....);
    
    old_font=pdc->SelectObject(font);
    
    //your draw code here
    ...
    
    pdc->SelectObject(old_font);
    delete font;

  3. #3
    Join Date
    Feb 2001
    Posts
    342

    What is the thought process

    behind your solution?

    I'm just trying to understand why this will help.

    thx.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured