-
MessageBoxC++ Builder/함수 2019. 3. 6. 10:55
음..
어제 올라온 질문중에 메세지박스의 캡션을 설정할수 있냐는 질문이 있었죠?
답변중 하나는 Win32API MessageBox를 이용하는것이구
http://cbuilder.borlandforum.com/impboard/impboard.dll?action=read&db=bcb_qna&no=59516
(Application->MessageBox는 win32api MessageBox를 호출합니다.)
또다른 하나는 Application->Title을 변경한후에 ShowMessage를 하면된다고 했습니다.
http://cbuilder.borlandforum.com/impboard/impboard.dll?action=read&db=bcb_qna&no=59518
둘다 맞는 말입니다.
첫번째 Win32API를 사용할경우
특별한 문제가 없습니다만..
Screen->OnActiveFormChange 이벤트를 사용하고자 할경우 이벤트가 발생하지 않습니다.
왜냐하면 말그대로 vcl함수가 아니구 vcl의 폼이 아니기 때문이죠
두번째 Appliction->Title을 수정할경우
Application->Title을 수정하면 작업표시줄에 나타나는 버튼의 캡션이 변경됩니다.
Application->Title은 말그대로 프로그램의 이름 즉 프로그램을 대표하는 title로써
메세지박스 띄울때마다 바꾸긴 좀 그렇죠..
다시 메세지박스를 close한후에 원상태로 해줘야하는 불편함도 있구요
그래서 한번 만들어 보았습니다.
[VCL메세지 박스의 원리]
음..
코딩에 앞서 먼저 VCL에 있는 메세지박스의 원리에 대해 간단히 설명해드리겠습니다.
VCL의 ShowMessage 나 MessageDlg 등을 호출하면
1) TForm을 상속받은 TMessageForm을 생성합니다.(new TMessageForm(Application); )
2) 그런다음 넘겨준 파라메터에 맞게
TButton과 TLabel을 동적으로 생성해서 Form위에 올리고
Form의 크기도 메세지의 길이에 맞게 조정합니다.
3) 그런다음 TMessageForm을 ShowModal로 띄워주는 것입니다.
[CreateMessageDialog 함수란?]
위 1~3과정에서 1,2과정을 CreateMessageDialog라는 함수안에서 합니다.
CreateMessageDialog라는 함수에서 TMessageForm을 생성하고.. return해줍니다.
만약 caption을 바꾸고 싶으면 CreateMessageDialog함수로
return받은 TMessageForm의 captionㅇ르 바꾼후에 ShowModal해주면 되는것입니다.'
[ShowMessage캡션 바꾸기]12345678910111213int
__fastcall ShowMessage(String sCaption,String sMessage)
{
TForm *frm=(TForm *)CreateMessageDialog(sMessage,mtCustom,TMsgDlgButtons() << mbOK);
frm->Caption=sCaption;
frm->Position = poScreenCenter;
//메세지 박스 위치 (화면 한가운데)
frm->ShowModal();
delete
frm;
}
void
__fastcall TForm1::Button1Click(TObject *Sender)
{
ShowMessage(
"타이틀"
,
"타이틀이있는 메세지박스 잘보이나요?"
);
}
위 기능을 방식을 응용하면 엄청 다양한 메세지박스를 만들수 잇습니다.
* Font를 바꾼다던가
* 글자의 Color를 바꾼다던지..
[ShowMessage 메세지 color바꾸기 ]12345678910int
__fastcall ShowMessage(String sCaption,String sMessage,TColor clMsgColor)
{
TForm *frm=(TForm *)CreateMessageDialog(sMessage,mtCustom,TMsgDlgButtons() << mbOK);
frm->Caption=sCaption;
frm->Position = poScreenCenter;
TLabel*lbl=(TLabel *)frm->FindComponent(
"Message"
);
if
(lbl) lbl->Font->Color=clMsgColor;
frm->ShowModal();
delete
frm;
}
[메세지박스 캡션을 한글로 ]
;다음과 같이 하면 메세지박스의 버튼 캡션을 한글로 바꿀수도 있구요1234567891011121314151617181920void
__fastcall ShowMessage(String Msg)
{
TForm *frm=CreateMessageDialog(Msg,mtCustom,TMsgDlgButtons()<<mbyes); frm-=
""
>Position=poScreenCenter;
for
(
int
idx=
0
; idx<frm->ControlCount;idx++)
{
if
(frm->Controls[idx]->InheritsFrom(__classid(TButton)))
{
((TButton *)frm->Controls[idx])->Caption=
"확인"
;
break
;
}
}
frm->ShowModal();
delete
frm;
}
//---------------------------------------------------------------------------
void
__fastcall TForm1::Button1Click(TObject *Sender)
{
::ShowMessage(
"메세지박스 캡션을 한글로..."
);
}
</frm-></mbyes);>
그럼..뽀뽀중 [kissjung] 2009-12-30 12:50 X감사 합니다.출처:http://cbuilder.borlandforum.com/impboard/impboard.dll?action=read&db=bcb_tip&no=946
728x90'C++ Builder > 함수' 카테고리의 다른 글
IncMonth(), IncWeek() (0) 2019.03.26 isdigit (0) 2019.03.25 TIniFile ::ReadSectionValues (0) 2019.01.25 ForceDirectories (0) 2019.01.25 ExtractFilePath() (0) 2019.01.24 댓글