Message.cs 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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. //
  25. //
  26. // $Revision: 1.1 $
  27. // $Modtime: $
  28. // $Log: Message.cs,v $
  29. // Revision 1.1 2004/07/09 05:21:25 pbartok
  30. // - Initial check-in
  31. //
  32. //
  33. // COMPLETE
  34. using System;
  35. using System.Runtime.InteropServices;
  36. using System.Text;
  37. using System.Diagnostics;
  38. namespace System.Windows.Forms {
  39. public struct Message {
  40. private int msg;
  41. private IntPtr hwnd;
  42. private IntPtr lParam;
  43. private IntPtr wParam;
  44. private IntPtr result;
  45. #region Public Instance Properties
  46. public IntPtr Hwnd {
  47. get { return hwnd; }
  48. set { hwnd=value; }
  49. }
  50. public IntPtr LParam {
  51. get { return lParam; }
  52. set { lParam=value; }
  53. }
  54. public int Msg {
  55. get { return msg; }
  56. set { msg=value; }
  57. }
  58. public IntPtr Result {
  59. get { return result; }
  60. set { result=value; }
  61. }
  62. public IntPtr WParam {
  63. get { return wParam; }
  64. set { wParam=value; }
  65. }
  66. #endregion // Public Instance Properties
  67. #region Public Static Methods
  68. public static Message Create(IntPtr hWnd, int msg, IntPtr wparam, IntPtr lparam) {
  69. Message new_message = new Message();
  70. new_message.msg=msg;
  71. new_message.hwnd=hWnd;
  72. new_message.wParam=wparam;
  73. new_message.lParam=lparam;
  74. return new_message;
  75. }
  76. #endregion // Public Static Methods
  77. #region Public Instance Methods
  78. public override bool Equals(object o) {
  79. if (!(o is Message)) {
  80. return false;
  81. }
  82. return (this == (Message)o);
  83. }
  84. public static bool operator == (Message msg_a, Message msg_b) {
  85. return ((msg_a.msg == msg_b.msg) &&
  86. (msg_a.hwnd == msg_b.hwnd) &&
  87. (msg_a.lParam == msg_b.lParam) &&
  88. (msg_a.wParam == msg_b.wParam) &&
  89. (msg_a.result == msg_b.result));
  90. }
  91. public static bool operator != (Message msg_a, Message msg_b) {
  92. return ((msg_a.msg != msg_b.msg) ||
  93. (msg_a.hwnd != msg_b.hwnd) ||
  94. (msg_a.lParam != msg_b.lParam) ||
  95. (msg_a.wParam != msg_b.wParam) ||
  96. (msg_a.result != msg_b.result));
  97. }
  98. public override int GetHashCode() {
  99. return base.GetHashCode();
  100. }
  101. public object GetLParam(Type cls) {
  102. object o = Marshal.PtrToStructure(this.lParam, cls);
  103. return(o);
  104. }
  105. public override string ToString() {
  106. return String.Format("[{0} {1} {2} {3}]", msg.ToString(), lParam.ToString(), wParam.ToString(), hwnd.ToString());
  107. }
  108. #endregion // Public Instance Methods
  109. }
  110. }