This section of the archives stores flipcode's complete Developer Toolbox collection, featuring a variety of mini-articles and source code contributions from our readers.

 

  Windows Template Library (WTL)
  Submitted by



For ones who doesn't know about WTL WTL as defined by Microsoft is A library for developing Windows(r) applications and UI components. Extends ATL (Active Template Library) and provides a set of classes for controls, dialogs, frame windows, GDI objects, and more. or in other words awsome piece of templated C++ code that wraps

In its heart WTL based on ATL CWindow class, and is actually extension of ATL. WTL provides UI framework much like MFC but not forces you into Doc/View model, doesn't have any run-time overheads and doesn't need any Dlls. Whole WTL comes in a header files, so everything gets nicely inlined and code written with the WTL runs as fast as code written with a native Win32 API. Unfortunatly for some unknown reason, Microfosft don't want to actively support the WTL, neither provide any documentation for it, they just released source as is, which is strange, they rarely do such a things. But WTL is soo simple that almost no documentation needed except basic stuff, contained in the ATL documentation. All my experience with WTL in my project was simply a joy! It's almost as fast as with MFC to get complex UI working, and it runs Fast (as opposite to MFC). The best thing about the WTL is that it extends Win32 API but not replace,you can always use Win32Api function in any place instead of WTL, and they perfectly live together, Most of the WTL classes can be manipulated in the same way as win32 handles and can be substituted in win32api calls. Give it a try on next UI you make. <die>MFC<die> Few WTL usage examples:
// Create Tooltip.
CtoolTipCtrl tooltip;
tooltip.Create(m_hWnd,rcDefault,NULL,WS_POPUP|TTS_NOPREFIX|TTS_NOFADE|TTS_NOANIMATE,0 );
tooltip.SetDelayTime(TTDT_INITIAL,0);
tooltip.SetDelayTime(TTDT_RESHOW,0);

// Create rebar. CReBarCtrl m_bar; CRect rc( 0,0,100,100 ); m_bar.Create( m_hWnd,rc,"WebRebar",WS_CHILD|WS_VISIBLE|WS_CLIPCHILDREN|CCS_TOP|RBS_BANDBORDERS|CCS_NODIVIDER,0 );

// Init toolbar. CImageList img; CToolBarCtrl m_navigationBar; m_navigationBar.Create( m_bar.m_hWnd,rc,NULL,CCS_NODIVIDER|CCS_NOPARENTALIGN|CCS_NORESIZE|WS_CHILD| TBSTYLE_FLAT|TBSTYLE_TRANSPARENT|TBSTYLE_TOOLTIPS ); img.Create(IDB_HOTTOOLBAR_WEB, 22, 0, RGB(255, 0, 255)); m_navigationBar.SetPadding( 6,6 ); m_navigationBar.SetHotImageList( img ); img.Detach(); img.Create(IDB_COLDTOOLBAR_WEB, 22, 0, RGB(255, 0, 255)); m_navigationBar.SetImageList( img ); img.Detach();

// Init address bar at web rebar. CRect arc( 0,0,200,120 ); m_addressBar.Create( m_bar.m_hWnd,arc,NULL,CBS_DROPDOWN|WS_CHILD|WS_VISIBLE ); memset( &bi,0,sizeof(bi) ); bi.cbSize = sizeof(REBARBANDINFO); bi.lpText = "Address"; bi.fStyle = RBBS_GRIPPERALWAYS; bi.fMask = RBBIM_TEXT|RBBIM_CHILD|RBBIM_CHILDSIZE|RBBIM_STYLE;

bi.cxMinChild = 60; bi.cyMinChild = 0; bi.cyMaxChild = 10; bi.hwndChild = m_addressBar.m_hWnd;

m_bar.InsertBand(m_bar.GetBandCount(),&bi);

// Draw some stuff. Cbrush brush; brush.CreateSolidBrush( 0x11223344 ); CPen pen; pen.CreatePen( PS_SOLID,0, 0x11223344 );

CPen prevPen = dc.SelectPen( pen ); CBrush prevBrush = dc.SelectBrush( brush );

dc.Ellipse( p.x-m_itemSize-2,p.y-m_itemSize-2,p.x+m_itemSize+2,p.y+m_itemSize+2 ); dc.SetTextColor( 0xFFFFFFFF ); dc.SelectFont( (HFONT)GetStockObject(ANSI_VAR_FONT) ); string text = item-getName(); SIZE sz; dc.GetTextExtent( text,text.size(),&sz ); dc.ExtTextOut( pt.x,pt.y,ETO_CLIPPED,rc,text );



WTL souce located at Microsoft Platform SDK\Src\Wtl (in MSDN)
For more info about WTL see http://www.codeproject.com/wtl


The zip file viewer built into the Developer Toolbox made use of the zlib library, as well as the zlibdll source additions.

 

Copyright 1999-2008 (C) FLIPCODE.COM and/or the original content author(s). All rights reserved.
Please read our Terms, Conditions, and Privacy information.