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

📄 gdiplus.cpp

📁 《Visual C++.NET专业项目实例开发》源代码Project02Chapter12
💻 CPP
📖 第 1 页 / 共 4 页
字号:
	{
		MessageBox::Show(e->ToString());
	}
}

//PrintPage 
void CMainWindow::PrintPage(Object* sender, PrintPageEventArgs* printEv)
{
	try{
		CGDIPlusView* pActiveView = dynamic_cast<CGDIPlusView*>(this->ActiveMdiChild);
		CGDIPlusDoc* pActiveDoc = pActiveView->GetDocument();	

		for(int i=0; i < pActiveDoc->strokeList->Count; i++)
		{
			CStroke* st = dynamic_cast<CStroke*>(pActiveDoc->strokeList->Item[i]);
			st->DrawStroke(printEv->Graphics) ;
		}
		printEv->HasMorePages = false;
	}

	catch (Exception* ex)
	{
		MessageBox::Show(ex->ToString());
	}
}

//PrintPreview
void CMainWindow::PrintPreview()
{
	try {
		PrintPreviewDialog* pPrevDlg = new PrintPreviewDialog();
		pPrevDlg->Document = pPrintDoc;
		pPrevDlg->Size = System::Drawing::Size(600, 329);
		pPrevDlg->ShowDialog();
	}
	catch(Exception* ex)
	{
		MessageBox::Show(ex->ToString());
	}
}


//Exit
void CMainWindow::Exit()
{
	Form* paChildForm[] = this->MdiChildren ;
	//Make sure to ask for saving the doc before exiting the app
	for(int i=0; i < paChildForm->Length ; i++)
		paChildForm[i]->Close();
	Application::Exit();
}

//Close
void CMainWindow::CloseView()
{
	CGDIPlusView* pActiveView = dynamic_cast<CGDIPlusView*> (this->ActiveMdiChild);
	pActiveView->Close();	
}

//Tile_Click
void CMainWindow::Tile()
{
	this->LayoutMdi(MdiLayout::TileHorizontal);	
}

//Cascade_Click
void CMainWindow::Cascade()
{
	this->LayoutMdi(MdiLayout::Cascade);	
}

//ClearAll
void CMainWindow::ClearAll()
{
	CGDIPlusView* pActiveView = dynamic_cast<CGDIPlusView*> (this->ActiveMdiChild);
	if(pActiveView)
	{
		CGDIPlusDoc* pActiveDoc = pActiveView->GetDocument();
		pActiveDoc->DeleteContents();
	}
}

//Open
void CMainWindow::Open()
{
	OpenFileDialog* pOpenDlg = new OpenFileDialog();
	pOpenDlg->Filter = "GDIPlus Files (*.scb)|*.scb|All Files (*.*)|*.*";
	pOpenDlg->FileName = "" ;
	pOpenDlg->DefaultExt = ".scb";
	pOpenDlg->CheckFileExists = true;
	pOpenDlg->CheckPathExists = true;
		
	int nRes = pOpenDlg->ShowDialog ();

	if(nRes == DialogResult::OK)
	{
		if( !(pOpenDlg->FileName)->EndsWith(".scb") && !(pOpenDlg->FileName)->EndsWith(".SCB")) 
			MessageBox::Show("Unexpected file format","GDIPlus",MessageBoxButtons::OK );
		else
		{
			CGDIPlusDoc* pNewDoc = CreateDocument();
			pNewDoc->OpenDocument(pOpenDlg->FileName);
		}
	}
}

//Save
void CMainWindow::Save()
{
	try 
	{
		CGDIPlusView* pSelectedView = dynamic_cast<CGDIPlusView*>(this->ActiveMdiChild);
		SaveFileDialog* pSaveDlg = new SaveFileDialog();
		pSaveDlg->Filter = "GDIPlus Files (*.scb)|*.scb|All Files (*.*)|*.*";
		pSaveDlg->DefaultExt = ".scb";
		pSaveDlg->FileName = "GDIPlus1.scb";
		
		int nRes = pSaveDlg->ShowDialog();
		if(nRes == DialogResult::OK)
		{
			if(pSelectedView)
			{
				CGDIPlusDoc* pDoc = pSelectedView->GetDocument();
				pDoc->SaveDocument(pSaveDlg->FileName);	
			}			
		}
	}
	catch(Exception* ex)
	{
		MessageBox::Show(ex->ToString());
	}
}

//New
void CMainWindow::New()
{
	//If this is the first child window, enable the Menu and Toolbar items
	if(!this->ActiveMdiChild)
		EnableItems();
	CreateDocument();
}

