Click here to Skip to main content
15,885,216 members
Articles / Desktop Programming / WTL
Article

Method cast for WTL classes

Rate me:
Please Sign up or sign in to vote.
1.00/5 (13 votes)
11 Feb 2006 27K   9   2
Method cast for WTL classes

Introduction

There is often a need to obtain the base class function from a parameter of the type HWND. How can this be done, if it is not possible to use the static_cast method ?

This problem can be solved sufficiently simply for MFC. For example, for CScrollView, you should obtain the function method GetScrollPosition(). This is solved simply for MFC:

<o:p> 

CMyClass::MyFunction(HWND hWnd)<o:p>

{<o:p>

            CScrollView * p = (CScrollView *) CScrollView::FromHandle(hWnd);<o:p>

            CPoint ptScroll = pScroll->GetScrollPosition();<o:p>

}

<o:p> 

How can the analogous problem be solved in WTL?.

Let us assume we need to obtain the function 

void GetScrollOffset( POINT& ptOffset)

public class CScrollWindowImpl from a parameter of the type hWnd. We create the prototype of the class of the parameter.

<o:p> 

class CScrollView : public CScrollWindowImpl<CScrollView><o:p>

{<o:p>

public:<o:p>

            CScrollView(HWND hWnd){ m_hWnd = hWnd; }<o:p>

};<o:p>

<o:p> 

And then in MyFunction method we make

<o:p> 

CMyClass::MyFunction(HWND hWnd)<o:p>

{<o:p>

            ……<o:p>

            CScrollView tScroll(hWnd);<o:p>

            POINT pt;<o:p>

            tScroll.GetScrollOffset(pt);<o:p>

            WTL::CPoint ptScroll(pt);<o:p>

     

}<o:p>

<o:p> 

 

 

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
Israel Israel
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralAttach Pin
Jörgen Sigvardsson12-Feb-06 2:38
Jörgen Sigvardsson12-Feb-06 2:38 
GeneralRe: Attach Pin
michaelvy12-Feb-06 3:04
michaelvy12-Feb-06 3:04 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.