ActiveX控件全屏显示

来源:互联网 发布:深圳知行科技有限公司 编辑:程序博客网 时间:2024/05/03 18:18

http://bbs.csdn.net/topics/310053242


(一) 第一种方式,转载

思路:
双击窗体
1。把嵌入在ActiveX里有窗体“跳”出来
2。隐藏任务栏
再次双击和上面相反,又回到了这个ActiveX里去了

bool m_bFullScreen=false;HWND m_hWndParent;void CFfDlg::OnLButtonDblClk(UINT nFlags, CPoint point) {CDialog::OnLButtonDblClk(nFlags, point);m_bFullScreen=!m_bFullScreen; // 设置全屏显示标志 //一种更好的全屏显示LONG style = ::GetWindowLong(this->m_hWnd,GWL_STYLE);if(m_bFullScreen)//全屏显示{//用MFC隐藏系统任务栏CWnd * wnd = FindWindow("Shell_TrayWnd",NULL);wnd->SetWindowPos(NULL,0,0,0,0,SWP_HIDEWINDOW);        m_hWndParent=::GetParent(m_hWnd);           ::ShowWindow(m_hWndParent,SW_HIDE);           ::SetParent(m_hWnd,NULL);   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);int   nScreenWidth=GetSystemMetrics(SM_CXSCREEN);   int   nScreenHeight=GetSystemMetrics(SM_CYSCREEN);::SetWindowPos(this->m_hWnd,HWND_NOTOPMOST,0,0, nScreenWidth,nScreenHeight, SWP_FRAMECHANGED);}else{//用MFC显示系统任务栏CWnd * wnd = FindWindow("Shell_TrayWnd",NULL);wnd->SetWindowPos(NULL,0,0,0,0,SWP_SHOWWINDOW);style |= WS_DLGFRAME | WS_THICKFRAME;SetWindowLong(this->m_hWnd, GWL_STYLE, style);::SetParent(m_hWnd,m_hWndParent);   ::ShowWindow(m_hWndParent,SW_SHOW);  }}

(二)第二种方式,转载

复合窗口的ActiveX控件全屏及键盘消息处理问题 [转

最近在开发一个ActiveX视频控件,需要有全屏功能,因为用到好几层窗口,在全屏的时候费了很多周折,最后瞎凑总算凑好了,写下来与大家共享。

让应用程序全屏显示其实思路很简单:

1.先保存要全屏的窗口的父窗口

2.如果要全屏的窗口不是子窗口,设置其风格为WS_CHILD

3.设置窗口的父窗口为桌面(::GetDesktopWindow())

4.移动窗口至全屏,并将窗口设为总在最上HWND_TOPMOST

 

m_videoMgr是我控件里创建的视频窗口,它的父窗口是控件窗口(CameraControl)控件本身的窗口不直接显示,被这个m_videoMgr窗口完全覆盖。在全屏的时候,如果直接更改CameraControl的父窗口,它的子窗口m_videoMgr窗口总是不能正确的设置为全屏,可能在控件测试容器里正常,但是到了IE里就不正常了。于是我改为更改m_videoMgr窗口的父窗口,保留控件本身窗口,但是改变窗口大小的时候,改变父窗口的大小,也许m_videoMgr窗口可能和控件本身窗口的大小有关联,这样成功的进行了全屏,而且不管是在IE和控件测试容器里都可以正常的全屏和恢复。

if(bFullScreen)
  {
   
   //获取控件窗口的绝对位置
   GetWindowRect(m_rcCtrlRect); 
   ::SetParent(m_videoMgr.GetSafeHwnd(),::GetDesktopWindow());
   
   int cx = ::GetSystemMetrics(SM_CXSCREEN);
   int cy = ::GetSystemMetrics(SM_CYSCREEN);
   MoveWindow(0, 0, cx, cy);
   ::SetWindowPos(m_videoMgr.GetSafeHwnd(),HWND_TOPMOST,0,0,cx,cy,SWP_FRAMECHANGED|SWP_DEFERERASE);
   m_bFullScreen = TRUE;
   
  }
  else
  {
   
   ::SetParent(m_videoMgr.GetSafeHwnd(),m_hWnd); 
   
   //MoveWindow使用相对窗口坐标,所以必须先转化为相对坐标
   CPoint LeftTop(m_rcCtrlRect.TopLeft());
   CPoint BottomRight(m_rcCtrlRect.BottomRight());
   ::ScreenToClient(m_hWnd,&LeftTop);
   ::ScreenToClient(m_hWnd,&BottomRight);
   
   ::MoveWindow(m_hWnd,LeftTop.x,LeftTop.y,m_rcCtrlRect.Width(),m_rcCtrlRect.Height(),TRUE);
   ::SetWindowPos(m_videoMgr.GetSafeHwnd(),HWND_NOTOPMOST,0,0,0,0,SWP_NOMOVE|SWP_NOSIZE);
   m_bFullScreen = FALSE;
  }

解决了上面的问题之后,又发现了一个新的问题,就是全屏以后想使用Esc键退出全屏时,根本不响应键盘消息,后来发现MFC也有控件不处理键盘消息的问题,想想可能跟控件的焦点有关系,于是在FullScreen的之前,加一个SetFocus()

if(FullScreen&&!IsFullScreen())

{

SetFocus();

OnFullScreen(TRUE);

}

然后发现键盘消息处理正常了,问题解决。

(三)根据上述代码修改

环境 VC++2008,ATL项目(添加MFC支持)

1、先生成两个控件,一个是static控件,一个是复合控件,将static控件放置在复合控件

在// AtlComFull2.h : CAtlComFull2 的声明添加变量声明

private:HWND m_hWndParent;BOOL bFullScreen;//全屏标识int m_nTotalWnd;//视频窗口个数int m_nCurIndex;//当前活动的窗口CAxWindow m_videoWnd[16];int MAXWNDNUM;//最大窗口数void ArrayWindow(WORD iNumber);//矩阵化视频窗口bool m_bFullScreen ;WINDOWPLACEMENT m_struOldWndpl;public:CAtlComFull2(){m_bWindowOnly = TRUE;CalcExtent(m_sizeExtent);MAXWNDNUM=16;m_bFullScreen=false;}

矩阵排列子控件在复合控件上:

void CAtlComFull2::ArrayWindow(WORD iNumber){m_nTotalWnd = iNumber;int i = 0;CRect Rect;//此处需要MFC支持,可以改用ATL的形式,Rect即可RECT rect = { 0, 0, 100, 100 };GetClientRect(&Rect);WORD iWidth,iHeight;int nFullWidth=Rect.Width();int nFullHeight=Rect.Height();/*iWidth = (int) nFullWidth*0.75515625;iHeight = (int)nFullHeight*0.91*/;iWidth =  nFullWidth;iHeight = nFullHeight;for (i = 0;i < MAXWNDNUM;i++){m_videoWnd[i].ShowWindow(SW_HIDE);}int nNull = 3;switch(iNumber){case 1:m_videoWnd[0].MoveWindow(3 + 0, 0, iWidth, iHeight);m_videoWnd[0].ShowWindow(SW_SHOW);break;case 4:for(i = 0; i < 2; i++){m_videoWnd[i].MoveWindow( 3 + i * (iWidth / 2) + i * nNull , 0, (iWidth / 2), iHeight / 2);m_videoWnd[i].ShowWindow(SW_SHOW);}for(i = 2; i < 4; i++){m_videoWnd[i].MoveWindow(3 + (i - 2) * (iWidth / 2) + (i - 2) * nNull, iHeight / 2 + nNull, (iWidth / 2), iHeight / 2);m_videoWnd[i].ShowWindow(SW_SHOW);}break;case 9:for (i=0;i<3;i++){m_videoWnd[i].MoveWindow(3 + i * (iWidth / 3) + i * nNull, 0, (iWidth / 3), iHeight / 3);m_videoWnd[i].ShowWindow(SW_SHOW);}for (i=3;i<6;i++){m_videoWnd[i].MoveWindow(3 +(i - 3) * (iWidth / 3) + (i - 3) * nNull, iHeight / 3 + nNull, (iWidth / 3), iHeight / 3);m_videoWnd[i].ShowWindow(SW_SHOW);}for (i=6;i<9;i++){m_videoWnd[i].MoveWindow(3 + (i - 6) * (iWidth / 3) + (i - 6) * nNull, 2 * iHeight / 3 + 2 * nNull ,(iWidth / 3), iHeight / 3);m_videoWnd[i].ShowWindow(SW_SHOW);}break;case 16:for(i = 0; i < 4; i++){m_videoWnd[i].MoveWindow(3 + i * (iWidth / 4) + (i) * nNull, 0, (iWidth / 4), iHeight / 4);m_videoWnd[i].ShowWindow(SW_SHOW);}for(i = 4; i < 8; i++){m_videoWnd[i].MoveWindow(3 +(i - 4) * (iWidth / 4) + (i - 4) * nNull, iHeight / 4 + nNull, (iWidth / 4), iHeight / 4);m_videoWnd[i].ShowWindow(SW_SHOW);}for(i = 8; i < 12; i++){m_videoWnd[i].MoveWindow(3 +(i - 8) * (iWidth / 4) + (i - 8) * nNull, iHeight / 2 + 2 * nNull, (iWidth / 4), iHeight / 4);m_videoWnd[i].ShowWindow(SW_SHOW);}for(i = 12; i < 16; i++){m_videoWnd[i].MoveWindow(3 +(i - 12) * (iWidth / 4) + (i - 12) * nNull, 3 * iHeight / 4 + 3 * nNull, (iWidth / 4), iHeight / 4);m_videoWnd[i].ShowWindow(SW_SHOW);}break;default:break;}}


初始化子控件,使之显示在复合控件上

LRESULT CAtlComFull2::OnBnClickedButton1(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/){AtlAxWinInit();RECT rect = { 0, 0, 100, 100 };for(int i=0;i<MAXWNDNUM;i++){if(!m_videoWnd[i].m_hWnd){m_videoWnd[i].Create(m_hWnd,rect,_T("{9AA126CB-19CA-47B8-AE76-3598E0227C1A}"),WS_CHILD | WS_CLIPSIBLINGS | WS_CLIPCHILDREN, WS_EX_CLIENTEDGE);}}ArrayWindow(4);return 0;}

全屏与退出全屏

LRESULT CAtlComFull2::OnBnClickedButton2(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/){// 全屏//if(!bFullScreen){GetWindowPlacement(&m_struOldWndpl);  m_hWndParent=::GetParent(m_hWnd); ::SetParent(m_hWnd,::GetDesktopWindow());int cx = ::GetSystemMetrics(SM_CXSCREEN);int cy = ::GetSystemMetrics(SM_CYSCREEN);MoveWindow(0, 0, cx, cy);::SetWindowPos(m_hWnd,HWND_TOPMOST,0,0,cx,cy,SWP_FRAMECHANGED|SWP_DEFERERASE);m_bFullScreen = TRUE;//最大化之后重新布局播放窗口ArrayWindow(9);bFullScreen=true;//}else{}return 0;}//退出全屏LRESULT CAtlComFull2::OnBnClickedButton3(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/){// TODO: 在此添加控件通知处理程序代码if(bFullScreen){::SetParent(m_hWnd,m_hWndParent);SetWindowPlacement(&m_struOldWndpl);ArrayWindow(9);bFullScreen=false;}return 0;}





原创粉丝点击