當在MFC中應用opencv的窗口來顯示圖片。希望namedWindow創建的窗口能根據需要改變風格:
//by dongchunxiao
cv::namedWindow("windows1",0); //創建一個窗口
HWND hWnd = (HWND)cvGetWindowHandle("windows1");//獲取子窗口的HWND
HWND hParentWnd = ::GetParent(hWnd);//獲取父窗口HWND。父窗口是我們要用的
::SetWindowPos(hParentWnd,HWND_TOPMOST,100,1,500,500,SWP_NOSIZE | SWP_NOMOVE); //修改窗口為最頂部
//隱藏窗口標題欄
long style = GetWindowLong(hParentWnd,GWL_STYLE);
style &= ~(WS_CAPTION);
// style &= ~(WS_MAXIMIZEBOX);
SetWindowLong(hParentWnd,GWL_STYLE,style);
//改變窗口的位置和大小。這里主要前面的SetWindowPos不能改變位置和大小(為什么?)
::MoveWindow(hParentWnd,10,100,500,500,0);