C++Builder Programming Forum
C++Builder  |  Delphi  |  FireMonkey  |  C/C++  |  Free Pascal  |  Firebird
볼랜드포럼 BorlandForum
 경고! 게시물 작성자의 사전 허락없는 메일주소 추출행위 절대 금지
C++빌더 포럼
Q & A
FAQ
팁&트릭
강좌/문서
자료실
컴포넌트/라이브러리
메신저 프로젝트
볼랜드포럼 홈
헤드라인 뉴스
IT 뉴스
공지사항
자유게시판
해피 브레이크
공동 프로젝트
구인/구직
회원 장터
건의사항
운영진 게시판
회원 메뉴
북마크
볼랜드포럼 광고 모집

C++빌더 Q&A
C++Builder Programming Q&A
[48373] Re:Re:Re:Re:정말 감사합니다.(냉무)
또아리 [sky4242] 876 읽음    2007-03-13 16:03
이현진 님이 쓰신 글 :
: 또아리 님이 쓰신 글 :
: : 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);
: }
: //---------------------------------------------------------------------------

+ -

관련 글 리스트
48364 여러폼관리하기... 또아리 907 2007/03/12
48365     Re:여러폼관리하기... 이현진 996 2007/03/12
48369         Re:Re:여러폼관리하기... 또아리 1042 2007/03/13
48372             Re:Re:Re:여러폼관리하기... 이현진 1597 2007/03/13
48373                 Re:Re:Re:Re:정말 감사합니다.(냉무) 또아리 876 2007/03/13
Google
Copyright © 1999-2015, borlandforum.com. All right reserved.