|
#pragma once
#include "MappedFileAllocator.hpp"
namespace ScreenScrape {
namespace detail {
/// traits for reading the text of a tab control
struct TabTraits
{
typedef int item_type;
static wchar_t* ClassName() { return WC_TABCONTROL; };
static bool CheckValiditiy( HWND target, DWORD timeout = INFINITE )
{
DWORD item_count = 0;
if( ::SendMessageTimeout( target,
TCM_GETITEMCOUNT,
0,
0,
SMTO_NORMAL,
timeout,
&item_count ) > 0 )
{
return item_count > 0;
}
return false;
};
static BOOL LocateItem( HWND target,
const POINT& pt,
item_type* item,
DWORD timeout = INFINITE )
{
MappedBuffer tch_buffer( sizeof( TCHITTESTINFO ) );
TCHITTESTINFO* tch =
reinterpret_cast< TCHITTESTINFO* >( &tch_buffer.front() );
tch->pt = pt;
item_type it;
if( ::SendMessageTimeout( target,
TCM_HITTEST,
0,
reinterpret_cast< LPARAM >( tch ),
SMTO_NORMAL,
timeout,
reinterpret_cast< DWORD* >( &it ) ) > 0 )
{
if( it > -1 )
{
*item = it;
return true;
}
}
return false;
};
static DWORD GetTextLength( HWND /*target*/,
const item_type& /*item*/,
DWORD /*timeout*/ = INFINITE )
{
return 260;
};
static bool GetText( HWND target,
const item_type& item,
DWORD length,
std::wstring* text,
DWORD timeout = INFINITE )
{
MappedBuffer tc_buffer( sizeof( TCITEM ) + sizeof( wchar_t ) * length );
TCITEM* tc = reinterpret_cast< TCITEM* >( &tc_buffer.front() );
tc->cchTextMax = length;
tc->mask = TCIF_TEXT;
tc->pszText = reinterpret_cast< wchar_t* >(
&tc_buffer.front() + sizeof( TCITEM ) );
BOOL success = FALSE;
if( ::SendMessageTimeout( target,
TCM_GETITEM,
item,
reinterpret_cast< LPARAM >( tc ),
SMTO_NORMAL,
timeout,
reinterpret_cast< DWORD* >( &success ) ) > 0 )
{
if( success )
{
*text = tc->pszText;
return true;
}
}
return false;
}
private:
/// a sequential byte-buffer backed by a memory-mapped file.
typedef std::vector< byte, MappedFileAllocator< byte > > MappedBuffer;
}; // struct TabTraits
}; // namespace detail
}; // namespace ScreenScrape
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.