2014-01-09 104 views
2

我有一個應用程序要在Windows 7平板電腦上運行,並且需要將屏幕鍵盤停靠在屏幕底部。理想情況下,我想阻止某人能夠移動或更改這些設置。在屏幕鍵盤上以編程方式控制Windows 7

使用評論張貼到堆棧溢出答案在這裏How do I control the text input panel programmatically (TabTip.exe) in Windows Vista/7我能夠編程停靠在屏幕底部的鍵盤,所以這是一個開始。我不得不使用提升的權限運行,以得到它的工作

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

[return: MarshalAs(UnmanagedType.Bool)] 
[DllImport("user32.dll", SetLastError = true)] 
public static extern bool PostMessage(IntPtr hWnd, uint msg, IntPtr wParam, IntPtr lParam); 

string onScreenKeyboardPath = @"C:\Program Files\Common Files\Microsoft Shared\ink\TabTip.exe"; 
var onScreenKeyboardProc = Process.Start(onScreenKeyboardPath); 

IntPtr wKB = FindWindow("IPTip_Main_Window", null); 

const uint WM_COMMAND = 0x111; 
// Where message is 10021 for dock bottom, 10023 for dock top and 10020 for floating 
bool x = PostMessage(wKB, WM_COMMAND, new IntPtr(10021), IntPtr.Zero); 

我寧願能控制大小有點比這更好的,所以我想移動窗口,像這樣:

[DllImport("user32.dll")] 
static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int X, int Y, int cx, int cy, uint uFlags); 

private const uint SWP_SHOWWINDOW = 0x0040; 
bool ok = SetWindowPos(wKB, this.Handle, 0, 500, 750, 500, SWP_SHOWWINDOW); 

確定返回true,但窗口不會改變。如果我試着用記事本來做這件事,那就完美了。那麼這是否是這個特定程序的問題?

+0

相關:http://stackoverflow.com/questions/1770670/how-do-i-control-the-text-input-panel -programmatically-tabtip-exe-in-windows-v – sshow

+0

可以肯定的是:你是在談論無法調整大小的黑色「新風格」鍵盤,或者是具有「正常」窗口邊界的屏幕鍵盤上的舊鍵盤嗎?調整大小? – Traubenfuchs

+0

@Traubenfuchs我正在談論新式鍵盤。但是我也看過了較老的osk.exe,我無法說服那個人移動。想知道是否要在Windows 7 x64上嘗試這樣做。但也許這需要更多的調查。 – Firedragon

回答

2

您的問題可以通過以下部分

1)防止窗口被移動
2)防止窗口被調整大小
3)防止窗口被最小化

1被分割)似乎是容易:How do you prevent a windows from being moved?

2)& 3)可以在同一步驟中解決。

我有一個解決方案不同的想法:
一)創建,如果鍵盤窗口進行調整定期檢查線程/最小/感動,重置它與位置(例如)SetWindowPos
How to get and set the window position of another application in C#
B)「聽「用於調整大小/最小化/移動事件(WH_CBT =在發生任何這些事件之前發生)並結束它。可悲的是,我不知道是否以及如何強制禁用通過WH_CBT宣佈的事件。
似乎有另一種解決方案:
http://msdn.microsoft.com/en-us/library/windows/desktop/ms644990%28v=vs.85%29.aspx
向下滾動到評論部分,以什麼用戶帕維爾Shkleinik寫道。
EVENT_SYSTEM_MOVESIZ *和EVENT_SYSTEM_MINIMIZE *對您的情況似乎很有趣。
您可以檢測到之前的事件並阻止它們(如果我只知道如何)或檢測這些事件的結束並強制重置窗口位置(SetWindowPos)。
的PInvoke的維基和谷歌將幫助您設置掛鉤:
http://www.pinvoke.net/default.aspx/user32.setwineventhook

相關問題