/**** ファイル名 : BaseApp.h ****/
#ifndef BASEAPP #define BASEAPP //--------------------------------------------------------------------- #include <Be.h> #include "MainWindow.h" //--------------------------------------------------------------------- #define APPLICATION_SIGNATURE "application/x-vnd.vow-be2ndapp" //--------------------------------------------------------------------- class BaseApp : public BApplication { public: BaseApp() :BApplication(APPLICATION_SIGNATURE) { BAppMainWindow *mainwnd=new BAppMainWindow( BRect(MAINWINDOW_POSITION_LEFT,MAINWINDOW_POSITION_TOP, MAINWINDOW_POSITION_WIDTH+MAINWINDOW_POSITION_LEFT-1, MAINWINDOW_POSITION_HEIGHT+MAINWINDOW_POSITION_TOP-1), MAINWINDOW_TITLE); mainwnd->Show(); }; }; //--------------------------------------------------------------------- #endif
/**** ファイル名 : MainWindow.h ****/
#ifndef MAINWINDOW #define MAINWINDOW //--------------------------------------------------------------------- #include <Be.h> //--------------------------------------------------------------------- #define MAINWINDOW_TITLE "RadioButton,CheckBox Application" #define MAINWINDOW_POSITION_LEFT 100 #define MAINWINDOW_POSITION_TOP 100 #define MAINWINDOW_POSITION_WIDTH 400 #define MAINWINDOW_POSITION_HEIGHT 320 #define MAINWINDOW_WINDOWSTYLE (B_TITLED_WINDOW) //--------------------------------------------------------------------- #define MSG_SET 'setb' //--------------------------------------------------------------------- class BAppMainView : public BView { public: BRadioButton *rbuttons_a[3],*rbuttons_b[3]; BStringView *strview; BCheckBox *chkbox_a,*chkbox_b; BAppMainView(BRect frame); }; //--------------------------------------------------------------------- class BAppMainWindow : public BWindow { public: BAppMainView *mainview; //----------------------------------------------------------------- BAppMainWindow(BRect frame,const char *title); virtual void MessageReceived(BMessage *msg); //----------------------------------------------------------------- bool QuitRequested() { be_app->PostMessage(B_QUIT_REQUESTED); return true; }; }; //--------------------------------------------------------------------- int GetSelectionIndex(BRadioButton *rbuttons[],int button_max); //--------------------------------------------------------------------- #endif
/**** ファイル名 : MainWindow.cpp ****/
//--------------------------------------------------------------------- #include "MainWindow.h" //--------------------------------------------------------------------- BAppMainWindow::BAppMainWindow(BRect frame,const char *title) :BWindow(frame,title,MAINWINDOW_WINDOWSTYLE,0) { mainview=new BAppMainView(Bounds()); AddChild(mainview); } //--------------------------------------------------------------------- void BAppMainWindow::MessageReceived(BMessage *msg) { switch(msg->what) { case MSG_SET: char wk[256]; sprintf(wk,"Group A=%d,Group B=%d,Check A=%d,Check B=%d", GetSelectionIndex(mainview->rbuttons_a,3), GetSelectionIndex(mainview->rbuttons_b,3), (int)mainview->chkbox_a->Value(), (int)mainview->chkbox_b->Value()); mainview->strview->SetText(wk); break; default: BWindow::MessageReceived(msg); } } //--------------------------------------------------------------------- BAppMainView::BAppMainView(BRect frame) :BView(frame,"bappmainview",B_FOLLOW_ALL,B_WILL_DRAW) { BRect viewrect(Bounds()); BRect boxrect; struct { char name[16]; char text[16]; } rb_a[3]={{"rb_a1","ABCDE"},{"rb_a2","FGHIJ"},{"rb_a3","KLMNO"}}, rb_b[3]={{"rb_b1","123"},{"rb_b2","456"},{"rb_b3","789"}}; BMessage *setmsg=new BMessage(MSG_SET); BButton *btn= new BButton(BRect(viewrect.right-68,248,viewrect.right-8,260), "btn1","SET!!",setmsg); AddChild(btn); strview=new BStringView(BRect(8,248,viewrect.right-70,260), "strview","No Data"); AddChild(strview); BBox *box1=new BBox(BRect(8,8,viewrect.right-8,90),"box1"); box1->SetLabel("Group A"); AddChild(box1); boxrect=box1->Bounds(); for(int i=0;i<3;i++) { rbuttons_a[i]= new BRadioButton(BRect(8,16+20*i,boxrect.right-8,16+20*(i+1)), rb_a[i].name,rb_a[i].text,NULL); box1->AddChild(rbuttons_a[i]); } BBox *box2=new BBox(BRect(8,98,viewrect.right-8,180),"box2"); box2->SetLabel("Group B"); AddChild(box2); boxrect=box2->Bounds(); for(int i=0;i<3;i++) { rbuttons_b[i]= new BRadioButton(BRect(8,16+20*i,boxrect.right-8,16+20*(i+1)), rb_b[i].name,rb_b[i].text,NULL); box2->AddChild(rbuttons_b[i]); } chkbox_a=new BCheckBox(BRect(8,188,viewrect.right-8,210),"chkbox1", "Check A",NULL); AddChild(chkbox_a); chkbox_b=new BCheckBox(BRect(8,218,viewrect.right-8,230),"chkbox2", "Check B",NULL); AddChild(chkbox_b); } //--------------------------------------------------------------------- int GetSelectionIndex(BRadioButton *rbuttons[],int button_max) { int result=-1; for(int i=0;i<button_max && result==-1;i++) if(rbuttons[i]->Value()==B_CONTROL_ON) result=i; return result; } //---------------------------------------------------------------------
/**** ファイル名 : main.cpp ****/
//--------------------------------------------------------------------- #include "BaseApp.h" //--------------------------------------------------------------------- int main(void) { new BaseApp(); be_app->Run(); delete be_app; return true; } //---------------------------------------------------------------------
チェックボックスやラジオボタンのValue関数は、選択された状態であれば、 B_CONTROL_ONを返します。sprintf(wk,"Group A=%d,Group B=%d,Check A=%d,Check B=%d", GetSelectionIndex(mainview->rbuttons_a,3), GetSelectionIndex(mainview->rbuttons_b,3), (int)mainview->chkbox_a->Value(), (int)mainview->chkbox_b->Value());
圧縮ファイル R5 Intel環境で確認 |
Be2ndApp19991206.zip |
ソースファイル | |
BaseApp.h | |
main.cpp | |
MainWindow.cpp | |
MainWindow.h |