2、NativeMethods類定義:
1: // 功能:Windows API調用
2: // 描述:大家可以參照MSDN
3: // 作者:溫偉鵬
4: // 日期:2009-02-08
5:
6: using System;
7: using System.Collections.Generic;
8: using System.Text;
9: using System.Runtime.InteropServices;
10:
11: namespace GEDemo
12: {
13: public class NativeMethods
14: {
15: [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
16: public static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int x, int y, int cx, int cy, UInt32 uflags);
17:
18: [DllImport("user32.dll", CharSet = CharSet.Auto)]
19: public static extern IntPtr PostMessage(int hWnd, int msg, int wParam, int lParam);
20:
21: #region 預定義
22:
23: public static readonly IntPtr HWND_BOTTOM = new IntPtr(1);
24: public static readonly IntPtr HWND_NOTOPMOST = new IntPtr(-2);
25: public static readonly IntPtr HWND_TOP = new IntPtr(0);
26: public static readonly IntPtr HWND_TOPMOST = new IntPtr(-1);
27: public static readonly UInt32 SWP_NOSIZE = 1;
28: public static readonly UInt32 SWP_NOMOVE = 2;
29: public static readonly UInt32 SWP_NOZORDER = 4;
30: public static readonly UInt32 SWP_NOREDRAW = 8;
31: public static readonly UInt32 SWP_NOACTIVATE = 16;
32: public static readonly UInt32 SWP_FRAMECHANGED = 32;
33: public static readonly UInt32 SWP_SHOWWINDOW = 64;
34: public static readonly UInt32 SWP_HIDEWINDOW = 128;
35: public static readonly UInt32 SWP_NOCOPYBITS = 256;
36: public static readonly UInt32 SWP_NOOWNERZORDER = 512;
37: public static readonly UInt32 SWP_NOSENDCHANGING = 1024;
38:
39: #endregion
40:
41: public delegate int EnumWindowsProc(IntPtr hwnd, int lParam);
42:
43: [DllImport("user32", CharSet = CharSet.Auto)]
44: public extern static IntPtr GetParent(IntPtr hWnd);
45:
46: [DllImport("user32", CharSet = CharSet.Auto)]
47: public extern static bool MoveWindow(IntPtr hWnd, int X, int Y, int nWidth, int nHeight, bool bRepaint);
48:
49: [DllImport("user32", CharSet = CharSet.Auto)]
50: public extern static IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent);
51:
52: [DllImport("user32.dll", ExactSpelling = true, CharSet = CharSet.Auto)]
53: public static extern IntPtr GetWindow(IntPtr hWnd, int uCmd);
54:
55: public static int GW_CHILD = 5;
56: public static int GW_HWNDNEXT = 2;
57: }
58: }
3、執行效果: