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

📄 program_10_6.cpp

📁 c++程序设计讲义 cppprograming 含源码
💻 CPP
字号:
// Example showing use of the mouse
// The program displays a bitmap in the window at
// the place where the mouse is clicked

#include <bitmap>
#include <cassert>
using namespace std;

// define two non-overlapping windows
SimpleWindow W1("Window One", 15., 12., Position(1., 1.));

SimpleWindow W2("Window Two", 15., 12., Position(15., 12.));

// define two bitmpas, one for each window
BitMap W1Bmp(W1);
BitMap W2Bmp(W2);

// W1MouseClick(): callback function for window 1
int W1MouseClick(const Position &p) {
	// Erase the bitmap
	W1Bmp.Erase();

	// Set its new position and display it
	W1Bmp.SetPosition(p);
	W1Bmp.Draw();

	return 1;
}

// W2MouseClick(): callback function for window 2
int W2MouseClick(const Position &p) {
	// Erase the bitmap
	W2Bmp.Erase();

	// Set its new position and display it
	W2Bmp.SetPosition(p);
	W2Bmp.Draw();

	return 1;
}


int ApiMain() {
	// Open the windows
	W1.Open();
	assert(W1.GetStatus() == WindowOpen);
	W2.Open();
	assert(W2.GetStatus() == WindowOpen);

	// Load the images
	W1Bmp.Load("me.bmp");
	assert(W1Bmp.GetStatus() == BitMapOkay);
	W2Bmp.Load("bush.bmp");
	assert(W2Bmp.GetStatus() == BitMapOkay);

	// Display the bitmaps at a starting position
	W1Bmp.SetPosition(Position(1., 1.));
	W2Bmp.SetPosition(Position(1., 1.));
	W1Bmp.Draw();
	W2Bmp.Draw();

	// Register the callbacks for each window
	W1.SetMouseClickCallback(W1MouseClick);
	W2.SetMouseClickCallback(W2MouseClick);

	return 0;
}

int ApiEnd() {
	W1.Close();
	W2.Close();
	return 0;
}

⌨️ 快捷键说明

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