|
이현진 님이 쓰신 글 :
: 또아리 님이 쓰신 글 :
: : TComponentList 등을 이용해서 폼/판넬들을 등록은 어떻게 하나요?...좀 제가 보기에 어렵게 되어 있는 코드 같은데 설명좀 해주시면 안될까요? 죄송합니다..(__)
: :
:
: TComponentList에 메뉴에 사용할 폼들을 추가하고, for 등의 반복문을 통해서 원하는 폼은 TForm::Show() 함수를 호출하고, 나머지는 TForm::Hide() 함수를 호출하면 됩니다.
:
: 첨부한 테스트 소스를 참고하세요.
: (Turbo C++ Explorer 에서 작성한 것입니다.)
:
: ///////////////////////////////////////////////////////////////////////////////////////////
: // 헤더
: #define WM_USER_INITIALIZE_MENU WM_USER+100
:
: class TMainForm : public TForm
: {
: /*** 생략 ***/
: private: // User declarations
: TComponentList* screen_list;
:
: void __fastcall InitializeMenu(void);
: void __fastcall ShowMenuForm(TForm* _form);
: void __fastcall ShowMenu(int _index);
: /*** 생략 ***/
: };
: //---------------------------------------------------------------------------
:
: ///////////////////////////////////////////////////////////////////////////////////////////
: // 소스
: __fastcall TMainForm::TMainForm(TComponent* Owner)
: : TForm(Owner)
: , screen_list(NULL)
: {
: }
: //---------------------------------------------------------------------------
:
: void __fastcall TMainForm::InitializeMenu(void)
: {
: try
: {
: if(screen_list==NULL)
: {
: screen_list=new TComponentList;
: screen_list->OwnsObjects=false;
: } else
: {
:
: screen_list->Clear();
: }
:
: // 메뉴 목록에 폼 추가.
: screen_list->Add(Menu0Form);
: screen_list->Add(Menu1Form);
: screen_list->Add(Menu2Form);
: screen_list->Add(Menu3Form);
:
: // 메뉴 선택 버튼 초기화.
: MenuRadioGroup->Items->Clear();
: MenuComboBox->Items->Clear();
: MenuListBox->Items->Clear();
: for(int index=0; index<screen_list->Count; ++index)
: {
: TForm* form=dynamic_cast<TForm*>(screen_list->Items[index]);
: if(form!=NULL)
: {
: form->Parent=MainPanel;
: form->Width=320;
: form->Height=240;
: form->Left=0;
: form->Top=0;
: form->Hide();
:
: MenuRadioGroup->Items->Add(form->Caption);
: MenuComboBox->Items->Add(form->Caption);
: MenuListBox->Items->Add(form->Caption);
: }
: }
:
: ShowMenu(0);
: } catch(...) {}
: }
: //---------------------------------------------------------------------------
:
: void __fastcall TMainForm::FormCreate(TObject *Sender)
: {
: //메뉴 초기화 윈도우 메시지
: ::PostMessage(this->Handle,WM_USER_INITIALIZE_MENU,0,0);
: }
: //---------------------------------------------------------------------------
:
: void __fastcall TMainForm::FormDestroy(TObject *Sender)
: {
: try
: {
: if(screen_list!=NULL)
: {
: delete screen_list;
: }
: } catch(...) {}
: }
: //---------------------------------------------------------------------------
:
: void __fastcall TMainForm::ApplicationEvents1Message(tagMSG &Msg, bool &Handled)
: {
: if(Msg.message==WM_USER_INITIALIZE_MENU)
: {
: Handled=false;
: InitializeMenu();
: }
: }
: //---------------------------------------------------------------------------
:
: void __fastcall TMainForm::ShowMenu(int _index)
: {
: switch(_index)
: {
: case 0://menu1
: ShowMenuForm(Menu0Form);
: break;
: case 1://menu2
: ShowMenuForm(Menu1Form);
: break;
: case 2://menu3
: ShowMenuForm(Menu2Form);
: break;
: case 3://menu4
: ShowMenuForm(Menu3Form);
: break;
: default:
: break;
: }
:
: if(MenuRadioGroup->ItemIndex!=_index) MenuRadioGroup->ItemIndex=_index;
: if(MenuComboBox->ItemIndex!=_index) MenuComboBox->ItemIndex=_index;
: if(MenuListBox->ItemIndex!=_index) MenuListBox->ItemIndex=_index;
: }
: //---------------------------------------------------------------------------
:
: void __fastcall TMainForm::ShowMenuForm(TForm* _form)
: {
: if(_form==NULL) return;
:
: try
: {
: for(int index=0; index<screen_list->Count; ++index)
: {
: TForm* form=dynamic_cast<TForm*>(screen_list->Items[index]);
: if(form!=NULL)
: {
: if(form==_form)
: {
: form->BringToFront();
: form->Show();
: } else
: {
: form->Hide();
: }
: }
: }
: } catch(...) {}
: }
: //---------------------------------------------------------------------------
:
: void __fastcall TMainForm::MenuRadioGroupClick(TObject *Sender)
: {
: ShowMenu(MenuRadioGroup->ItemIndex);
: }
: //---------------------------------------------------------------------------
:
: void __fastcall TMainForm::MenuComboBoxSelect(TObject *Sender)
: {
: ShowMenu(MenuComboBox->ItemIndex);
: }
: //---------------------------------------------------------------------------
:
: void __fastcall TMainForm::MenuListBoxClick(TObject *Sender)
: {
: ShowMenu(MenuListBox->ItemIndex);
: }
: //---------------------------------------------------------------------------
|