Programming/MFC
MFC Alert MessageBox
TanSanC
2016. 9. 6. 10:40
MFC Alert MessageBox
MessageBox 클래스
.NET Framework (current version)
사용자에게 메시지를 보여 주는 메시지 창을 표시합니다. 이 창을 대화 상자라고도 합니다. 이 창은 사용자가 닫을 때까지 응용 프로그램의 다른 동작을 차단하는 모달 창입니다. MessageBox에는 사용자에게 필요한 정보와 명령을 제공하는 텍스트, 단추 및 기호가 포함될 수 있습니다.
어셈블리: System.Windows.Forms.dll의 System.Windows.Forms
private: void validateUserEntry() { // Checks the value of the text. if ( serverName->Text->Length == 0 ) { // Initializes the variables to pass to the MessageBox::Show method. String^ message = "You did not enter a server name. Cancel this operation?"; String^ caption = "No Server Name Specified"; MessageBoxButtons buttons = MessageBoxButtons::YesNo; System::Windows::Forms::DialogResult result; // Displays the MessageBox. result = MessageBox::Show( this, message, caption, buttons ); if ( result == ::DialogResult::Yes ) { // Closes the parent form. this->Close(); } } }
private: void Form1_FormClosing(Object^ sender, FormClosingEventArgs^ e) { // If the no button was pressed ... if ((MessageBox::Show( "Are you sure that you would like to close the form?", "Form Closing", MessageBoxButtons::YesNo, MessageBoxIcon::Question) == DialogResult::No)) { // cancel the closure of the form. e->Cancel = true; } }