WPF&MFC&Opencv透明全屏无边框窗口创建

来源:互联网 发布:徐州淘金网络 编辑:程序博客网 时间:2024/06/03 17:36

WPF窗口:

MainWindow.xaml中修改代码如下:
Title="MainWindow" Height="1080" Width="1920" WindowStyle="None"<!--无边框--> Background="{x:Null}" AllowsTransparency="True" <!--透明--> Topmost ="True" <!--置顶-->> 

MainWindow.xaml.cs中修改如下: 
public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); #region 设置全屏 this.WindowState = System.Windows.WindowState.Normal; this.WindowStyle = System.Windows.WindowStyle.None; this.ResizeMode = System.Windows.ResizeMode.NoResize; this.Topmost = true; this.Left = 0.0; this.Top = 0.0; this.Width = System.Windows.SystemParameters.PrimaryScreenWidth; this.Height = System.Windows.SystemParameters.PrimaryScreenHeight; #endregion } private void Grid_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) { } //Esc for close private void Window_KeyDown(object sender, System.Windows.Input.KeyEventArgs e) { if (e.Key == Key.Escape) { this.Close(); } } }

MFC窗口:

透明全屏隐藏任务栏图标:在修改OnInitDialog如下 
BOOL xxxDlg::OnInitDialog() { CDialog::OnInitDialog(); // 将“关于...”菜单项添加到系统菜单中。 // IDM_ABOUTBOX 必须在系统命令范围内。 ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX); ASSERT(IDM_ABOUTBOX < 0xF000); CMenu* pSysMenu = GetSystemMenu(FALSE); if (pSysMenu != NULL) { BOOL bNameValid; CString strAboutMenu; bNameValid = strAboutMenu.LoadString(IDS_ABOUTBOX); ASSERT(bNameValid); if (!strAboutMenu.IsEmpty()) { pSysMenu->AppendMenu(MF_SEPARATOR); pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu); } } // 设置此对话框的图标。当应用程序主窗口不是对话框时,框架将自动 // 执行此操作 SetIcon(m_hIcon, TRUE); // 设置大图标 SetIcon(m_hIcon, FALSE); // 设置小图标 ModifyStyleEx(0,WS_EX_TOPMOST); ShowWindow(SW_SHOW); // TODO: 在此添加额外的初始化代码 ModifyStyleEx(WS_EX_APPWINDOW,WS_EX_TOOLWINDOW);//hide taskbar icon SendMessage(WM_SYSCOMMAND,SC_MAXIMIZE,0); //full screen HWND hWnd = this->GetSafeHwnd (); ::SetWindowPos(hWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE);//topmost //SetWindowPos(&wndTopMost,0,0, GetSystemMetrics(SM_CXSCREEN),GetSystemMetrics(SM_CYSCREEN), // SWP_SHOWWINDOW | SWP_NOACTIVATE); //full screen //transparent windows SetWindowLong(this->GetSafeHwnd(),GWL_EXSTYLE, GetWindowLong(this->GetSafeHwnd(),GWL_EXSTYLE)^WS_EX_LAYERED); HINSTANCE hInst = LoadLibrary(L"User32.DLL");//显式加载DLL if(hInst!=NULL) { typedef BOOL (WINAPI *MYFUNC)(HWND,COLORREF,BYTE,DWORD); MYFUNC pFun = NULL; pFun=(MYFUNC)GetProcAddress(hInst, "SetLayeredWindowAttributes");//取得SetLayeredWindowAttributes函数指针 if(pFun!=NULL) pFun(this->GetSafeHwnd(),0,150,LWA_ALPHA); FreeLibrary(hInst); } int cx=::GetSystemMetrics(SM_CXSCREEN);//get screen width int cy=::GetSystemMetrics(SM_CYSCREEN);//get screen hight return TRUE; // 除非将焦点设置到控件,否则返回 TRUE } 

无边框:添加OnCeate重写该方法如下 
int xxxDlg::OnCreate(LPCREATESTRUCT lpCreateStruct) { ModifyStyle(WS_CAPTION|WS_THICKFRAME, 0, SWP_DRAWFRAME); SetMenu(NULL); if (CDialog::OnCreate(lpCreateStruct) == -1) return -1; // TODO: 在此添加您专用的创建代码 return 0; }

Opencv窗口:

cvNamedWindow( "Transform", 0 ); //置顶 HWND hWnd = (HWND)cvGetWindowHandle("Transform"); HWND hRawWnd = ::GetParent(hWnd); if (hRawWnd != NULL) { BOOL bRet = ::SetWindowPos(hRawWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE); assert(bRet); } hWnd = (HWND) cvGetWindowHandle("Transform"); hWnd = GetParent(hWnd) ; // 透明视窗 LONG style = GetWindowLong( hWnd, GWL_EXSTYLE); style = style | WS_EX_LAYERED; SetWindowLong( hWnd, GWL_EXSTYLE, style); SetLayeredWindowAttributes(hWnd, RGB(255,255,255), 0, LWA_COLORKEY); // 无边框无标题,无效 style = GetWindowLong(hWnd, GWL_STYLE); style = style & (~WS_CAPTION) & ~(WS_BORDER) & ~WS_THICKFRAME; SetWindowLong( hWnd, GWL_STYLE, style);

 哦了,窗口建立好了,重点还是在后面要做什么啊!参考了网上好多资料感觉这个最简单,帖出来分享下同时做个笔记~

原创粉丝点击