//NewWindow
void CMainWindow::NewWindow()
{
	CGDIPlusView* pActiveView = dynamic_cast<CGDIPlusView*>(this->ActiveMdiChild);
	CGDIPlusView* pNewView = new CGDIPlusView(pActiveView->GetDocument(), pParentWindow);
	pNewView->GetDocument()->viewList->Add(pNewView);
	pNewView->Show();	
}

//ThickLine
void CMainWindow::ThickLine()
{		 
	CGDIPlusView* pActiveView = dynamic_cast<CGDIPlusView*> (this->ActiveMdiChild);
	CGDIPlusDoc* pActiveDoc = pActiveView->GetDocument();
	pActiveDoc->bIsThickPen = !pActiveDoc->bIsThickPen;
	pActiveDoc->ReplacePen();
	this->pThickLineMenuItem->Checked = pActiveDoc->bIsThickPen;
}

//PenWidthDlg
void CMainWindow::PenWidthsDlg()
{
	Form* f = new Form();

	//Get the document of active view
	CGDIPlusView* pActiveView = dynamic_cast<CGDIPlusView*> (this->ActiveMdiChild);
	CGDIPlusDoc* pActiveDoc = pActiveView->GetDocument();

	f->AutoScaleBaseSize =  System::Drawing::Size(5, 13);
	f->Text = "Pen Width";
	
	f->ClientSize =  System::Drawing::Size(352, 125);
	
	Button* button1 = new Button();
	button1->Location =  System::Drawing::Point(264, 20);
	button1->Size =  System::Drawing::Size(75, 23);
	button1->TabIndex = 1;
	button1->Text = "OK";
	button1->DialogResult  = System::Windows::Forms::DialogResult::OK ;//Make this "OK" button

	Button* button2 = new Button();
	button2->Location =  System::Drawing::Point(264, 52);
	button2->Size =  System::Drawing::Size(75, 23);
	button2->TabIndex = 6;
	button2->Text = "Cancel";
	
	TextBox* textBox1 = new TextBox();		
	textBox1->Location =  System::Drawing::Point(120, 36);
	textBox1->Text = pActiveDoc->nThinWidth.ToString();
	textBox1->TabIndex = 1;
	textBox1->Size =  System::Drawing::Size(64, 20);

	TextBox* textBox2 = new TextBox();		
	textBox2->Location =  System::Drawing::Point(120, 76);
	textBox2->Text = pActiveDoc->nThickWidth.ToString();
	textBox2->TabIndex = 2;
	textBox2->Size =  System::Drawing::Size(64, 20);
	
	Label* label1 = new Label();
	label1->Location =  System::Drawing::Point(16, 36);
	label1->Text = "Thin Pen Width:";
	label1->Size =  System::Drawing::Size(88, 16);
	label1->TabIndex = 3;
	
	Label* label2 = new Label();
	label2->Location =  System::Drawing::Point(16, 76);
	label2->Text = "Thick Pen Width:";
	label2->Size =  System::Drawing::Size(95, 16);
	label2->TabIndex = 4;		
	
	f->FormBorderStyle = FormBorderStyle::FixedDialog;
	// Set the MaximizeBox to false to remove the maximize box.
	f->MaximizeBox = false;
	// Set the MinimizeBox to false to remove the minimize box.
	f->MinimizeBox = false;
	// Set the accept button of the form to button1.
	f->AcceptButton = button1;
	// Set the cancel button of the form to button2.
	f->CancelButton = button2;
	
	f->StartPosition = FormStartPosition::CenterScreen;		
	
	f->Controls->Add(button1);
	f->Controls->Add(button2);
	f->Controls->Add(label1);
	f->Controls->Add(label2);
	f->Controls->Add(textBox1);  
	f->Controls->Add(textBox2);			
		
	System::Windows::Forms::DialogResult res = f->ShowDialog();
			
	if(res == System::Windows::Forms::DialogResult::OK )
	{			
		pActiveDoc->nThinWidth = UInt32::Parse(textBox1->Text);
		pActiveDoc->nThickWidth = UInt32::Parse(textBox2->Text);
		pActiveDoc->ReplacePen();
		f->Close();
	}			
}

//Disable the menu and toolbar items when there is no active child form
void CMainWindow::DisableItems()
{
	this->pEditMenuItem->Visible=false;
	this->pPenMenuItem->Visible=false;
	this->pWindowMenuItem->Visible=false;
	this->pCloseMenuItem->Visible=false;
	this->pSaveMenuItem->Visible=false;
	this->pSaveAsMenuItem->Visible=false;
	this->pPrintMenuItem->Visible=false;
	this->pPrintPreviewMenuItem->Visible=false;
	this->pSaveTBButton->Enabled = false;
	this->pPreviewTBButton->Enabled=false;
	this->pPrintTBButton->Enabled=false;
}

