方法一:
1,注意一定在子对话框的这里面有ON_WM_PAINT这句话,子对话框中不会默认的创建Paint函数,需要在类向导的“消息”中添加响应函数
BEGIN_MESSAGE_MAP(Child, CDialogEx)
ON_BN_CLICKED(IDC_BUTTON1, &Child::OnBnClickedButton1)
ON_WM_TIMER()
**ON_WM_PAINT()**
END_MESSAGE_MAP()
2,在子对话框的onPaint()函数中写上显示图像的函数
void Child::OnPaint()
{
CWnd* test = GetDlgItem(IDC_PIC);
Mat s = imread("test.jpg");
ShowPicturesFunction(s, test);
CPaintDC dc(this); // device context for painting
}
方法二
设置一个定时器
1,
在初始化函数中
BOOL Child::OnInitDialog()
{
CDialogEx::OnInitDialog();
// TODO: 在此添加额外的初始化
// i 为全局,初始为0
if (i==0)
{
//700 zhi指的是700ms
SetTimer(1, 700, NULL);
}
return TRUE; // return TRUE unless you set the focus to a control
}
2,添加响应函数OnTimer()
void Child::OnTimer(UINT_PTR nIDEvent)
{
// TODO: 在此添加消息处理程序代码和/或调用默认值
if (nIDEvent == 1) //1位上面设定的定时器的ID号
OnBnClickedButton1(); //此为执行按键的事件处理函
CDialogEx::OnTimer(nIDEvent);
}
3,
定時器激发的函数
void Child::OnBnClickedButton1()
{
// TODO: 在此添加控件通知处理程序代码
if (i==0)
{
CWnd* test = GetDlgItem(IDC_PIC);
Mat s = imread("test.jpg");
ShowPicturesFunction(s, test);
i++; // i 为全局,初始为0
}
}