- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
遵循 MS 指南,我的 WPF 应用程序的 App 构造函数包含以下代码以实现正确的焦点行为:
HwndSource.DefaultAcquireHwndFocusInMenuMode = false;
Keyboard.DefaultRestoreFocusMode = RestoreFocusMode.None;
如
this article 中所述,这些设置可防止焦点窃取。
最佳答案
我通过执行以下操作来防止我的 wpf 窗口获得焦点,我仍然可以通过使用 ALT-TAB 或单击它的任务栏项来激活它。
在这里,您可以更改窗口上的窗口样式,使其没有激活。
var yourWindow = new YourWindowType();
//set the windowstyle to noactivate so the window doesn't get focus
yourWindow.SourceInitialized += (s, e) =>
{
var interopHelper = new WindowInteropHelper(yourWindow);
int exStyle = User32.GetWindowLong(interopHelper.Handle, (int)WindowLongFlags.GWL_EXSTYLE);
User32.SetWindowLong(interopHelper.Handle, (int)WindowLongFlags.GWL_EXSTYLE, exStyle | (int)WindowStylesEx.WS_EX_NOACTIVATE);
//If you have trouble typing into your form's textboxes then do this
ElementHost.EnableModelessKeyboardInterop(yourWindow);
};
private IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
{
switch (msg)
{
//don't activate the window when you click on it.
case WindowMessage.WM_MOUSEACTIVATE:
handled = true;
return (IntPtr)MouseActivate.MA_NOACTIVATE;
//For Borderless Windows: occurs while dragging. it reports new position before it has been finalized.
//otherwise you wont see the window moving while you're dragging it
case WindowMessage.WM_MOVING:
RECT rect = (RECT)Marshal.PtrToStructure(lParam, typeof(RECT));
User32.SetWindowPos(new WindowInteropHelper(this).Handle, Hwnd.HWND_TOPMOST,
rect.Left, rect.Top, rect.Width, rect.Height,
SetWindowPosFlags.SWP_NOACTIVATE | SetWindowPosFlags.SWP_NOSIZE);
break;
}
return IntPtr.Zero;
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
HwndSource source = HwndSource.FromHwnd(new WindowInteropHelper(this).Handle);
if (source == null) return;
source.AddHook(WndProc);
}
private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
HwndSource source = HwndSource.FromHwnd(new WindowInteropHelper(this).Handle);
if (source == null) return;
source.RemoveHook(WndProc);
}
private void WpfPillForm_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
this.DragMove();
}
[StructLayout(LayoutKind.Sequential)]
public struct WINDOWPOS
{
public IntPtr hwnd;
public IntPtr hwndInsertAfter;
public int x;
public int y;
public int cx;
public int cy;
public int flags;
}
[StructLayout(LayoutKind.Sequential)]
struct RECT
{
public int left, top, right, bottom;
}
public static class MouseActivate
{
public const int MA_ACTIVATE = 1;
public const int MA_ACTIVATEANDEAT = 2;
public const int MA_NOACTIVATE = 3;
public const int MA_NOACTIVATEANDEAT = 4;
}
public enum WindowLongFlags : int
{
GWL_EXSTYLE = -20,
GWLP_HINSTANCE = -6,
GWLP_HWNDPARENT = -8,
GWL_ID = -12,
GWL_STYLE = -16,
GWL_USERDATA = -21,
GWL_WNDPROC = -4,
DWLP_USER = 0x8,
DWLP_MSGRESULT = 0x0,
DWLP_DLGPROC = 0x4
}
public const int WM_MOVING = 0x0216;
public const uint WS_EX_NOACTIVATE = 0x08000000,
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int X, int Y, int cx, int cy, SetWindowPosFlags uFlags);
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
public static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong);
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
public static extern int GetWindowLong(IntPtr hwnd, int index);
关于wpf - 如何防止焦点窃取,但在使用 Alt+Tab 返回我的应用程序时仍能获得焦点?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7618395/
说我有 some text google 我想给h3附加一个点击事件 $("h3").click(function(){ $(this).slideDown(); return false
关闭。这个问题是off-topic .它目前不接受答案。 想改进这个问题? Update the question所以它是on-topic对于堆栈溢出。 10年前关闭。 Improve this qu
据说当您使用 ssl 时,您可以防止中间人从服务器窃取信息到客户端,反之亦然。在我的例子中,窃取了 jsonwebtoken。我还从其他答案中了解到,ssl 使用私钥和公钥。私钥存储在服务器上,公钥提
我已经阅读了 Stack Overflow 上的其他问题,但没有找到这个问题的明确答案: 是什么阻止了攻击者通过 JS 窃取用户的 CSRF token ?他不能直接找到 CSRF 元素并用 JS 获
我认为有人在使用 iframe 窃取我的内容。我的网站是一个论坛,一个用户刚刚向我报告了他们。 如果其他人这样做,我如何以编程方式(php、JavaScript、jQuery、HTML)找到他们的网站
我正在使用 SSL 传输所有数据。 HTTP 已完全禁用。除了恶意软件,或者访问某人的物理机器(这两者都很难从服务器端阻止),我不知道攻击者如何窃取登录 cookie。 因此,不用担心窃取登录 coo
有一个 QQuickPaintedItem 带有重载的鼠标事件处理程序: void Plotter::mousePressEvent(QMouseEvent *event) { qDebug(
我正在学习 Caja,我对“this”-stealing 的概念感到困惑: Another security vulnerability that Caja addresses is called “
如果使用客户端流,则回调 URL 包含访问 token 。那么如果回调URL是通过HTTP发送的,是不是很容易被捕获和滥用。 如果我的应用程序的用户 2 获得用户 1 的访问 token ,他就可以访
http://jsfiddle.net/wzew9/ #menu { width: 1001px; height: 34px; padding: 0; margin: 0; b
我实现了 OnTouchEvent(我需要对 Action.MOVE 和 Action.Up 使用react)和 OnClick,但它从未进入 OnClick。 OnTouch 窃取了事件。如何解决这
当 SplashScreen 关闭时(手动或通过 AutoClose),它会在淡出动画期间窃取 MainWindow 的焦点。这会导致主窗口的标题从事件切换到非事件(灰色)再到事件。有什么技巧可以防止
使用其他用户在受信任站点植入的 javascript 函数很容易窃取 session ID cookie。针对这种攻击有哪些可能的反制措施? 在客户端拒绝所有 javascript 脚本可能很困难,因
我有一个网站想要为登录用户提供 YouTube 视频内容(我自己负责以 SSO 方式登录用户)。 因此,我们的想法是视频只能在嵌入到页面中时才能看到(例如以 iFrame 或类似方式)。复制 URL
我在另一个 NSView 中有几个类 MyView(NSView 的子类)的 View 。 MyView 实现 -mouseEntered:, -mouseExited:, -mouseDown:,
我是 flatbuffer 的新手,我想知道是否可以完全(不是 const*)访问 flatbuffers::Vector 中的数据。看看下面的例子,我想窃取 img2::mem::data 的所有权
我有一个带有用户控件的 ASP.Net 页面。页面的提交按钮在用户控件内。页面本身(在用户控件之外)有一个 ImageButton。每当我按回车键提交表单时,它总是执行 ImageButton 单击而
我在Unity中编写了自己的组件,它实现了IBeginDragHandler、IDragHandler和IDropHandler。我想添加一个 UnityEngine.UI 附带的 EventTrig
我最近开始使用 knockout.js 和 sammy.js 来使我的应用现代化。但是我遇到了一些问题。 我在页面上有一些有效链接 - 用户应该实际导航到该位置,而不是使用 sammy.js 模仿导航
我已将 HTML 模板上传到 themeforest,但我发现有些网站免费提供完整的源代码。因为它是 HTML,anycone 可以轻松复制它。如果用户在其他网站(跟踪 IP)上托管我的模板而无需购买
我是一名优秀的程序员,十分优秀!