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

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;
	ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;
	GetOpenFileName(&ofn);	

	wcstombs(filename,szFile,255);

	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
	cvWaitKey(0);
	cvReleaseImage(&image);
	cvDestroyAllWindows();

	ReleaseDC(hWnd, hdc);
	UpdateWindow(hWnd);

	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!
Posted
Updated 19-Jul-17 22:40pm
v2

1 solution

You must use the correct syntax by showing it in your window:
C++
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