2017-09-15 1 views
0

프로세스가 쳐다 보았을 때 OSK 키보드를 화면 왼쪽 하단에 배치하는 코드를 작성했습니다. 내가 알아 낸 점은 핸들이 활성화 된 시점에 디버거를 배치했을 때 코드가 올바르게 작동한다는 것입니다. 그러나 모든 디버깅 포인트를 제거하고 Windows 폼을 실행하자마자 OSK는 왼쪽 아래로 위치하지 않습니다. 내가 발견 한 것은 모든 디버깅 포인트가 제거 될 때 KeyboardWnd가 값 0을 가지도록 처리 한 것입니다.디버거를 제거 할 때 setwindowpos C# 메서드가 작동하지 않습니다.

그때까지 핸들이로드되는지 확인하기 위해 프로세스를 지연하려고했지만 작동하지 않습니다. 그것의 호출 아래

에 대한 비동기를 필요로하기 때문에 또한 옵션을 선택하지 않습니다 "기다린다는"

string osk = Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Windows), "system32"), "osk.exe"); 

      // start the keyboard process 
      ProcessStartInfo startInfo = new ProcessStartInfo(osk);     
      Process tmp = Process.Start(startInfo); 
      IntPtr KeyboardWnd = GetTabTipWindowHandle(); 

       System.Threading.Thread.Sleep(20); 

      MoveKeyBoard(KeyboardWnd, 0, Screen.PrimaryScreen.Bounds.Height/4*3); 

MoveKeyBoard가 어떤 inturn 내가 가진

public static bool MoveKeyBoard(IntPtr hWnd, int ToX, int ToY) 
    {   
     return SetWindowPos(hWnd, (IntPtr)0, ToX, ToY, Screen.PrimaryScreen.Bounds.Width/2, Screen.PrimaryScreen.Bounds.Height/4, SWP.NOZORDER | SWP.SHOWWINDOW | SWP.NOCOPYBITS); 
    } 

public static IntPtr GetTabTipWindowHandle() 
    { 
     if (TabTip.UseTabTipKeyboard) 
      return FindWindow("IPTip_Main_Window", null); 
     else    
      return FindWindow("OSKMainClass", null); 

    } 
+0

잘 작동? – jdweng

+0

나는 편집을했다. 한번 봐주세요. –

+0

디버거의 장점은 프로그램 속도를 늦추는 것입니다. 따라서 OSK는 윈도우를 생성 할 수있는 충분한 시간을 가지며 FindWindow()는 그것을 찾을 수 있습니다. 초기화 할 기회를주기 위해 기다려야합니다. tmp.WaitForInputIdle().을 추가하는 것이 최소한의 요구 사항입니다. –

답변

0

아래로를 SetWindowPos 방법을 요구 참조 코드입니다 이것에 대한 해결책. 코드 아래 어디 방법 GetTabTipWindowHandle은()이다

RegistryKey myKey = Registry.CurrentUser.OpenSubKey(@"SOFTWARE\Microsoft\Osk", true); 

       myKey.SetValue("WindowLeft", 0, RegistryValueKind.DWord); 
       myKey.SetValue("WindowTop", Screen.PrimaryScreen.Bounds.Height/4 * 3, RegistryValueKind.DWord); 
       myKey.SetValue("WindowWidth", Screen.PrimaryScreen.Bounds.Width/2, RegistryValueKind.DWord); 
       myKey.SetValue("WindowHeight", Screen.PrimaryScreen.Bounds.Height/4, RegistryValueKind.DWord); 
       IntPtr KeyboardWnd = GetTabTipWindowHandle(); 


        MoveKeyBoard(KeyboardWnd, 0, Screen.PrimaryScreen.Bounds.Height/4 * 3); 
관련 문제