messagebox.cpp

来自「SimpleGraphicOperatingSystem 32位图形化操作系统 」· C++ 代码 · 共 61 行

CPP
61
字号
#include <osdef.h>//WM_**
#include <System.h>
#include <Api.h>	//Sgos api


namespace System{

	class MessageForm: public Form{
	private:
		class OKButton: public Button{
		public:
			OKButton(BaseWindow* parent):Button( parent, string("  OK  "), 0 ){}
			virtual int OnMouseUp(int button, Point* p ){
				if( button==1 ){
					if( Parent()->Parent()  ){
						delete Parent()->Parent();
					}
				}
				//Button::OnMouseUp(button,p);
			}
		};
		BaseWindow* ok;
		Label *lbText;
	public:
		MessageForm(Form* parent, string strText, string strTitle):Form( parent, strTitle, 0 ){
			lbText = new Label( GetClient(), strText, LABEL_NOFRAME );
		}
		int Init(){
			Move( 300, 200, 350, 150 );
			lbText->Move( 5, 5, 330, 65 );
			lbText->Show();
			ok = new OKButton( GetClient() );
			ok->Move( 173-ok->Width()/2, 80 );
			ok->Show();
			Form::OnInitialize();
		}
		~MessageForm(){
			delete lbText;
			delete ok;
		}
		virtual int OnPaint(){
			Form::OnPaint();
		}
	};

	int MessageBox::Show( string strText ){
		Show( strText, string("Message"), MB_Default );
	}
	int MessageBox::Show( string strText, int mode ){
		Show( strText, string("Message"), mode );
	}
	int MessageBox::Show( string strText, string strTitle ){
		Show( strText, strTitle, MB_Default );
	}
	int MessageBox::Show( string strText, string strTitle, int mode ){
		MessageForm* frmMsgBox = new MessageForm( (Form*)0, strText, strTitle );
		frmMsgBox->Init();
		frmMsgBox->Show();
	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?