Click here to Skip to main content
Licence 
First Posted 11 Feb 2006
Views 18,498
Bookmarked 9 times

Method cast for WTL classes

By | 11 Feb 2006 | Article
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:

 

CMyClass::MyFunction(HWND hWnd)

{

            CScrollView * p = (CScrollView *) CScrollView::FromHandle(hWnd);

            CPoint ptScroll = pScroll->GetScrollPosition();

}

 

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.

 

class CScrollView : public CScrollWindowImpl<CScrollView>

{

public:

            CScrollView(HWND hWnd){ m_hWnd = hWnd; }

};

 

And then in MyFunction method we make

 

CMyClass::MyFunction(HWND hWnd)

{

            ……

            CScrollView tScroll(hWnd);

            POINT pt;

            tScroll.GetScrollOffset(pt);

            WTL::CPoint ptScroll(pt);

     

}

 

 

 

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

About the Author

michaelvy

Web Developer

Israel Israel

Member



Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralAttach PinmemberJörgen Sigvardsson2:38 12 Feb '06  
GeneralRe: Attach Pinmembermichaelvy3:04 12 Feb '06  

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

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

Permalink | Advertise | Privacy | Mobile
Web04 | 2.5.120517.1 | Last Updated 12 Feb 2006
Article Copyright 2006 by michaelvy
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid