如何取消隐藏WPF窗口上的X按钮

时间:2016-04-19 16:08:01

标签: c# wpf winforms webbrowser-control window-handles

我正在使用以下机制,一旦事务开始处理,我就会阻止代理关闭窗口,如何将它们放回去?

我通过删除~ WS_SYSMENUSetWindowLong(hwnd, GWL_STYLE, GetWindowLong(hwnd, GWL_STYLE) & WS_SYSMENU);前面的 public class WithoutCloseButton : Window { private const int GWL_STYLE = -16; private const int WS_SYSMENU = 0x80000; [DllImport("user32.dll", SetLastError = true)] private static extern int GetWindowLong(IntPtr hWnd, int nIndex); [DllImport("user32.dll")] private static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong); public void HideButtons() { var hwnd = new WindowInteropHelper(this).Handle; SetWindowLong(hwnd, GWL_STYLE, GetWindowLong(hwnd, GWL_STYLE) & ~WS_SYSMENU); } public void ShowButtons() { var hwnd = new WindowInteropHelper(this).Handle; SetWindowLong(hwnd, GWL_STYLE, GetWindowLong(hwnd, GWL_STYLE) & WS_SYSMENU); } } private void OpenBrowser(PaymentViewModel viewModel, Uri uri) { viewModel.BrowserWindow = new WithoutCloseButton(); viewModel.BrowserWindow.Closed += BrowserWindow_Closed; var browser = new MyWebBrowser(); var scrollviewer = new ScrollViewer(); var stackPanel = new StackPanel { Orientation = System.Windows.Controls.Orientation.Vertical}; var formsHost = new WindowsFormsHost {Child = browser}; stackPanel.Children.Add(formsHost); scrollviewer.Content = stackPanel; viewModel.BrowserWindow.Content = scrollviewer; viewModel.BrowserWindow.Width = browser.Width = (int)System.Windows.SystemParameters.PrimaryScreenWidth; viewModel.BrowserWindow.Height = browser.Height = (int)System.Windows.SystemParameters.PrimaryScreenHeight; viewModel.BrowserWindow.Top = viewModel.BrowserWindow.Left = 0; viewModel.BrowserWindow.Show(); browser.Show(); browser.Navigate("about:blank"); browser.DocumentCompleted += delegate(object obj, WebBrowserDocumentCompletedEventArgs e) { var urlInLower = e.Url.ToString().ToLower(); if (urlInLower == "about:blank") { ((MyWebBrowser)obj).Navigate(uri); } if (urlInLower.Contains("accepted")) { ViewModel.AuthCode = this.GetAuthToken(); ViewModel.updateUiWhenDoneWithPayment_RunWorkerCompleted(new object(), null); ViewModel.BrowserWindow.Close(); ViewModel.BrowserWindow = null; } if (urlInLower.Contains("payment/processing")) { viewModel.BrowserWindow.HideButtons(); } if (urlInLower.Contains("payment/error")) { viewModel.BrowserWindow.ShowButtons(); } }; 来取消按位取消NOT。但

隐藏按钮的代码看起来像ATM:

alert(textStatus+":"+errorThrown);

1 个答案:

答案 0 :(得分:1)

public void ShowButtons()
{
    var hwnd = new WindowInteropHelper(this).Handle;
    //SetWindowLong(hwnd, GWL_STYLE, GetWindowLong(hwnd, GWL_STYLE) & WS_SYSMENU);
    SetWindowLong(hwnd, GWL_STYLE, GetWindowLong(hwnd, GWL_STYLE) | WS_SYSMENU);
}

&(and)没有将WS_SYSMENU添加到style,如果在style上设置了它,则返回该标志。

style | b //sets `b` flag on `style`
style & ~b //clears `b` flag from `style`