⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 复件 form.cpp

📁 SimpleGraphicOperatingSystem 32位图形化操作系统 多进程 支持FAT32 详见www.sgos.net.cn
💻 CPP
字号:
#include <OsDef.h>//WM_**
#include <System.h>
#include <Api.h>	//Sgos api

#define MID_SPACE 2



namespace System{

	class CloseButton: public Button{
		public:
			CloseButton( BaseWindow* parent, string text, int style ):
				Button( parent, text, style ){
			}
			virtual int OnMouseUp( int button, Point* p ){
				if( button == 1 ){
					Form* parent = (Form*)Parent();
					if( parent )
						delete parent;
				}
			}
			virtual int DrawLabel(int type){
			int w = BaseWindow::Width();
			int h = BaseWindow::Height();
			Bitmap::Line( bitmap, w/4, h/4, w*3/4, h*3/4, Bitmap::BLACK );
			Bitmap::Line( bitmap, w/4, h*3/4, w*3/4, h/4, Bitmap::BLACK );
			Label::DrawLabel(type);
		}
	};
	
	class MiniButton: public Button{
		public:
			MiniButton( BaseWindow* parent, string text, int style ):
				Button( parent, text, style ){
			}
			virtual int OnMouseUp( int button, Point* p ){
				if( button == 1 ){
					Form* parent = (Form*)Parent();
					if( parent )
						int w_ = parent->Width();
						int h_ = parent->Height();
						parent->Move(0,768-23,133,23);
				}
			}
			virtual int DrawLabel(int type){
			int w = BaseWindow::Width();
			int h = BaseWindow::Height();
			Bitmap::Line( bitmap, w/4, h*3/4, w*3/4, h*3/4, Bitmap::BLACK );
			Label::DrawLabel(type);

			}
	};






	
	class LargeButton: public Button{
		public:
			LargeButton( BaseWindow* parent, string text, int style ):
				Button( parent, text, style ){
			}
			virtual int OnMouseUp( int button, Point* p ){
				if( button == 1 ){
					Form* parent = (Form*)Parent();
					if( parent )
                MessageBox::Show( string("功能未实现"), string("Error") );
				}
			}
			virtual int DrawLabel(int type){
			int w = BaseWindow::Width();
			int h = BaseWindow::Height();
			Bitmap::Line( bitmap, w/4,   h/4,   w*3/4, h/4, Bitmap::BLACK );
			Bitmap::Line( bitmap, w/4,   h/4+1,   w*3/4, h/4+1, Bitmap::BLACK );
			Bitmap::Line( bitmap, w/4, h*3/4,   w*3/4, h*3/4,   Bitmap::BLACK );
			Bitmap::Line( bitmap, w/4,   h/4,   w/4,   h*3/4, Bitmap::BLACK );
			Bitmap::Line( bitmap, w*3/4, h/4,   w*3/4, h*3/4, Bitmap::BLACK );
			Label::DrawLabel(type);

			}
	};








