2010-05-21 5 views
1

Je dois désactiver les clics de la souris, le mouvement de la souris et les entrées clavier pour une fenêtre spécifique pour une application Kiosque. Est-ce faisable en utilisant .NET?Utilisation de la poignée de fenêtre pour désactiver les clics souris et les entrées clavier à l'aide de P/Invoke

J'ai enlevé la barre de menu et la barre de titre d'une fenêtre spécifique, ce sera un point de départ pour atteindre l'exigence ci-dessus?

Le code pour supprimer la barre de menu et la barre de titre à l'aide poignée de fenêtre:

#region Constants 
//Finds a window by class name 
[DllImport("USER32.DLL")] 
public static extern IntPtr FindWindow(string lpClassName, string lpWindowName); 

//Sets a window to be a child window of another window 
[DllImport("USER32.DLL")] 
public static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent); 

//Sets window attributes 
[DllImport("USER32.DLL")] 
public static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong); 

//Gets window attributes 
[DllImport("USER32.DLL")] 
public static extern int GetWindowLong(IntPtr hWnd, int nIndex); 

[DllImport("user32.dll", EntryPoint = "FindWindow", SetLastError = true)] 
static extern IntPtr FindWindowByCaption(IntPtr ZeroOnly, string lpWindowName); 

[DllImport("user32.dll")] 
static extern IntPtr GetMenu(IntPtr hWnd); 

[DllImport("user32.dll")] 
static extern int GetMenuItemCount(IntPtr hMenu); 

[DllImport("user32.dll")] 
static extern bool DrawMenuBar(IntPtr hWnd); 

[DllImport("user32.dll")] 
static extern bool RemoveMenu(IntPtr hMenu, uint uPosition, uint uFlags); 

//assorted constants needed 
public static uint MF_BYPOSITION = 0x400; 
public static uint MF_REMOVE = 0x1000; 
public static int GWL_STYLE = -16; 
public static int WS_CHILD = 0x40000000; //child window 
public static int WS_BORDER = 0x00800000; //window with border 
public static int WS_DLGFRAME = 0x00400000; //window with double border but no title 
public static int WS_CAPTION = WS_BORDER | WS_DLGFRAME; //window with a title bar 
public static int WS_SYSMENU = 0x00080000; //window menu 
#endregion 

public static void WindowsReStyle() 
{ 
    Process[] Procs = Process.GetProcesses(); 
    foreach (Process proc in Procs) 
    { 
     if (proc.ProcessName.StartsWith("notepad")) 
     { 
      IntPtr pFoundWindow = proc.MainWindowHandle; 
      int style = GetWindowLong(pFoundWindow, GWL_STYLE); 

      //get menu 
      IntPtr HMENU = GetMenu(proc.MainWindowHandle); 
      //get item count 
      int count = GetMenuItemCount(HMENU); 
      //loop & remove 
      for (int i = 0; i < count; i++) 
       RemoveMenu(HMENU, 0, (MF_BYPOSITION | MF_REMOVE)); 

      //force a redraw 
      DrawMenuBar(proc.MainWindowHandle); 
      SetWindowLong(pFoundWindow, GWL_STYLE, (style & ~WS_SYSMENU)); 
      SetWindowLong(pFoundWindow, GWL_STYLE, (style & ~WS_CAPTION)); 
     } 
    } 
} 
+0

Comment l'utilisateur va-t-il interagir avec l'application sans clavier ni souris? –

+0

@ Carlos Loth, L'utilisateur n'a pas besoin d'interagir. Cette application est destinée à View uniquement. Bien qu'il ait des choses à faire avec la souris et la frappe, j'ai besoin de désactiver la souris et le clavier de cette fenêtre. – Anuya

+0

S'il est possible de supprimer la barre de titre et la barre de menu d'une application externe, je pense même que la souris de désactivation est possible .. Ouais? – Anuya

Répondre

1

Utilisez le EnableWindow API appel pour ce faire. Je n'ai pas utilisé cela depuis de nombreuses années, mais je ne crois pas qu'il y ait des problèmes de processus croisés avec cela.