Click here to Skip to main content
15,880,967 members
Please Sign up or sign in to vote.
0.00/5 (No votes)

I do simple picture editor,using openCV libriary,and i faced , that when i use openCV libriary,image that i need to open in hWnd opens in his "own" child window,and i don't know,how to get picture from child window,and set in parent window.

What I have tried:

int MyOpenFile(HWND hWnd)
	ZeroMemory(&ofn, sizeof(ofn));
	ofn.lStructSize = sizeof(ofn);
	ofn.hwndOwner = hWnd;
	ofn.lpstrFile = szFile;
	ofn.lpstrFile[0] = '\0';
	ofn.nMaxFile = sizeof(szFile);
	ofn.lpstrFilter = L"Bitmap files(*.bmp)\0*.bmp\0JPEG files(*.jpg)\0*.jpg\0All files(*.*)\0*.*\0\0";
	ofn.nFilterIndex = 1;
	ofn.lpstrFileTitle = NULL;
	ofn.nMaxFileTitle = 0;
	ofn.lpstrInitialDir = NULL;


	hdc = GetDC(hWnd);
	memDC = CreateCompatibleDC(hdc);
	image = cvLoadImage(filename, CV_LOAD_IMAGE_UNCHANGED);;

	dst = cvCloneImage(image);

	cvShowImage("image",image);//this func creates its own window,but i don't know 
                                   //how to display image in parent window

	ReleaseDC(hWnd, hdc);

	return 0;

I've tried this MFC algorithm,but it doesn't work in Winapi,but i think it's correct,but not for winapi,please tell me how to use it correctly in winapi
    cvNamedWindow("IDC_STATIC_OUTPUT", 0);
cvResizeWindow("IDC_STATIC_OUTPUT", 420, 240);

hWnd = (HWND)cvGetWindowHandle("IDC_STATIC_OUTPUT");
HWND hParent = ::GetParent(hWnd);
::SetParent(hWnd, GetDlgItem(hWnd, ));
::ShowWindow(hParent, SW_HIDE);

cvShowImage("IDC_STATIC_OUTPUT", frame_copy)

Thank you in advance!
Updated 19-Jul-17 22:40pm

1 solution

You must use the correct syntax by showing it in your window:
cvShowImage("MyWindowName",image);//use your windows (else it creates a new one
You arent using MFC, but Windows-API. Dont mix them.

Please spend some time by digging trough the OpenCV Tutorials. Often are tons of code in it, which will helpful to you.
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900