Lumen писал(а):Другими словами. ты будешь знать, когда будет появляться это меню, но предотвратить его появление путем "обмана" винды, типа "неправда ваша, там другая клавища была нажата" не получится.
Можно выгнать ее за пределы экрана, вероятно меню не будет доступно. Я ее однажды загнал в левый верхний угол, нажимаю, а меню не видно. Нажимаю с клавиатуры, потом вверх, энтер, и ничего не происходит. А первый снизу пункт - выключение компьютера.iGrok писал(а):Antoniary.. Но она все раво будет работать при вызове с клавиатуры.
using System;
using System.Diagnostics;
using System.Windows.Forms;
using System.Runtime.InteropServices;
class TEST
{
private const int WH_KEYBOARD_LL = 13;
private const int WM_KEYDOWN = 0x0100;
private static LowLevelKeyboardProc _proc = HookCallback;
private static IntPtr _hookID = IntPtr.Zero;
public static void Main()
{
_hookID = SetHook(_proc);
Application.Run();
UnhookWindowsHookEx(_hookID);
}
private static IntPtr SetHook(LowLevelKeyboardProc proc)
{
using (Process curProcess = Process.GetCurrentProcess())
using (ProcessModule curModule = curProcess.MainModule)
{
return SetWindowsHookEx(WH_KEYBOARD_LL, proc, GetModuleHandle(curModule.ModuleName), 0);
}
}
private delegate IntPtr LowLevelKeyboardProc(int nCode, IntPtr wParam, IntPtr lParam);
private static IntPtr HookCallback(int nCode, IntPtr wParam, IntPtr lParam)
{
if ( (nCode >= 0) && (wParam == (IntPtr)WM_KEYDOWN) )
{
int vkCode = Marshal.ReadInt32(lParam);
if( ((Keys)vkCode == Keys.LWin)||((Keys)vkCode == Keys.RWin) )
{
Console.WriteLine("{0} blocked!", (Keys)vkCode);
return (IntPtr)1;
}
}
return CallNextHookEx(_hookID, nCode, wParam, lParam);
}
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
private static extern IntPtr SetWindowsHookEx(int idHook, LowLevelKeyboardProc lpfn, IntPtr hMod, uint dwThreadId);
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
Option Explicit
Private Declare Function FindWnd Lib "User32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWiName As String) As Long
Private Declare Function FindWndEx Lib "User32" Alias "FindWindowExA" (ByVal HWnd1 As Long, ByVal HWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
Private Declare Function GetDesktopWindow Lib "User32" () As Long
Private Declare Function SetParent Lib "User32" (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As Long
'Private Declare Function SetWindowPos Lib "User32" (ByVal HWnd As Long, ByVal HWndInsertAfter As Long, ByVal X As Long, ByVal Y As Long, ByVal CX As Long, ByVal CX As Long, ByVal WFlags As Long) As Long
Private Declare Function ShowWindow Lib "User32" (ByVal HWnd As Long, ByVal nCmdShow As Long) As Long
Private Const SW_SHOWNORMAL = 1
Private Const SW_HIDE = 0
Private hTrayWnd, hButton As Long
Private Sub Block_Start_Click()
'Блокируем кнопку "Пуск"
SetParent hButton, GetDesktopWindow
ShowWindow hButton, SW_HIDE
End Sub
Private Sub UnBlock_Start_Click()
'Возвращаем кнопку на законное место...
SetParent hButton, hTrayWnd
'SetWindowPos hButton, 0, 0, 0, 54, 24, 0
ShowWindow hButton, SW_SHOWNORMAL
End Sub
Private Sub Form_Load()
'Определяем хэндл кнопки "Пуск"
hTrayWnd = FindWnd("Shell_TrayWnd", vbNullString)
hButton = FindWndEx(hTrayWnd, 0, "Button", vbNullString)
End Sub
Private Sub End_Command_Click()
End
End Sub
Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWndParent As Long, ByVal hWndChildAfter As Long, ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal _
lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function SendNotifyMessage Lib "user32" Alias "SendNotifyMessageA" (ByVal _
hwnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Const WM_CLOSE = &H10
Private Sub Command1_Click()
'Находим хэндл кнопки "Пуск"...
hTrayWnd = FindWindow("Shell_TrayWnd", vbNullString)
hButton = FindWindowEx(hTrayWnd, ByVal 0&, "BUTTON", vbNullString)
SendNotifyMessage hButton, WM_CLOSE, ByVal 0&, ByVal 0&
End Sub
Сейчас этот форум просматривают: Yandex-бот и гости: 97