WPF&MFC&Opencv透明全屏無邊框視窗建立

來源:互聯網
上載者:User
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 closeprivate 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 iconSendMessage(WM_SYSCOMMAND,SC_MAXIMIZE,0);//full screenHWND 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 windowsSetWindowLong(this->GetSafeHwnd(),GWL_EXSTYLE,GetWindowLong(this->GetSafeHwnd(),GWL_EXSTYLE)^WS_EX_LAYERED);HINSTANCE hInst = LoadLibrary(L"User32.DLL"); //明確式載入DLLif(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 widthint cy=::GetSystemMetrics(SM_CYSCREEN);//get screen hightreturn 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);哦了,視窗建立好了,重點還是在後面要做什麼啊!參考了網上好多資料感覺這個最簡單,帖出來分享下同時做個筆記~改了下結果全成代碼了,懶得弄了~

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.