	int Form::OnInitialize(){
	}


	
	Form::Form( BaseWindow* parent, string text, int style )
		:BaseWindow( parent, text, style )
	{
		int x=50, y=50, w = 200, h = 150;
		strFormName = text;
		type = TypeForm;
		status = FormRunning;
		bMouseCatched=false;
        frameColor1 = Bitmap::MakeColor(200,200,200);
		frameColor2 = Bitmap::MakeColor(200,200,200);
		titleColor1 = Bitmap::MakeColor(41,41,41);
		client = new BaseWindow( (BaseWindow*)this, string("client"), 0 );
        buttonClose = new CloseButton( (BaseWindow*)this, string(" "), 0 );
		buttonClose->Move( x-MID_SPACE+3, y-MID_SPACE+3,13,13);
        buttonMini = new MiniButton( (BaseWindow*)this, string(" "), 0 );
		buttonMini->Move( x-MID_SPACE+3, y-MID_SPACE+3,13,13);
		buttonLarge = new LargeButton( (BaseWindow*)this, string(" "), 0 );
		buttonLarge->Move( x-MID_SPACE+3, y-MID_SPACE+3,13,13);
		buttonClose->Show();
		buttonMini->Show();
		buttonLarge->Show();
		Move( x-MID_SPACE, y-MID_SPACE);
   		client->Show();
        client->BaseWindow::MoveToTop(true);
		Activate();
		OnInitialize();
	}



	
	Form::~Form()
	{
		delete buttonClose;
		delete buttonMini;
		delete buttonLarge;
		delete client;
	}

	
	BaseWindow* Form::GetClient(){
		return client;
	}

	
	int Form::OnPaint(){
		DrawBackGround(1);
		DrawTitleBar(1);
		if( visible ){
			client->Refresh();
			buttonClose->Refresh();
			buttonMini->Refresh();
			buttonLarge->Refresh();
			Refresh();
		}
		BaseWindow::OnPaint();
	}

	
	int Form::OnActivate(bool active){
		if( active )
		{
			DrawBackGround(1);
			DrawTitleBar(1);
		}else{
			DrawBackGround(0);
			DrawTitleBar(0);
		}
		Refresh();
		return BaseWindow::OnActivate(active);
	}

	
	int Form::OnSize(int w, int h){
		client->Move( MID_SPACE, 21+MID_SPACE, w-MID_SPACE*2, h-MID_SPACE*2-21 );
		buttonClose->Move( w-MID_SPACE-buttonClose->Width(), MID_SPACE );
		buttonClose->Refresh();
		buttonMini->Move( w-MID_SPACE-buttonClose->Width()-30, MID_SPACE );
		buttonMini->Refresh();
		buttonLarge->Move( w-MID_SPACE-buttonClose->Width()-15, MID_SPACE );
		buttonLarge->Refresh();

		Bitmap::RectFill( bitmap, 0, 0, bitmap->Width-1-MID_SPACE, bitmap->Height-1-MID_SPACE,winStyle.active.backColor );
		Bitmap::RectFill( client->Bitmap(), 0, 0, client->Bitmap()->Width-1, client->Bitmap()->Height-1,winStyle.active.backColor );
		client->Refresh();
		return BaseWindow::OnSize(w,h);
	}

	
	int Form::OnLoad()
	{
        return BaseWindow::OnLoad();
	}

	
	int Form::SetFormSize( int w, int h )
	{
	    w = w+MID_SPACE*2;
	    h = h+MID_SPACE*2+ 22;
	    return BaseWindow::SetSize( w, h );
	}

	
	int Form::DrawTitleBar(int type){



                        int x,y,w,c;
                        x=MID_SPACE+3;
                        y=MID_SPACE+3;
                        w=bitmap->Width-x-1;
                        c=231;

			Bitmap::RectFill( bitmap, MID_SPACE, MID_SPACE, bitmap->Width-MID_SPACE-3, 22, Bitmap::MakeColor(c,c,c));


		switch(type){
		case 0:
			

			break;
		case 1:

Bitmap::DrawText(
				bitmap,
				strFormName.GetData(),
				strFormName.Length(),
				MID_SPACE-30+w/2-strFormName.Length()/2,
				MID_SPACE+5,
				FONT_MINI_SIZE,
				titleColor1,
				0 );
			break;
		}
		buttonClose->Refresh();
		buttonMini->Refresh();
		buttonLarge->Refresh();
	}

	
	int Form::DrawBackGround(int type){
		switch(type)
		{
			case 0:
				//上
				Bitmap::RectFill( bitmap, 0, 0, bitmap->Width-1, MID_SPACE-1,
					frameColor2 );
				//左
				Bitmap::RectFill( bitmap, 0, MID_SPACE, MID_SPACE-1, bitmap->Height-MID_SPACE-1,
					frameColor2 );
				//右
				Bitmap::RectFill( bitmap, bitmap->Width-MID_SPACE, MID_SPACE-1, bitmap->Width-1, bitmap->Height-MID_SPACE-1,
					frameColor2 );
				//下
				Bitmap::RectFill( bitmap, 0, bitmap->Height-MID_SPACE, bitmap->Width-1, bitmap->Height-1,
					frameColor2 );
				break;
			case 1:
				//上
				Bitmap::RectFill( bitmap, 0, 0, bitmap->Width-1, MID_SPACE-1,
					frameColor1 );
				//左
				Bitmap::RectFill( bitmap, 0, MID_SPACE, MID_SPACE-1, bitmap->Height-MID_SPACE-1,
					frameColor1 );
				//右
				Bitmap::RectFill( bitmap, bitmap->Width-MID_SPACE, MID_SPACE-1, bitmap->Width-1, bitmap->Height-MID_SPACE-1,
					frameColor1 );
				//下
				Bitmap::RectFill( bitmap, 0, bitmap->Height-MID_SPACE, bitmap->Width-1, bitmap->Height-1,
					frameColor1 );
				break;
		}
	}

	
	int Form::OnMessage( Message* msg )
	{
		switch(msg->message){
		}

		//基类
		BaseWindow::OnMessage(msg);
	}

	
	int Form::OnMouseDown( int button, Point* p ){
		if( button==1 && p->y < 21+MID_SPACE ){
			Point gM;
			Rect r;
			Mouse::GetMousePoint(&gM);	//we get the global mouse position.
			GetRect( r );
			oldMouseRelX = gM.x;
			oldMouseRelY = gM.y;
			oldWinX = r.left;
			oldWinY = r.top;
			bMouseCatched = true;
		}
		BaseWindow::OnMouseDown( button, p );
	}
	
	int Form::OnMouseUp( int button, Point* p ){
		bMouseCatched = false;
		BaseWindow::OnMouseUp( button, p );
	}
	
	int Form::OnMouseLeave( int button ){
		bMouseCatched = false;
		BaseWindow::OnMouseLeave( button );
	}
	
	int Form::OnMouseMove( Point* p ){
		if( bMouseCatched ){
			short x,y;
			Point gM;
			Mouse::GetMousePoint(&gM);	//we get the global mouse position.
			x = gM.x-oldMouseRelX;
			y = gM.y-oldMouseRelY;
			Move( x+oldWinX, y+oldWinY, 0, 0 );
			BaseWindow::OnMouseMove( p );
		}
	}

	
	int Form::OnDispose(int& cancel){
		BaseWindow::OnDispose(cancel);
	}
}

⌨️ 快捷键说明

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