1.打開菜單界面:
2.設置點擊的處理程序:
3.編輯代碼:
注意這裏不要寫畫圖的代碼什麼的,這裏控制改變某個變量,讓OnDraw函數取處理不同的情況!以下是我生成隨機線段的代碼,這個可以自己根據情況寫代碼。
最後一行通知畫圖函數是必須的。
void CTestView::OnCreateLine()
{
//Debug
//lines.push_back(Line(Point(500, 200), Point(100, 400)));
int n = 10;
srand(unsigned(time(NULL)));
for (int i = 0; i < n; i++)
{
double x = rand() % WindowWidth+1;
double y = rand() % WindowHeight+1;
Point a = Point(x, y);
x = rand() % WindowWidth + 1;
y = rand() % WindowHeight + 1;
Point b = Point(x, y);
lines.push_back(Line(a, b));
}
SendMessage(WM_PAINT); //通知畫圖
}