XDF.GamePlugInCommon 类库项目
1
//
API.cs 文件,定义一些常用API函数及常量
2
3 using System;
4 using System.IO;
5 using System.Threading;
6 using System.Diagnostics;
7 using System.Runtime.InteropServices;
8
9 namespace XDF.GamePlugInCommon
10 {
11 /**/ /// <summary>
12 /// API 的摘要说明。
13 /// </summary>
14 public sealed class API
15 {
16 public static int WM_KEYDOWN = 0x0100 ;
17 public static int WM_KEYUP = 0x0101 ;
18 public static int WM_SYSKEYDOWN = 0x0104 ;
19 public static int WM_SYSKEYUP = 0x0105 ;
20
21 public static int WM_MOUSEMOVE = 0x0200 ;
22 public static int WM_LBUTTONDOWN = 0x0201 ;
23 public static int WM_LBUTTONUP = 0x0202 ;
24 public static int WM_LBUTTONDBLCLK = 0x0203 ;
25 public static int WM_RBUTTONDOWN = 0x0204 ;
26 public static int WM_RBUTTONUP = 0x0205 ;
27 public static int WM_RBUTTONDBLCLK = 0x0206 ;
28 public static int WM_USER = 0x0400 ;
29
30 public static int MK_LBUTTON = 0x0001 ;
31 public static int MK_RBUTTON = 0x0002 ;
32 public static int MK_SHIFT = 0x0004 ;
33 public static int MK_CONTROL = 0x0008 ;
34 public static int MK_MBUTTON = 0x0010 ;
35
36 public static int MK_XBUTTON1 = 0x0020 ;
37 public static int MK_XBUTTON2 = 0x0040 ;
38
39 [DllImport( " user32.dll " )]
40 public static extern int SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam);
41
42 // 此处主要用来让窗口置于最前(SetWindowPos(this.Handle,-1,0,0,0,0,0x4000|0x0001|0x0002);)
43 [System.Runtime.InteropServices.DllImport( " user32.dll " )]
44 public static extern bool SetWindowPos(IntPtr hWnd,
45 int hWndInsertAfter,
46 int X,
47 int Y,
48 int cx,
49 int cy,
50 int uFlags
51 );
52
53 /**/ /// <summary>
54 /// 窗口置前
55 /// </summary>
56 /// <param name="hWnd"></param>
57 public static void SetWindowPos(IntPtr hWnd)
58 {
59 SetWindowPos(hWnd, - 1 , 0 , 0 , 0 , 0 , 0x4000 | 0x0001 | 0x0002 );
60 }
61
62 /**/ /// <summary>
63 ///
64 /// </summary>
65 /// <param name="processName"></param>
66 /// <returns></returns>
67 public static Process GetGameProcess( string processName)
68 {
69 Process pro = null ;
70 Process[] pros = Process.GetProcessesByName(processName);
71 if (pros.Length > 0 )
72 {
73 pro = pros[ 0 ];
74 }
75 return pro;
76 }
2
3 using System;
4 using System.IO;
5 using System.Threading;
6 using System.Diagnostics;
7 using System.Runtime.InteropServices;
8
9 namespace XDF.GamePlugInCommon
10 {
11 /**/ /// <summary>
12 /// API 的摘要说明。
13 /// </summary>
14 public sealed class API
15 {
16 public static int WM_KEYDOWN = 0x0100 ;
17 public static int WM_KEYUP = 0x0101 ;
18 public static int WM_SYSKEYDOWN = 0x0104 ;
19 public static int WM_SYSKEYUP = 0x0105 ;
20
21 public static int WM_MOUSEMOVE = 0x0200 ;
22 public static int WM_LBUTTONDOWN = 0x0201 ;
23 public static int WM_LBUTTONUP = 0x0202 ;
24 public static int WM_LBUTTONDBLCLK = 0x0203 ;
25 public static int WM_RBUTTONDOWN = 0x0204 ;
26 public static int WM_RBUTTONUP = 0x0205 ;
27 public static int WM_RBUTTONDBLCLK = 0x0206 ;
28 public static int WM_USER = 0x0400 ;
29
30 public static int MK_LBUTTON = 0x0001 ;
31 public static int MK_RBUTTON = 0x0002 ;
32 public static int MK_SHIFT = 0x0004 ;
33 public static int MK_CONTROL = 0x0008 ;
34 public static int MK_MBUTTON = 0x0010 ;
35
36 public static int MK_XBUTTON1 = 0x0020 ;
37 public static int MK_XBUTTON2 = 0x0040 ;
38
39 [DllImport( " user32.dll " )]
40 public static extern int SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam);
41
42 // 此处主要用来让窗口置于最前(SetWindowPos(this.Handle,-1,0,0,0,0,0x4000|0x0001|0x0002);)
43 [System.Runtime.InteropServices.DllImport( " user32.dll " )]
44 public static extern bool SetWindowPos(IntPtr hWnd,
45 int hWndInsertAfter,
46 int X,
47 int Y,
48 int cx,
49 int cy,
50 int uFlags
51 );
52
53 /**/ /// <summary>
54 /// 窗口置前
55 /// </summary>
56 /// <param name="hWnd"></param>
57 public static void SetWindowPos(IntPtr hWnd)
58 {
59 SetWindowPos(hWnd, - 1 , 0 , 0 , 0 , 0 , 0x4000 | 0x0001 | 0x0002 );
60 }
61
62 /**/ /// <summary>
63 ///
64 /// </summary>
65 /// <param name="processName"></param>
66 /// <returns></returns>
67 public static Process GetGameProcess( string processName)
68 {
69 Process pro = null ;
70 Process[] pros = Process.GetProcessesByName(processName);
71 if (pros.Length > 0 )
72 {
73 pro = pros[ 0 ];
74 }
75 return pro;
76 }