Message.cs 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. // Permission is hereby granted, free of charge, to any person obtaining
  2. // a copy of this software and associated documentation files (the
  3. // "Software"), to deal in the Software without restriction, including
  4. // without limitation the rights to use, copy, modify, merge, publish,
  5. // distribute, sublicense, and/or sell copies of the Software, and to
  6. // permit persons to whom the Software is furnished to do so, subject to
  7. // the following conditions:
  8. //
  9. // The above copyright notice and this permission notice shall be
  10. // included in all copies or substantial portions of the Software.
  11. //
  12. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  13. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  14. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  15. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  16. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  17. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  18. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  19. //
  20. // Copyright (c) 2004 Novell, Inc.
  21. //
  22. // Authors:
  23. // Peter Bartok [email protected]
  24. // COMPLETE
  25. using System;
  26. using System.Runtime.InteropServices;
  27. using System.Text;
  28. using System.Diagnostics;
  29. namespace System.Windows.Forms {
  30. public struct Message {
  31. private int msg;
  32. private IntPtr hwnd;
  33. private IntPtr lParam;
  34. private IntPtr wParam;
  35. private IntPtr result;
  36. #region Public Instance Properties
  37. public IntPtr HWnd {
  38. get { return hwnd; }
  39. set { hwnd=value; }
  40. }
  41. public IntPtr LParam {
  42. get { return lParam; }
  43. set { lParam=value; }
  44. }
  45. public int Msg {
  46. get { return msg; }
  47. set { msg=value; }
  48. }
  49. public IntPtr Result {
  50. get { return result; }
  51. set { result=value; }
  52. }
  53. public IntPtr WParam {
  54. get { return wParam; }
  55. set { wParam=value; }
  56. }
  57. #endregion // Public Instance Properties
  58. #region Public Static Methods
  59. public static Message Create(IntPtr hWnd, int msg, IntPtr wparam, IntPtr lparam) {
  60. Message new_message = new Message();
  61. new_message.msg=msg;
  62. new_message.hwnd=hWnd;
  63. new_message.wParam=wparam;
  64. new_message.lParam=lparam;
  65. return new_message;
  66. }
  67. #endregion // Public Static Methods
  68. #region Public Instance Methods
  69. public override bool Equals(object o) {
  70. if (!(o is Message)) {
  71. return false;
  72. }
  73. return ((this.msg == ((Message)o).msg) &&
  74. (this.hwnd == ((Message)o).hwnd) &&
  75. (this.lParam == ((Message)o).lParam) &&
  76. (this.wParam == ((Message)o).wParam) &&
  77. (this.result == ((Message)o).result));
  78. }
  79. public override int GetHashCode() {
  80. return base.GetHashCode();
  81. }
  82. public object GetLParam(Type cls) {
  83. object o = Marshal.PtrToStructure(this.lParam, cls);
  84. return(o);
  85. }
  86. public override string ToString() {
  87. return String.Format("[{0} {1} {2} {3}]", msg.ToString(), lParam.ToString(), wParam.ToString(), hwnd.ToString());
  88. }
  89. #endregion // Public Instance Methods
  90. }
  91. }