how to display many picture in 1 dialog

Hi,
In my dialog, i have 4 picture control to display the picture 1 -> picture 4
4 radio button to select picture 1->picture 4, and 1 button(Load Image button).
When the users click on the load image, the program will check the radio button now is on which picture, then load and display the picture into picture control.eg, if radio button now is on picture3,then the image must display in picture control number 3.
I had done this step,the image can display correctly. But when i click on another radio button,let say picture 2, the image previous show in picture control 3 will disappear. This is my problem now.but when i click back into radio button 3,it will show the previous image..
The image had store in memory..er..sorry for my poor English.hope you all can understand wat i saying...Please help me.
no body know the solution?oh my god.x.x
i thought this simple?
sorry i;m new in mfc..
Post the code.
This is a partially of my code.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
void CTest::OnRadioDirection(UINT nID)
{

	switch(nID)
	{
	case IDC_1:								  
		id = 0;
		break;
	case IDC_2:
		id = 1;
		break;
	case IDC_3:
		id = 2;
		break;
	case IDC_4:
		id = 3;
	default:
		break;
	}
	m_pGUIDoc->UpdateAllViews(NULL);
}


void CTest::DrawPreview(CDC* pDC)
{
	if (m_pImg[id])            //m_pImg is a IplImage,can say is a image
	{                          //the id is the no of the radio button,
//eg,button 1 = id = 0,button 2 = id =1 
		BYTE* pImg = (BYTE*)m_pImg[id]->imageData;
		CvSize size = cvGetSize(m_pImg[id]);
		CRect rcPreview;
		if (id == 0)
			GetDlgItem(IDC_picture1)->GetWindowRect(&rcPreview);
		else if (id == 1)
			GetDlgItem(IDC_PICTURE2)->GetWindowRect(&rcPreview);
		else if (id == 2)
			GetDlgItem(IDC_PICTURE3)->GetWindowRect(&rcPreview);
		else if (id == 3)
			GetDlgItem(IDC_PICTURE4)->GetWindowRect(&rcPreview);
		else
			;

		ScreenToClient(&rcPreview);
	
		double scaleX = (double)size.width / (double)rcPreview.Width();
		double scaleY = (double)size.height / (double)rcPreview.Height();
		double scaleToFit = (scaleX > scaleY) ? scaleX : scaleY;
		int iWidth = (int) ((double)size.width / scaleToFit);
		int iHeight = (int) ((double)size.height / scaleToFit);
		int iOffX = rcPreview.left;
		int iOffY = rcPreview.top;

		HDC hDC = pDC>GetSafeHdc();
		SetStretchBltMode(hDC, COLORONCOLOR);
		StretchDIBits(hDC, iOffX, iOffY, iWidth, iHeight, 
			0, 0, size.width, size.height, pImg, GetBitmapTag(), DIB_RGB_COLORS, SRCCOPY);
	}
}
I think this is the usual problem of 'inappropriate painting' in a GUI context

I am guessing that you are using the MFC document/View architecture, and that CTest is a typeof CView.
If each time you get a radiobutton click, and you call m_pGUIDoc->UpdateAllViews(NULL); , I think this will cause the CView to repaint the background, which will obliterate any previous images. There will then be a WM_PAINT message sent to the CView.

In MS windows, you can get a HDC to the window and paint anytime you like (as you appears to have done in the DrawPreview(CDC* pDC) function --- BUT when the window get painted, first the background gets erased any your stuff will be wiped.

You need to override the WM_PAINT or what ever the function is for CTest (possibly CTest::onUpdate() ) and put or call your image blitting code from there (which means that you need to keep a record of what images to paint)

Do you understand what I'm saying?
Topic archived. No new replies allowed.