English 中文(简体)
员额似乎没有工作
原标题:PostMessage does not seem to be working

我正试图利用后马斯派一个表态钥匙。

我的守则是:

// This class allows us to send a tab key when the the enter key
//  is pressed for the mooseworks mask control.   
public class MaskKeyControl : MaskedEdit
{
//  [DllImport("coredll.dll", SetLastError = true, CharSet = CharSet.Auto)]
//  static extern IntPtr SendMessage(IntPtr hWnd, UInt32 Msg, Int32 wParam, Int32 lParam);

    [return: MarshalAs(UnmanagedType.Bool)]
    // I am calling this on a Windows Mobile device so the dll is coredll.dll
    [DllImport("coredll.dll", SetLastError = true)]
    static extern bool PostMessage(IntPtr hWnd, uint Msg, Int32 wParam, Int32 lParam);

    public const Int32 VK_TAB = 0x09;
    public const Int32 WM_KEYDOWN = 0x100;

    protected override void OnKeyDown(KeyEventArgs e)
    {
        if (e.KeyData == Keys.Enter)
        {
            PostMessage(this.Handle, WM_KEYDOWN, VK_TAB, 0);
            return;
        }
        base.OnKeyDown(e);
    }

    protected override void OnKeyPress(KeyPressEventArgs e)
    {
        if (e.KeyChar ==  
 ) 
            e.Handled = true;
        base.OnKeyPress(e);
    }
}

当我报到这部法典时,没有发生。 然后,我向TAB施加压力,并做罚款。 (我寄来的塔信是错误的)

最佳回答

确实,你应当提供与用户直接对窗口控制的投入有关的短信。 相反,如果你想要模拟投入,那么你就应当依靠 附录Input AP=,而不是发送关键新闻。

此外,正如克里斯·泰勒在其评论中提到的那样,SendKeys par,如果你想要利用现有的有管理的包装人(而不是通过P/Invoke层调用SendInput功能)。

问题回答

关键事件的后遗症确实令人感到奇怪。

在这种情况下,可能与KEYDOWN、KEYPRESS、KEYUP(三条电话)进行更好的工作。

除了向控制机构发出投入信息之外,你还可以更明确,并做以下工作。

protected override void OnKeyDown(KeyEventArgs e)
{
  if (e.KeyCode == Keys.Enter)
  {
    if (Parent != null)
    {
      Control nextControl = Parent.GetNextControl(this, true);
      if (nextControl != null)
      {
        nextControl.Focus();
        return;
      }
    }
  }
  base.OnKeyDown(e);
}

这将在进入钥匙时把重点放在对父母的下一个控制上。





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签