Category : C++ Source Code
Archive   : ODRBTN.ZIP
Filename : RBTNTEST.CPP

 
Output of file : RBTNTEST.CPP contained in archive : ODRBTN.ZIP

// ObjectWindows - (C) Copyright 1991 by Borland International

// ==================================================================
//
// rbtntest.cpp - test harness for bitmap radiobuttons
// Colin Robertson, Digital Systems
// CIS: 70550,3306
// Internet: [email protected]
//
// "If it happens, it must be possible."
// Thanks to John Williams for some sample sources.
// ==================================================================

#include
#include
#include
#include

const WORD ID_RBUTTON1 = 401;
const WORD ID_RBUTTON2 = 402;
const WORD ID_RBUTTON3 = 403;
const WORD ID_GROUPBOX = 105;

class TRadioBitmap : public TBRadioButton
{
HBITMAP hBtnUp, hBtnDown, hBtnUpF, hBtnDownF, hBtnGray;
enum ResourceOffset{ UpNoFocus = 1000, DnFocus = 3000, UpFocus = 5000,
DnNoFocus = 7000, Grayed = 9000 };
public:
TRadioBitmap( PTWindowsObject AParent, int AnId, LPSTR AText, int X,
int Y, int W, int H, PTGroupBox AGroup, PTModule AModule = NULL );
~TRadioBitmap();
protected:
virtual void WMDrawItem( RTMessage Msg ) = [WM_FIRST + WM_DRAWITEM];
};

class TTestApp : public TApplication
{
public:
TTestApp( LPSTR AName, HANDLE hInstance, HANDLE hPrevInstance, LPSTR lpCmdLine, int nCmdShow )
: TApplication( AName, hInstance, hPrevInstance, lpCmdLine, nCmdShow ) {};
virtual void InitMainWindow();
};

class TTestWindow : public TWindow
{
public:
TRadioBitmap *RTButton1, *RTButton2, *RTButton3;
TBGroupBox *GroupBox;

TTestWindow( PTWindowsObject AParent, LPSTR ATitle );
};

// TRadioBitmap ------------------------------------------------------------

TRadioBitmap::TRadioBitmap(
PTWindowsObject AParent, int AnId, LPSTR AText, int X,
int Y, int W, int H, PTGroupBox AGroup, PTModule AModule)
: TBRadioButton( AParent, AnId, AText, X, Y, W, H, AGroup, AModule )
{
Attr.Style = BS_AUTORADIOBUTTON | BBS_OWNERDRAW | WS_CHILD | WS_VISIBLE ;

HANDLE hInstance = GetApplication()->hInstance;
hBtnUp = LoadBitmap( hInstance, MAKEINTRESOURCE( UpNoFocus + AnId ));
hBtnDown = LoadBitmap( hInstance, MAKEINTRESOURCE( DnNoFocus + AnId ));
hBtnUpF = LoadBitmap( hInstance, MAKEINTRESOURCE( UpFocus + AnId ));
hBtnDownF = LoadBitmap( hInstance, MAKEINTRESOURCE( DnFocus + AnId ));
hBtnGray = LoadBitmap( hInstance, MAKEINTRESOURCE( Grayed + AnId ));

BITMAP bitMap;
GetObject( hBtnUp, sizeof( bitMap ), (LPSTR)&bitMap );
Attr.W = bitMap.bmWidth + 4;
Attr.H = bitMap.bmHeight + 4;
}

TRadioBitmap::~TRadioBitmap()
{
DeleteObject( hBtnUp );
DeleteObject( hBtnDown );
DeleteObject( hBtnUpF );
DeleteObject( hBtnDownF );
DeleteObject( hBtnGray );
}

void TRadioBitmap::WMDrawItem( RTMessage Msg )
{
LPDRAWITEMSTRUCT lpdis = (LPDRAWITEMSTRUCT)Msg.LParam;
HBITMAP hbmp;

// select the bitmap to draw
switch ( GetCheck() )
{
case BF_CHECKED:
hbmp = (( lpdis->itemState & ODS_FOCUS ) ? hBtnDownF : hBtnDown );
break;
case BF_UNCHECKED:
hbmp = (( lpdis->itemState & ODS_FOCUS ) ? hBtnUpF : hBtnUp );
break;
default:
hbmp = hBtnGray;
break;
}

// draw black border around button if selected, ltgray otherwise
RECT rc;
SetRect( &rc, lpdis->rcItem.left, lpdis->rcItem.top,
lpdis->rcItem.left + Attr.W,
lpdis->rcItem.top + Attr.H );
FillRect( lpdis->hDC, &rc, GetStockObject(
( lpdis->itemState & ODS_SELECTED ) ?
BLACK_BRUSH : LTGRAY_BRUSH ));

// draw the bitmap
HDC hDCmem = CreateCompatibleDC( lpdis->hDC );
SelectObject( hDCmem, hbmp );
BitBlt( lpdis->hDC, lpdis->rcItem.left + 2, lpdis->rcItem.top + 2,
Attr.W - 2, Attr.H - 2, hDCmem, 0, 0, SRCCOPY );
DeleteDC( hDCmem );
}



// TestWindow ------------------------------------------------------

TTestWindow::TTestWindow( PTWindowsObject AParent, LPSTR ATitle )
: TWindow( AParent, ATitle )
{
GroupBox = new TBGroupBox( this, ID_GROUPBOX, "Group Box",
158, 102, 206, 168 );
RTButton1 = new TRadioBitmap( this, ID_RBUTTON1, "&Table",
174, 128, 138, 24, GroupBox );
RTButton2 = new TRadioBitmap( this, ID_RBUTTON2, "&Chart",
174, 162, 138, 24, GroupBox );
RTButton3 = new TRadioBitmap( this, ID_RBUTTON3, "&Pie",
174, 192, 138, 24, GroupBox );
EnableKBHandler();
}


void TTestApp::InitMainWindow()
{
BWCCGetVersion();
MainWindow = new TTestWindow( NULL, Name );
}

int PASCAL WinMain(
HANDLE hInstance,
HANDLE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow )
{
TTestApp TestApp( "TRadioBitmap Tester", hInstance, hPrevInstance,
lpCmdLine, nCmdShow);
TestApp.Run();
return TestApp.Status;
}