1
using
System;
2 using System.Collections.Generic;
3 using System.ComponentModel;
4 using System.Windows.Forms;
5 using System.Runtime.InteropServices;
6 using System.Text;
7
8 namespace Hello_World
9 {
10 public partial class StartForm : Form
11 {
12 private Timer timer;
13 public StartForm()
14 {
15
16 InitializeComponent();
17 IntPtr hWnd = API.FindWindow(this.Text);
18 if (hWnd != IntPtr.Zero)
19 {
20 System.Diagnostics.Debug.WriteLine("hWnd ist nicht null");
21 this.MaximizeBox = false;
22 this.MinimizeBox = false;
23 this.Focus();
24
25 SHAPI.SetForegroundWindow(hWnd);
26 SHAPI.FullScreen(hWnd);
27 }
28 }
29 }
30
31 public class API
32 {
33 [DllImport("coredll.dll", EntryPoint = "FindWindow")]
34 private extern static IntPtr FindWindow(string lpClassName, string lpWindowName);
35
36 public static IntPtr FindWindow(string windowName)
37 {
38 return FindWindow(null, windowName);
39 }
40 }
41
42 public class SHAPI
43 {
44 public const int SHFS_SHOWTASKBAR = 1;
45 public const int SHFS_HIDETASKBAR = 2;
46 public const int SHFS_SHOWSIPBUTTON = 4;
47 public const int SHFS_HIDESIPBUTTON = 8;
48 public const int SHFS_SHOWSTARTICON = 16;
49 public const int SHFS_HIDESTARTICON = 32;
50
51 [DllImport("aygshell.dll")]
52 private extern static bool SHFullScreen(IntPtr hWnd, int dwState);
53
54 public static bool FullScreen(IntPtr hWnd)
55 {
56 return SHFullScreen(hWnd, SHFS_HIDESTARTICON | SHFS_HIDETASKBAR);
57 }
58
59 [DllImport("coredll.dll")]
60 internal static extern int SetForegroundWindow(IntPtr hWnd);
61 }
62}
63
64
65 下面的代码仅仅隐藏开始菜单但程序退出后会重现
66
67 using System;
68 using System.Collections.Generic;
69 using System.ComponentModel;
70 using System.Windows.Forms;
71 using System.Runtime.InteropServices;
72 using System.Text;
73
74 namespace Wm5ppc
75 {
76 public partial class Form1 : Form
77 {
78 public Form1 ()
79 {
80 InitializeComponent ();
81 this.MinimizeBox = false;
82 }
83 private void Form1_Activated (object sender, EventArgs e)
84 {
85 IntPtr hWnd = this.Handle;
86 SHAPI.FullScreen (hWnd);
87 }
88 }
89
90 public class SHAPI
91 {
92 public const int SHFS_SHOWTASKBAR = 1;
93 public const int SHFS_HIDETASKBAR = 2;
94 public const int SHFS_SHOWSIPBUTTON = 4;
95 public const int SHFS_HIDESIPBUTTON = 8;
96 public const int SHFS_SHOWSTARTICON = 16;
97 public const int SHFS_HIDESTARTICON = 32;
98 [DllImport ("aygshell.dll")]
99 private extern static bool SHFullScreen (IntPtr hWnd, int dwState);
100
101 public static bool FullScreen (IntPtr hWnd)
102 {
103 return SHFullScreen (hWnd, SHFS_HIDESTARTICON);
104 }
105 }
106}
2 using System.Collections.Generic;
3 using System.ComponentModel;
4 using System.Windows.Forms;
5 using System.Runtime.InteropServices;
6 using System.Text;
7
8 namespace Hello_World
9 {
10 public partial class StartForm : Form
11 {
12 private Timer timer;
13 public StartForm()
14 {
15
16 InitializeComponent();
17 IntPtr hWnd = API.FindWindow(this.Text);
18 if (hWnd != IntPtr.Zero)
19 {
20 System.Diagnostics.Debug.WriteLine("hWnd ist nicht null");
21 this.MaximizeBox = false;
22 this.MinimizeBox = false;
23 this.Focus();
24
25 SHAPI.SetForegroundWindow(hWnd);
26 SHAPI.FullScreen(hWnd);
27 }
28 }
29 }
30
31 public class API
32 {
33 [DllImport("coredll.dll", EntryPoint = "FindWindow")]
34 private extern static IntPtr FindWindow(string lpClassName, string lpWindowName);
35
36 public static IntPtr FindWindow(string windowName)
37 {
38 return FindWindow(null, windowName);
39 }
40 }
41
42 public class SHAPI
43 {
44 public const int SHFS_SHOWTASKBAR = 1;
45 public const int SHFS_HIDETASKBAR = 2;
46 public const int SHFS_SHOWSIPBUTTON = 4;
47 public const int SHFS_HIDESIPBUTTON = 8;
48 public const int SHFS_SHOWSTARTICON = 16;
49 public const int SHFS_HIDESTARTICON = 32;
50
51 [DllImport("aygshell.dll")]
52 private extern static bool SHFullScreen(IntPtr hWnd, int dwState);
53
54 public static bool FullScreen(IntPtr hWnd)
55 {
56 return SHFullScreen(hWnd, SHFS_HIDESTARTICON | SHFS_HIDETASKBAR);
57 }
58
59 [DllImport("coredll.dll")]
60 internal static extern int SetForegroundWindow(IntPtr hWnd);
61 }
62}
63
64
65 下面的代码仅仅隐藏开始菜单但程序退出后会重现
66
67 using System;
68 using System.Collections.Generic;
69 using System.ComponentModel;
70 using System.Windows.Forms;
71 using System.Runtime.InteropServices;
72 using System.Text;
73
74 namespace Wm5ppc
75 {
76 public partial class Form1 : Form
77 {
78 public Form1 ()
79 {
80 InitializeComponent ();
81 this.MinimizeBox = false;
82 }
83 private void Form1_Activated (object sender, EventArgs e)
84 {
85 IntPtr hWnd = this.Handle;
86 SHAPI.FullScreen (hWnd);
87 }
88 }
89
90 public class SHAPI
91 {
92 public const int SHFS_SHOWTASKBAR = 1;
93 public const int SHFS_HIDETASKBAR = 2;
94 public const int SHFS_SHOWSIPBUTTON = 4;
95 public const int SHFS_HIDESIPBUTTON = 8;
96 public const int SHFS_SHOWSTARTICON = 16;
97 public const int SHFS_HIDESTARTICON = 32;
98 [DllImport ("aygshell.dll")]
99 private extern static bool SHFullScreen (IntPtr hWnd, int dwState);
100
101 public static bool FullScreen (IntPtr hWnd)
102 {
103 return SHFullScreen (hWnd, SHFS_HIDESTARTICON);
104 }
105 }
106}
如果想实现程序完全全屏,可以设置Form的WindowState属性为Maximized,并且移除MainMenu1控件
Trackback: http://tb.blog.csdn.net/TrackBack.aspx?PostId=1570064