How to add button?

Login to reply to this topic.
Thu, 2006-02-23 19:39
Joined: 2006-02-23
Forum posts: 5
Hello.
I'm a beginer in develope.
I want to write a simple application.
But I don't know how to add button.
in C# it is very easy
Button btn1 = new Button();
Button.text = "Button 1";
Button.parent = this; or (Controls.Add(btn1));
But how the same thing make in the C in CodeWarrior.
Thx

Fri, 2006-02-24 10:23
Joined: 2004-12-23
Forum posts: 239
Re: How to add button?
Hi Mastahh,
U can try with following lines
Code:
iCmdBtn = new (ELeave) CEikCommandButton();
     iCmdBtn->SetContainerWindowL(*this);
     iCmdBtn->SetTextL(_L("Button Name"));
     //iCmdOkBtn->GetColor(TLogicalColor::EColorControlText,TRgb::Red);
     iCmdOkBtn->SetObserver((MCoeControlObserver*)this);
     iCmdOkBtn->SetExtent(TPoint(10,22), TSize(110,35));

BR


   


---------------
Bhatt Kavita

Fri, 2006-02-24 11:01
Joined: 2006-02-23
Forum posts: 5
Re: How to add button?
Thx for answer But i have error with this code.


Code:
void CGameAppView::ConstructL(const TRect& aRect)
    {
    // Create a window for this application view
    CreateWindowL();

    // Set the windows size
    SetRect(aRect);
   
   
     iCmdBtn = new (ELeave) CEikCommandButton();
     iCmdBtn->SetContainerWindowL(*this);
     iCmdBtn->SetTextL(_L("Button Name"));
     //iCmdOkBtn->GetColor(TLogicalColor::EColorControlText,TRgb::Red);
     iCmdOkBtn->SetObserver((MCoeControlObserver*)this);
     iCmdOkBtn->SetExtent(TPoint(10,22), TSize(110,35));

    // Activate the window, which makes it ready to be drawn
    ActivateL();
    }



error
Warning : tool exit status == 1

Error   : undefined identifier 'iCmdBtn'
GameAppView.cpp line 49   

Error   : undefined identifier 'iCmdBtn'
GameAppView.cpp line 50   

Error   : undefined identifier 'iCmdBtn'
GameAppView.cpp line 51   

Error   : undefined identifier 'iCmdOkBtn'
GameAppView.cpp line 53   

Error   : undefined identifier 'iCmdOkBtn'
GameAppView.cpp line 54   

Error   : Compile failed


Fri, 2006-02-24 13:33
Joined: 2004-12-23
Forum posts: 239
Re: How to add button?
Hi Mastahh

Don't forget to include "eikcmbut.h" file and its corresponding lib "eikcoctl.lib" and then create its instance in your header file like

//.h file

CEikCommandButton* iCmdBtn;

//.cpp
In .cpp file use like this
iCmdBtn = new (ELeave) CEikCommandButton();
....
.....

And sorry for my above post ,by mistake I type the variable wrong.It is iCmdBtn not iCmdBtnOk.
And yeah don't forgot to put .lib in ur mmp file.and then compile afresh.

Cheers

---------------
Bhatt Kavita

Fri, 2006-02-24 19:30
Joined: 2006-02-23
Forum posts: 5
Re: How to add button?
Thx for help.
Now i can compile it.
But i did not see the button and how to change Application name?
Mon, 2006-02-27 13:44
Joined: 2006-02-23
Forum posts: 5
Re: How to add button?
Maybe i must do something like this?
Control().AppendL(iCmdBtn);
?
  • Login to reply to this topic.