Author: Jonas Bilinkevicius
How can I disable the Windows start button and prevent the user from accessing it
by clicking on it or by pressing [CTRL] + [ESC] ?
Answer:
Solve 1:
To disable the Start button:
1 var
2 h: hwnd;
3 begin
4 h := FindWindowEx(FindWindow('Shell_TrayWnd', nil), 0, 'Button', nil);
5 EnableWindow(h, false);
6 end;
But the user can still access the start menu by pressing [CTL] + [ESC] or the
windows key. Even hiding the Start button doesn't work. But hiding the Start button
and using the SetParent function seems to work:
7 var
8 h: hwnd;
9 begin
10 h := FindWindowEx(FindWindow('Shell_TrayWnd', nil), 0, 'Button', nil)
11 ShowWindow(h, 0);
12 Windows.SetParent(h, 0);
13 end;
14
15 //To enable the Start button again:
16
17 var
18 h: hwnd;
19 TaskWindow: hwnd;
20 begin
21 h := FindWindowEx(GetDesktopWindow, 0, 'Button', nil);
22 TaskWindow := FindWindow('Shell_TrayWnd', nil);
23 Windows.SetParent(h, TaskWindow);
24 ShowWindow(h, 1);
25 end;
Furthermore, you could create your own Start button and "replace" it with your own.
26 var
27 b: TButton; {or another button type that can hold a bitmap}
28 h, Window: hwnd;
29 begin
30 Window := FindWindow('Shell_TrayWnd', nil);
31 b := TButton.Create(nil);
32 b.ParentWindow := Window;
33 b.Caption := 'Start';
34 b.Width := 60;
35 b.font.style := [fsbold];
36 end;
Solve 2:
37 procedure TForm1.Button1Click(Sender: TObject);
38 var
39 Rgn: hRgn;
40 begin
41 {Hide the start button}
42 Rgn := CreateRectRgn(0, 0, 0, 0);
43 SetWindowRgn(FindWindowEx(FindWindow('Shell_TrayWnd', nil), 0, 'Button', nil),
44 Rgn,
45 true);
46 end;
47
48 procedure TForm1.Button2Click(Sender: TObject);
49 begin
50 {Turn the start button back on}
51 SetWindowRgn(FindWindowEx(FindWindow('Shell_TrayWnd', nil), 0, 'Button', nil), 0,
52 true);
53 end;
54
55 procedure TForm1.Button3Click(Sender: TObject);
56 begin
57 {Disable the start button}
58 EnableWindow(FindWindowEx(FindWindow('Shell_TrayWnd', nil), 0, 'Button', nil),
59 false);
60 end;
61
62 procedure TForm1.Button4Click(Sender: TObject);
63 begin
64 {Enable the start button}
65 EnableWindow(FindWindowEx(FindWindow('Shell_TrayWnd', nil), 0, 'Button', nil),
66 true);
67 end;
|