参考资料:http://www.cnblogs.com/lidabo/archive/2012/07/17/2595452.html (windows 窗口介绍)
http://blog.youkuaiyun.com/ryfdizuo/article/details/6997135 opencv的bug介绍。
opencv如果可以全屏的话,可以省去不少事情呢,opencv的highgui中给出的api中,已经可以实现全屏了,我使用的版本是2.4.6,以下的版本就不知道了。
HWND hWnd = (HWND)cvGetWindowHandle("hello");这样就可以使用windows的sdk对这个句柄进行操作了,你可能会发现使用上面的方法不可行,值得注意的是cvNamedWindow这个函数的第二个参数一定要设置为0,如果设置为1的话,则不可以全屏了。
#include<opencv\cv.h>
#include<opencv\highgui.h>
#include<Windows.h>
void main()
{
IplImage *img1 = cvLoadImage("hello2.jpg");
cvNamedWindow("hello",0);//0是必须的。
cvSetWindowProperty("hello",CV_WND_PROP_FULLSCREEN,1);
//以前的方法。
HWND hWnd = (HWND)cvGetWindowHandle("hello");
HWND hRawWnd = ::GetParent(hWnd);
int screenX = GetSystemMetrics(SM_CXSCREEN);//获取整个屏幕右下角X坐标
int screenY = GetSystemMetrics(SM_CYSCREEN);//屏幕Y坐标
if (hRawWnd != NULL) {
BOOL bRet = ::SetWindowPos(hRawWnd, HWND_TOPMOST, 0, 0, screenX, screenY, SWP_NOSIZE |SWP_NOMOVE);
assert(bRet);
}
//cvWaitKey();
cvShowImage("hello",img1);
cvWaitKey();
}
如何使mfc全屏(与cv无关)
在mfc的mainFrame类中添加下面的代码,并想办法出发这个函数即可。
void CMainFrame::OnEditUndo()
{
// TODO: 在此添加命令处理程序代码
LONG style = ::GetWindowLong(this->m_hWnd,GWL_STYLE);
style &= ~(WS_DLGFRAME | WS_THICKFRAME);
SetWindowLong(this->m_hWnd,GWL_STYLE, style);
this->ShowWindow(SW_SHOWMAXIMIZED);
CRect rect;
this->GetWindowRect(&rect);
::SetWindowPos(this->m_hWnd,HWND_NOTOPMOST,rect.left-1, rect.top-1, rect.right-rect.left + 3, rect.bottom-rect.top + 3, SWP_FRAMECHANGED);
}