2010-02-27 5 views
0

J'ai créé une fenêtre ATL moins de contrôle et la définition de classe est comme ceci:Comment obtenir HWND d'un contrôle ATL sans fenêtre?

class ATL_NO_VTABLE CRSPClient : 
    public IObjectSafetyImpl<CRSPClient, INTERFACESAFE_FOR_UNTRUSTED_CALLER|INTERFACESAFE_FOR_UNTRUSTED_DATA>, 
    public CComObjectRootEx<CComSingleThreadModel>, 
    public IDispatchImpl<IRSPClient, &IID_IRSPClient, &LIBID_axBanckleRSPClientLib, /*wMajor =*/ 1, /*wMinor =*/ 0>, 
    public IPersistStreamInitImpl<CRSPClient>, 
    public IOleControlImpl<CRSPClient>, 
    public IOleObjectImpl<CRSPClient>, 
    public IOleInPlaceActiveObjectImpl<CRSPClient>, 
    public IQuickActivateImpl<CRSPClient>, 
    public IViewObjectExImpl<CRSPClient>, 
    public IOleInPlaceObjectWindowlessImpl<CRSPClient>, 
#ifdef _WIN32_WCE // IObjectSafety is required on Windows CE for the control to be loaded correctly 
    public IObjectSafetyImpl<CRSPClient, INTERFACESAFE_FOR_UNTRUSTED_CALLER>, 
#endif 
    public CComCoClass<CRSPClient, &CLSID_RSPClient>, 
    public CComControl<CRSPClient> 

ensuite dans un but que je dois poster un message à la fenêtre. J'ai essayé de la poignée de la fenêtre très bien des égards et tous Failed:

HWND CRSPClient::GetHwnd() 
{ 
    HWND hwndRet = NULL; 
    // hwndRet = m_hWnd; 
    //IOleInPlaceActiveObjectImpl<CRSPClient>::GetWindow(&hwndRet); 
    //IOleWindow<CRSPClient>::GetWindow(&hwndRet); 
    //this->m_spInPlaceSite->GetWindow(&hwndRet); 
    //CComQIPtr<IOleInPlaceSite> spSite = this->m_spClientSite; 
    //spSite->GetWindow(&hwndRet); 
    //hwndRet = ::WindowFromDC(GetDC()); 
    return hwndRet; 
} 

Tout le monde sait être là un moyen d'obtenir le HWND?

OMG Je suis totalement frustré par le super framework ATL de Microsoft!

Répondre

3

Le but du contrôle sans fenêtre est qu'il fonctionne sans poignée de fenêtre. Si vous vouliez utiliser la poignée de fenêtre au cas où, par hasard, elle existerait et que le contrôle revienne en mode fenêtré, alors c'est facile: m_hWndCD.

Dans le cas contraire, vous devez avoir une fenêtre, alors vous avez m_bWindowOnly pour marquer dans le constructeur et indiquer que vous aurez besoin d'un HWND:

drapeau indiquant le contrôle doit être fenêtré, même si le conteneur supporte sans fenêtre contrôles.

Si vous voulez encore sans fenêtre et ont besoin d'une fenêtre juste parfois, sous certaines conditions qui se présentent à l'exécution, vous avez toujours la possibilité de créer un message privé message only window et expédition à travers elle.

3

Voici un code extrait de l'exemple Direct3D ATL de Microsoft. Je ne l'ai pas encore testé.

// Get the window we need to use. This will either be the window that has already 
// been created if we are window. If we are windowless the HWND of the client 
// will be retrieved from the HDC. 
void GetOurWindow() 
{ 
    // If we're windowless we still need an HWND for Direct3d 
    if (m_bWndLess) 
    { 
     HDC hDC; 

     // Get the HDC from the client 
     m_spInPlaceSite->GetDC(NULL, OLEDC_NODRAW, &hDC); 
     m_hOurWnd = WindowFromDC(hDC); 
    #if 1 
     // Code to make VB5 paint properly now it has clipped it's own hDC 
     RECT rect; 
     ::GetClientRect(m_hOurWnd,&rect); 
     HRGN hRegion = CreateRectRgn(rect.left,rect.top,rect.right,rect.bottom); 
     SelectClipRgn(hDC,hRegion); 
    #endif 
     m_spInPlaceSite->ReleaseDC(hDC); 
    } 
    else 
     m_hOurWnd = m_hWnd; 
} 
Questions connexes