|
#pragma once
#include "MappedFileAllocator.hpp"
namespace ScreenScrape {
namespace detail {
/// traits for reading the text in a listbox control
struct ListBoxTraits
{
typedef DWORD item_type;
static wchar_t* ClassName() { return L"listbox"; };
static bool CheckValiditiy( HWND target, DWORD timeout = INFINITE )
{
DWORD item_count = 0;
if( ::SendMessageTimeout( target,
LB_GETCOUNT,
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 )
{
LPARAM lp = pt.y << 16 | pt.x;
item_type it;
if( ::SendMessageTimeout( target,
LB_ITEMFROMPOINT,
0,
lp,
SMTO_NORMAL,
timeout,
&it ) > 0 )
{
if( HIWORD( it ) == 0 && LOWORD( it ) > -1 )
{
*item = it;
return true;
}
}
return false;
};
static DWORD GetTextLength( HWND target,
const item_type& item,
DWORD timeout = INFINITE )
{
DWORD text_length = 0;
if( ::SendMessageTimeout( target,
LB_GETTEXTLEN,
item,
0,
SMTO_NORMAL,
timeout,
&text_length ) > 0 )
{
return text_length;
}
return 0;
};
static bool GetText( HWND target,
const item_type& item,
DWORD length,
std::wstring* text,
DWORD timeout = INFINITE )
{
MappedBuffer lb_buffer( ( length + 1 ) * sizeof( wchar_t ) );
wchar_t* result = reinterpret_cast< wchar_t* >( &lb_buffer.front() );
DWORD text_length = 0;
if( ::SendMessageTimeout( target,
LB_GETTEXT,
item,
reinterpret_cast< LPARAM >( result ),
SMTO_NORMAL,
timeout,
&text_length ) > 0 )
{
*text = result;
return true;
}
return false;
};
private:
/// a sequential byte-buffer backed by a memory-mapped file.
typedef std::vector< byte, MappedFileAllocator< byte > > MappedBuffer;
}; // struct ListBoxTraits
}; // 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.