|
이창환 님이 쓰신 글 :
: 메세지 맵을 사용하여 다른 폼에 메세지를 전송하는
:
: 일을 할 경우에 "Functions containing switch are not expanded line"이라는 메세지가 나타납니다.
:
: 메세지 맵을 쓸 경우 항상 이렇제 나타나는데여.
:
: (Command-line option to suppress warning: -w-inl)
:
: 도움말에는 이런 메세지가 나오는 것으로 봐서는 컴파일 옵션을 바꾸어 주어야 하는 것은데
:
: 자세한 것을 알고 싶습니다.
:
: 메세지 맵 사용한 소스는
:
: //////////////////////////////////////////////////////////////////////////////
: // Form1.h
: //////////////////////////////////////////////////////////////////////////////
:
: #define WM_MYMESSAGE (WM_APP + 400)
: //---------------------------------------------------------------------------
: class TForm1 : public TForm
: {
: __published: // IDE-managed Components
: TButton *Button1;
: TButton *Button2;
: void __fastcall Button1Click(TObject *Sender);
: void __fastcall Button2Click(TObject *Sender);
: private: // User declarations
: public: // User declarations
: __fastcall TForm1(TComponent* Owner);
:
: };
:
: //////////////////////////////////////////////////////////////////////////////
: // Form1.cpp
: //////////////////////////////////////////////////////////////////////////////
: void __fastcall TForm1::Button2Click(TObject *Sender)
: {
: PostMessage(Form2->Handle, WM_MYMESSAGE, 0,0);
: }
:
:
: //////////////////////////////////////////////////////////////////////////////
: // Form2.h
: //////////////////////////////////////////////////////////////////////////////
: #define WM_MYMESSAGE (WM_APP + 400)
: //---------------------------------------------------------------------------
: class TForm2 : public TForm
: {
: __published: // IDE-managed Components
: TEdit *Edit1;
: private: // User declarations
: public: // User declarations
: __fastcall TForm2(TComponent* Owner);
:
: protected:
: void __fastcall OnMyMessage(TMessage &Message);
: BEGIN_MESSAGE_MAP
: MESSAGE_HANDLER(WM_MYMESSAGE, TMessage, OnMyMessage)
: END_MESSAGE_MAP(TControl)
: };
:
: //////////////////////////////////////////////////////////////////////////////
: // Form2.cpp
: //////////////////////////////////////////////////////////////////////////////
: void __fastcall TForm2::OnMyMessage(TMessage &Message)
: {
: static int i = 0;
: Edit1->Text = IntToStr(i++);
: }
:
: 입니다.
:
:
Form1에서 Form2에게 메세지를 전송 하려면 우선 Form1에 Form2의 헤더 파일을 Include시키신다음에요
Form1에서 Send Message나 Post Message를 사용 하시기 전에 Form2를 new 하시고 메세지를
사용해보세요^^
ex)
//////////////////////////////////////////////////////////////////////////////
// Form1.cpp
//////////////////////////////////////////////////////////////////////////////
#include "Form2.h"
void __fastcall TForm1::Button2Click(TObject *Sender)
{
TForm2* m_Form = new TForm2(this);
PostMessage(m_Form->Handle, WM_MYMESSAGE, 0,0);
delete m_Form;
}
이렇게하면 경고메세지 안올겁니다..
위에 소스는 버튼 누룰때마다 Form을 New하는데 그게 싫으시면 Form1의 해더파일에
Form2해더파일을 Include하시고 Form1의 해더에 Form2를 정의 하신후 생성자나 FormShow하실때
new를 하신후 소멸자나 Form Close시 delete하시면 됩니다...
|