简体   繁体   中英

Is WM_KEYDOWN constant defined in C# assemblies?

I am going to use WM_KEYDOWN and other WM_ messages in a C# program. Are these constants defined somewhere or they should be defined in every program manually?

Because these constants are defined in winapi libraries and not .net you will need to recreate them yourself somewhere. The functions that use these constants are also defined in winapi and so you will need to use interop to use them in your applications. http://www.pinvoke.net/ is a good resource for protyping the interop versions of these winapi constants and functions.

Most of them can be found here: http://www.pinvoke.net/default.aspx/Constants.WM

Code fragment from that page:

/// <summary>
  /// Windows Messages
  /// Defined in winuser.h from Windows SDK v6.1
  /// Documentation pulled from MSDN.
  /// </summary>
  public enum WM : uint
  {
    /// <summary>
    /// The WM_NULL message performs no operation. An application sends the WM_NULL message if it wants to post a message that the recipient window will ignore.
    /// </summary>
    NULL = 0x0000,
    /// <summary>
    /// The WM_CREATE message is sent when an application requests that a window be created by calling the CreateWindowEx or CreateWindow function. (The message is sent before the function returns.) The window procedure of the new window receives this message after the window is created, but before the window becomes visible.
    /// </summary>
    CREATE = 0x0001,
    /// <summary>
    /// The WM_DESTROY message is sent when a window is being destroyed. It is sent to the window procedure of the window being destroyed after the window is removed from the screen. 
    /// This message is sent first to the window being destroyed and then to the child windows (if any) as they are destroyed. During the processing of the message, it can be assumed that all child windows still exist.
    /// /// </summary>
    DESTROY = 0x0002,
    ...

You should define them manually. You can search for their values in the PInvoke.Net site. For example the WM constants can be found here

C# PInvoke Interop WM Messages

Using this site you could create (for both VB.NET and C#) just the constants that your program requires.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM