ホテル管理システム
ogi
yesterday 1a1c8e71fcd14858f595029f089b2d4a00202b32
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
 
namespace HotelPms.Share.Windows.Component
{
    /// <summary>
    /// •Û—¯‚³‚ê‚Ä‚¢‚éƒEƒBƒ“ƒhƒEƒƒbƒZ[ƒW‚ðíœ
    /// </summary>
    public static class RemovePeekMessage
    {
        #region ’萔
        /// <summary>
        /// ŠY“–‚·‚éƒEƒBƒ“ƒhƒE‚ɍĕ`‰æ‚ª•K—v‚ÆOS‚ª”»’f‚µ‚½‚Æ‚«‚Ƀ|ƒXƒg‚³‚ê‚郁ƒbƒZ[ƒW
        /// </summary>
        private const int WM_PAINT = 0xF;
 
        /// <summary>
        ///  ƒEƒBƒ“ƒhƒE‚̃Nƒ‰ƒCƒAƒ“ƒg—̈æ‚ц[ƒU[‚ªƒ}ƒEƒX‚̈ړ®‚ð‚µ‚½‚Æ‚«‚Ƀ|ƒXƒg‚³‚ê‚郁ƒbƒZ[ƒW
        /// </summary>
        private const int WM_MOUSEMOVE = 0x200;
 
        /// <summary>
        /// ƒEƒBƒ“ƒhƒE‚̃Nƒ‰ƒCƒAƒ“ƒg—̈æ‚ц[ƒU[‚ªƒ}ƒEƒX‚̍¶ƒ{ƒ^ƒ“‚ð‰Ÿ‚µ‚½‚Æ‚«‚Ƀ|ƒXƒg‚³‚ê‚郁ƒbƒZ[ƒW
        /// </summary>
        private const int WM_LBUTTONDOWN = 0x201;
 
        /// <summary>
        /// ƒEƒBƒ“ƒhƒE‚̃Nƒ‰ƒCƒAƒ“ƒg—̈æ‚ц[ƒU[‚ªƒ}ƒEƒX‚̍¶ƒ{ƒ^ƒ“‚𗣂µ‚½‚Æ‚«‚Ƀ|ƒXƒg‚³‚ê‚郁ƒbƒZ[ƒW
        /// </summary>
        private const int WM_LBUTTONUP = 0x202;
 
        /// <summary>
        /// ƒ}ƒEƒXƒ|ƒCƒ“ƒ^‚ª—̈æŠO‚ɏo‚½Žž‚Ƀ|ƒXƒg‚³‚ê‚郁ƒbƒZ[ƒW
        /// </summary>
        private const int WM_MOUSELEAVE = 0x2A3;
 
        private const int WM_KEYFIRST = 0x100;
        private const int WM_KEYLAST = 0x109;
 
        private const int WM_MOUSEFIRST = 0x200;
        private const int WM_MOUSELAST = 0x20D;
 
        #endregion
 
        #region \‘¢‘Ì
        /// <summary>
        /// MSG \‘¢‘ÌŒ^
        /// </summary>
        [StructLayout(LayoutKind.Sequential)]
        public struct MSG
        {
            /// <summary>
            /// ƒEƒBƒ“ƒhƒEƒnƒ“ƒhƒ‹
            /// </summary>
            public IntPtr hWnd;
            /// <summary>
            /// MessageID
            /// </summary>
            public int msg;
            /// <summary>
            /// WParamƒtƒB[ƒ‹ƒhiMessageID‚²‚ƂɈႤ‚æ)
            /// </summary>
            public IntPtr wParam;
            /// <summary>
            /// LParamƒtƒB[ƒ‹ƒhiMessageID‚²‚ƂɈႤ‚æ)
            /// </summary>
            public IntPtr lParam;
            /// <summary>
            /// ŽžŠÔ
            /// </summary>
            public int time;
            /// <summary>
            /// ƒJ[ƒ\ƒ‹ˆÊ’uiƒXƒNƒŠ[ƒ“À•Wj
            /// </summary>
            public POINTAPI pt;
        }
 
        /// <summary>
        /// POINTAPI\‘¢‘Ì
        /// </summary>
        [StructLayout(LayoutKind.Sequential)]
        public struct POINTAPI
        {
            /// <summary>
            /// XÀ•W
            /// </summary>
            public int x;
            /// <summary>
            /// YÀ•W
            /// </summary>
            public int y;
        }
        #endregion
 
        #region —ñ‹“Œ^
        /// <summary>
        /// wRemoveMsg‚Å—˜—p‰Â”\‚ȃIƒvƒVƒ‡ƒ“
        /// </summary>
        enum EPeekMessageOption
        {
            /// <summary>
            /// ˆ—ŒãƒƒbƒZ[ƒW‚ðƒLƒ…[‚©‚çíœ‚µ‚È‚¢
            /// </summary>
            PM_NOREMOVE = 0,
            /// <summary>
            /// ˆ—ŒãƒƒbƒZ[ƒW‚ðƒLƒ…[‚©‚çíœ‚·‚é
            /// </summary>
            PM_REMOVE
        }
        #endregion
 
        #region DllImport
        /// <summary>
        /// ƒXƒŒƒbƒh‚̃ƒbƒZ[ƒWƒLƒ…[‚ɃƒbƒZ[ƒW‚ª‚ ‚é‚©‚Ç‚¤‚©‚ðƒ`ƒFƒbƒN‚µ
        /// ‚ ‚ê‚΁AŽw’肳‚ꂽ\‘¢‘̂ɂ»‚̃ƒbƒZ[ƒW‚ðŠi”[‚µ‚Ü‚·
        /// </summary>
        /// <param name="lpMsg"> ƒƒbƒZ[ƒWî•ñ‚ðŠi”[‚·‚éAMSG \‘¢‘ÌŒ^•ϐ”‚̃|ƒCƒ“ƒ^‚ðŽw’肵‚Ü‚·</param>
        /// <param name="hWnd">ƒƒbƒZ[ƒW‚ðŽæ“¾‚·‚éƒEƒBƒ“ƒhƒE‚̃nƒ“ƒhƒ‹‚ðŽw’肵‚Ü‚·B‘S‚Ă̏ꍇ‚Í NULL</param>
        /// <param name="wMsgFilterMin">ƒƒbƒZ[ƒW‚̍ŏ¬’l‚ðŽw’肵AƒtƒBƒ‹ƒ^ƒŠƒ“ƒO‚µ‚Ü‚·B‚µ‚È‚¢ê‡‚Í0</param>
        /// <param name="wMsgFilterMax">ƒƒbƒZ[ƒW‚̍őå’l‚ðŽw’肵AƒtƒBƒ‹ƒ^ƒŠƒ“ƒO‚µ‚Ü‚·B‚µ‚È‚¢ê‡‚Í0</param>
        /// <param name="wRemoveMsg">ˆ—ŒãƒƒbƒZ[ƒW‚ðƒLƒ…[‚ðíœ‚·‚é‚©”Û‚©</param>
        /// <returns>ƒƒbƒZ[ƒW‚ðŽæ“¾‚µ‚½‚Æ‚«‚Í 0 ˆÈŠOAŽæ“¾‚µ‚È‚©‚Á‚½‚Æ‚«‚Í 0</returns>
        [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
        [return: MarshalAs(UnmanagedType.Bool)]
        private static extern bool PeekMessage(
            out MSG lpMsg,
            int hWnd,
            int wMsgFilterMin,
            int wMsgFilterMax,
            EPeekMessageOption wRemoveMsg
        );
 
        /// <summary>
        /// Žw’肳‚ꂽ MSG \‘¢‘ÌŒ^•ϐ”‚ɃƒbƒZ[ƒW‚ðŠi”[‚µ‚Ü‚·
        /// </summary>
        /// <param name="lpMsg">ƒƒbƒZ[ƒWî•ñ‚ðŠi”[‚·‚éAMSG \‘¢‘ÌŒ^•ϐ”‚̃|ƒCƒ“ƒ^‚ðŽw’肵‚Ü‚·</param>
        /// <param name="hWnd">ƒƒbƒZ[ƒW‚ðŽæ“¾‚·‚éƒEƒBƒ“ƒhƒE‚̃nƒ“ƒhƒ‹‚ðŽw’肵‚Ü‚·B‘S‚Ă̏ꍇ‚Í NULL</param>
        /// <param name="wMsgFilterMin">ƒƒbƒZ[ƒW‚̍ŏ¬’l‚ðŽw’肵AƒtƒBƒ‹ƒ^ƒŠƒ“ƒO‚µ‚Ü‚·B‚µ‚È‚¢ê‡‚Í0</param>
        /// <param name="wMsgFilterMax">ƒƒbƒZ[ƒW‚̍őå’l‚ðŽw’肵AƒtƒBƒ‹ƒ^ƒŠƒ“ƒO‚µ‚Ü‚·B‚µ‚È‚¢ê‡‚Í0</param>
        /// <returns></returns>
        [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
        [return: MarshalAs(UnmanagedType.Bool)]
        private static extern bool GetMessage(
            out MSG lpMsg,
            int hWnd,
            int wMsgFilterMin,
            int wMsgFilterMax
        );
 
        /// <summary>
        /// Žw’肳‚ꂽƒEƒBƒ“ƒhƒEƒƒbƒZ[ƒW‚ðƒEƒBƒ“ƒhƒEƒvƒƒV[ƒWƒƒ‚ɃfƒBƒXƒpƒbƒ`‚µ‚Ü‚·
        /// </summary>
        /// <param name="lpMsg">ƒfƒBƒXƒpƒbƒ`‚·‚郁ƒbƒZ[ƒW‚ðŠi”[‚µ‚½ MSG \‘¢‘̕ϐ”‚̃|ƒCƒ“ƒ^‚ðŽw’肵‚Ü‚·</param>
        /// <returns>ƒEƒBƒ“ƒhƒEƒvƒƒV[ƒWƒƒ‚Ì–ß‚è’l</returns>
        [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
        private static extern IntPtr DispatchMessage(
             out MSG lpMsg
        );
        #endregion
 
        #region ƒƒ\ƒbƒh
        /// <summary>
        /// •Û—¯‚³‚ê‚Ä‚¢‚éƒEƒBƒ“ƒhƒEƒƒbƒZ[ƒW‚ðíœ‚µ‚Ü‚·B
        /// </summary>
        public static void Invoke()
        {
            //Console.WriteLine("y¦zRemovePeekMessage.Invoke():‚±‚ÌŽž“_‚̃Cƒxƒ“ƒg‚·‚ׂč폜ŽÀsŠJŽn");
            MSG wm;
            while (PeekMessage(out wm, 0, WM_KEYFIRST, WM_KEYLAST, EPeekMessageOption.PM_REMOVE)) { }
            while (PeekMessage(out wm, 0, WM_MOUSEFIRST, WM_MOUSELAST, EPeekMessageOption.PM_REMOVE)) { }
 
 
#if false
            System.Diagnostics.Debug.WriteLine("Invoke begin");
            MSG wm;
            while (true)
            {
                bool ret = PeekMessage(out wm, 0, 0, 0, EPeekMessageOption.PM_REMOVE);
                System.Diagnostics.Debug.WriteLine(wm.msg.ToString());
                System.Diagnostics.Debug.WriteLine(ret.ToString());
                if (!ret) { break; }
 
                switch (wm.msg)
                {
                    case WM_LBUTTONUP:
                    case WM_MOUSELEAVE:
                    case WM_PAINT:
                        System.Diagnostics.Debug.WriteLine(wm.msg.ToString());
                        DispatchMessage(out wm);
                        break;
                }
            }
            System.Diagnostics.Debug.WriteLine("Invoke end");
#endif
        }
        #endregion
    }
}