Thursday, June 18, 2009

SYMBIAN C++ Tutorial

Symbian C++ in developing GUI APPS

Syntax


RESOURCE {
= ;
[ = ; ...]
}

Here the is defined in files included from some .rh files. For example we can have MENU_BAR, MENU_PANE and so on.

Each can have a scalar value, a list value or a struct value. A scalar value is a number or a string. A list value is a sequence enclosed in braces. Examples:

name = "Hello" ;
list = { 1 , 2, 3 };

A struct value has this syntax:

{
= ;
[ = ; ...]
}

Where can be a scalar, list or structure value, so the structure can nest. Here is a complete (and real) example:

RESOURCE MENU_PANE r_simplemenu_menu_pane
{
items =
{
MENU_ITEM
{
command = ESimpleMenuCmdNewGame;
txt = NEW_GAME_TEXT;
cascade = r_simplemenu_game_submenu_menu_pane;
},
MENU_ITEM
{
command = CmdExit;
txt = EXIT_TEXT;
}
};
}

Creating a MENU in Symbian C++

RESOURCE MENU_BAR r_demo_menubar {
titles = {
MENU_TITLE {
menu_pane = r_demo_menu;
}
};
}

Then the menu pane:

RESOURCE MENU_PANE r_demo_menu {
{
items = {
MENU_ITEM {
command = EHelloWorldCommand1;
txt = COMMAND_ONE;
},
MENU_ITEM {
command = EAknCmdExit;
txt = text_softkey_exit;
}
};
}
}

Note the EHelloWorldCommand1 coming from the .hrh and COMMAND_ONE included from .loc



Creating a LISTBOX

RESOURCE LISTBOX r_list_listbox {
array_id = r_list_items;
flags = EAknListBoxSelectionList;
}
RESOURCE ARRAY r_list_items {
items =
{
LBUF { txt = "tFirst"; },
LBUF { txt = "xtSecond"; },
LBUF { txt = "tThird"; }
};
}

Now the code to create a list object. In the class we declare CAknColumnListBox* iListBox;, then in the HelloAppView::ConstrucL(), we create and load resource is it as follows:

TResourceReader reader;
iEikonEnv->CreateResourceReaderLC(reader, R_LIST_LISTBOX);
iListBox->ConstructFromResourceL(reader);
CleanupStack:PopAndDestroy(); // reader

The following is the code needed to display the listbox in the view.

void CHelloAppView::SizeChanged() {
iListBox->SetExtent (TPoint(0,0), iListBox->MinimumSize());
}
TInt CHelloAppView::CountComponentControls() const {
return 1;
}
CCoeControl* CHelloAppView::ComponentControl(TInt aIndex) const {
switch(aIndex) {
case 0: return iListBox;
default: return NULL;
}
}


#define M_SHOP_REMOVE_PROMPT "Are you sure to remove?"

The resource for a confirmation query is:

RESOURCE DIALOG r_shop_confirmation_query
{
flags=EGeneralQueryFlags;
buttons = R_AVKON_SOFTKEYS_YES_NO;
items =
{
DLG_LINE
{
type = EAknCtQuery;
id = EListDlgCId1;
control = AVKON_CONFIRMATION_QUERY
{
layout = EConfirmationQueryLayout;
label = M_SHOP_REMOVE_PROMPT;
};
}
};
}
RESOURCE TBUF r_shop_data_query_prompt
{
buf = M_SHOP_ADD_PROMPT;
}

Bluetooth GPS(Global Positioning System) device using C++ Mobile on a Symbian Series 60 cellphone

MY CODE

void Cbttest1Container::OniBtDiscovery1DeviceFound( CBase * aDiscovery )
{
_LIT(KDeviceFound, "Device Found");
iEikLabel1->SetTextL(KDeviceFound);
this->DrawDeferred();

CSdpSearchPattern * list = CSdpSearchPattern::NewL( );
list->AddL( 0x1101 );
iBtSdpQuery1->SetSearchPattern(list);
CSdpAttrIdMatchList * matchList = CSdpAttrIdMatchList::NewL( );
matchList->AddL( TAttrRange( KSdpAttrIdProtocolDescriptorList ) );
iBtSdpQuery1->SetAttrIdMatchList(matchList);
iBtSdpQuery1->StartNextSdpL(iBtDiscovery1->BDAddr());
}

No comments:

Post a Comment