//Enable the menu and toolbar items when the first child form is created
void CMainWindow::EnableItems()
{
	this->pEditMenuItem->Visible=true;
	this->pPenMenuItem->Visible=true;
	this->pWindowMenuItem->Visible=true;
	this->pCloseMenuItem->Visible=true;
	this->pSaveMenuItem->Visible=true;
	this->pSaveAsMenuItem->Visible=true;
	this->pPrintMenuItem->Visible=true;
	this->pPrintPreviewMenuItem->Visible=true;
	this->pSaveTBButton->Enabled = true;
	this->pPreviewTBButton->Enabled=true;
	this->pPrintTBButton->Enabled=true;
}
	
//Creates a new document
CGDIPlusDoc* CMainWindow::CreateDocument()
{
	CGDIPlusDoc* pNewDoc = new CGDIPlusDoc (pParentWindow);
	nDocCount++;
	return pNewDoc;
}

void CMainWindow::DrawEllipse()
{
	Form* f = new Form();
	//Get the document of active view
	CGDIPlusView* pActiveView = dynamic_cast<CGDIPlusView*> (this->ActiveMdiChild);
	CGDIPlusDoc* pActiveDoc = pActiveView->GetDocument();

	f->AutoScaleBaseSize =  System::Drawing::Size(5, 13);
	f->Text = "Draw Ellipse";
	
	f->ClientSize =  System::Drawing::Size(300, 125);
	
	Button* button1 = new Button();
	button1->Location =  System::Drawing::Point(70, 100);
	button1->Size =  System::Drawing::Size(60, 20);
	button1->TabIndex = 1;
	button1->Text = "OK";
	button1->DialogResult  = System::Windows::Forms::DialogResult::OK ;//Make this "OK" button

	Button* button2 = new Button();
	button2->Location =  System::Drawing::Point(150, 100);
	button2->Size =  System::Drawing::Size(60, 20);
	button2->TabIndex = 6;
	button2->Text = "Cancel";
	
	//Left
	TextBox* textBox1 = new TextBox();		
	textBox1->Location =  System::Drawing::Point(80, 15);
	textBox1->Text = "10"; //pActiveDoc->nThinWidth.ToString();
	textBox1->TabIndex = 1;
	textBox1->Size =  System::Drawing::Size(64, 20);

	//Top
	TextBox* textBox2 = new TextBox();		
	textBox2->Location =  System::Drawing::Point(80, 45);
	textBox2->Text = "10"; //pActiveDoc->nThickWidth.ToString();
	textBox2->TabIndex = 2;
	textBox2->Size =  System::Drawing::Size(64, 20);
	
	Label* label1 = new Label();
	label1->Location =  System::Drawing::Point(15, 20);
	label1->Text = "Left:";
	label1->Size =  System::Drawing::Size(50, 16);
	label1->TabIndex = 3;
	
	Label* label2 = new Label();
	label2->Location =  System::Drawing::Point(15, 50);
	label2->Text = "Top:";
	label2->Size =  System::Drawing::Size(50, 16);
	label2->TabIndex = 4;		

	//PSK START
	TextBox* textBox3 = new TextBox();		
	textBox3->Location =  System::Drawing::Point(220, 15);
	textBox3->Text = "50"; //pActiveDoc->nThinWidth.ToString();
	textBox3->TabIndex = 1;
	textBox3->Size =  System::Drawing::Size(64, 20);

	TextBox* textBox4 = new TextBox();		
	textBox4->Location =  System::Drawing::Point(220, 45);
	textBox4->Text = "25"; //pActiveDoc->nThickWidth.ToString();
	textBox4->TabIndex = 2;
	textBox4->Size =  System::Drawing::Size(64, 20);
	
	Label* label3 = new Label();
	label3->Location =  System::Drawing::Point(155, 20);
	label3->Text = "Width:";
	label3->Size =  System::Drawing::Size(50, 16);
	label3->TabIndex = 3;
	
	Label* label4 = new Label();
	label4->Location =  System::Drawing::Point(155, 50);
	label4->Text = "Height:";
	label4->Size =  System::Drawing::Size(50, 16);
	label4->TabIndex = 4;		

	//END

	f->FormBorderStyle = FormBorderStyle::FixedDialog;
	// Set the MaximizeBox to false to remove the maximize box.
	f->MaximizeBox = false;
	// Set the MinimizeBox to false to remove the minimize box.
	f->MinimizeBox = false;
	// Set the accept button of the form to button1.
	f->AcceptButton = button1;
	// Set the cancel button of the form to button2.
	f->CancelButton = button2;
	
	f->StartPosition = FormStartPosition::CenterScreen;		
	
	f->Controls->Add(button1);
	f->Controls->Add(button2);
	f->Controls->Add(label1);

⌨️ 快捷键说明

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