#include "src/WKGL.h" using namespace wkgl; BOOL OnAddText( Component*, UINT, WPARAM, LPARAM ); BOOL OnShowSelected( Component*, UINT, WPARAM, LPARAM ); BOOL OnShowElements( Component*, UINT, WPARAM, LPARAM ); ListBox *lb; Edit *edit1; WPARAM main() { Window win( "Test Edit" ); Static s1( "Type some text:", AUTOPOS, AUTOPOS ); Static s2( "Choose an option: ", AUTOPOS, AUTOPOS ); edit1 = new Edit( AUTOPOS, AUTOPOS, 10 ); Button b1( "Add Text", AUTOPOS, AUTOPOS ); Button b2( "Show Selected Element", AUTOPOS, AUTOPOS ); Button b3( "Show All Elements", AUTOPOS, AUTOPOS ); lb = new ListBox( AUTOPOS, AUTOPOS, 20, 10 ); LAYOUT_INFO linfo; linfo.hgap = 5; linfo.vgap = 5; linfo.client.top = 0; linfo.client.left = 0; linfo.client.right = win.getWidth(); linfo.client.bottom = win.getHeight(); LayoutManager lm( &win, linfo, FormLayout ); lm.add( &s1 ); lm.add( edit1 ); lm.add( &s2 ); lm.add( lb ); win.add( &s1 ); win.add( edit1 ); win.add( &s2 ); win.add( lb ); linfo.client = lm.layout(); linfo.client.top = linfo.client.bottom + linfo.vgap; LayoutManager lm2( &win, linfo, FlowLayoutR ); lm2.add( &b1 ); lm2.add( &b2 ); lm2.add( &b3 ); win.add( &b1 ); win.add( &b2 ); win.add( &b3 ); win.show(); //Add the callbacks b1.addCallBack( OnAddText ); b2.addCallBack( OnShowSelected ); b3.addCallBack( OnShowElements ); WPARAM param = win.beginMessageLoop(); delete lb; delete edit1; return param; } BOOL OnAddText( Component *com, UINT message, WPARAM wParam, LPARAM lParam ) { if ( message == BN_CLICKED ) { char buf[100]; edit1->getText( buf, 100 ); lb->addString( buf ); return TRUE; } return FALSE; } BOOL OnShowElements( Component *com, UINT message, WPARAM wParam, LPARAM lParam ) { if ( message == BN_CLICKED ) { char buf[1000]; buf[0] = 0; for ( int i = 0; i < lb->getNumberOfItems(); i++ ) { strcat( buf, lb->getString( i ) ); strcat( buf, "\n" ); } showMessageBox( com, buf ); return TRUE; } return FALSE; } BOOL OnShowSelected( Component *com, UINT message, WPARAM wParam, LPARAM lParam ) { if ( message == BN_CLICKED ) { showMessageBox( com, lb->getSelectedString() ); return TRUE; } return FALSE; }