Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. ATL / WTL / STL
  4. Control being created with a valid DC but no window until a refresh is made

Control being created with a valid DC but no window until a refresh is made

Scheduled Pinned Locked Moved ATL / WTL / STL
helpc++comtutorialquestion
2 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    TClarke
    wrote on last edited by
    #1

    Hi all, I've got an ATL ActiveX control which only starts correctly the second time it's loaded. The first time it's loaded the DC in the parameter of the OnDraw method cannot be used to get the window it is supposed to be associated with ie a cal to GetWindowFrom DC fails. When checked in spy++ it is clear that this is no error, there is no window being created with the control. Does anyone have an idea why this might be the case and how to resolve it? I'm using XP SP2 VS2005 ATL 8.0 Thanks loads for any help :)

    Cheers Tom Philosophy: The art of never getting beyond the concept of life. Religion: Morality taking credit for the work of luck.

    T 1 Reply Last reply
    0
    • T TClarke

      Hi all, I've got an ATL ActiveX control which only starts correctly the second time it's loaded. The first time it's loaded the DC in the parameter of the OnDraw method cannot be used to get the window it is supposed to be associated with ie a cal to GetWindowFrom DC fails. When checked in spy++ it is clear that this is no error, there is no window being created with the control. Does anyone have an idea why this might be the case and how to resolve it? I'm using XP SP2 VS2005 ATL 8.0 Thanks loads for any help :)

      Cheers Tom Philosophy: The art of never getting beyond the concept of life. Religion: Morality taking credit for the work of luck.

      T Offline
      T Offline
      TClarke
      wrote on last edited by
      #2

      Added the following code and fixed the problem:

      // this is derived from CComControl
      STDMETHOD(SetClientSite)(IOleClientSite *pClientSite)
      {
      if (pClientSite)
      {
      RECT rc = {0,0,0,0};
      // Don't have access to the container's window so just use the
      // desktop. Window will be resized correctly during in-place
      // activation.
      HWND hWnd = CreateControlWindow(::GetDesktopWindow(), rc);
      _ASSERT (hWnd);
      }
      return IOleObjectImpl::SetClientSite (pClientSite);
      }

      HRESULT InPlaceActivate(LONG iVerb, const RECT\* prcPosRect)
      {
      
      	// Get the container's window.
      	\_ASSERT (m\_spClientSite);
      	LPOLEINPLACESITE pInPlaceSite = NULL;
      	HRESULT hr = m\_spClientSite->QueryInterface(IID\_IOleInPlaceSite,
      		(void       \*\*)&pInPlaceSite);
      	\_ASSERT (SUCCEEDED (hr) && pInPlaceSite);
      	HWND hParent = NULL;
      	hr = pInPlaceSite->GetWindow (&hParent);
      	\_ASSERT (SUCCEEDED (hr) && hParent);
      	pInPlaceSite->Release ();
      	// Set container window as our parent window
      	SetParent (hParent);
      	return CComControlBase::InPlaceActivate(iVerb, prcPosRect);
      }
      

      Cheers Tom Philosophy: The art of never getting beyond the concept of life. Religion: Morality taking credit for the work of luck.

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups