2014-06-05 2 views
0

기업의 기존 응용 프로그램의 요구 사항을 해결하기 위해 C#에서 응용 프로그램을 만들었습니다. 최근 청구를 지원하기 위해 다른 애플리케이션을 구매해야했습니다. 이러한 응용 프로그램의 실행은 다음과 같다 :Lost Focus Windows Mobile

1 응용 프로그램 -> 2 응용 프로그램 -> 3 응용 프로그램

나는 세 번째 응용 프로그램에 대해 "Process.Start를"을 수행 할 때 "가 열리지 만 몇 초 후에는 대한 포커스를 잃었을 .

[DllImport("coredll.dll", EntryPoint="FindWindowW", SetLastError=true)] 
private static extern IntPtr FindWindowCE(string lpClassName, string lpWindowName); 

창을 사용하여 : 1 응용 프로그램 누구나 창에 대한 창 핸들을 얻을 수를 FindWindow를 사용하여 다음 창 클래스 및/또는 제목을 알 필요가 나는이 문제를 방지 할 수있는 방법

+0

질문이 자세하지 않습니다. 세 번째 응용 프로그램 창은 어떻게됩니까? 최소화되었거나 숨겨져 있습니까? 그렇다면 FindWindow() 및 SetWindowPos (둘 다 pinvoke를 통해 사용할 수 있음)를 사용하여 세 번째 응용 프로그램의 창 (있는 경우)을 앞에 놓아야합니다. – josef

+0

우리는 1 차 적용을 최소화하고 나타납니다. Windows Mobile에서는 FindWindow() 및 SetWindowPos가 어떻게됩니까? – user6018

답변

0

을 알고 창을 다시 nor로 변경할 수 있습니다. 말 디스플레이 사용을 SetWindowPos : 예에서

[DllImport("user32.dll", SetLastError=true)] 
[return: MarshalAs(UnmanagedType.Bool)] 
private static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int x, int y, int cx, int cy, uint uFlags); 

, 윈도우가 "앱 3"의 클래스 이름이있는 경우

... 
    IntPtr handle; 

    try 
    { 
    // Find the handle to the window with class name x 
    handle = FindWindowCE("App 3", null); 
    // If the handle is found then show the window 
    if (handle != IntPtr.Zero) 
    { 
     // show the window 
     SetWindowPos(handle, 0, 0, 0, 0, 0, SWP_SHOWWINDOW | SWP_NOSIZE); 
    } 
    } 
    catch 
    { 
     MessageBox.Show("Could not find window."); 
    } 

윈도우의 클래스와 제목을 찾으려면 CE 원격 도구를 시작 "CE 스파이 "(VS 설치의 일부) app 3이 시작될 때. 그런 다음 창 목록을 탐색하고 app 3 창을 봅니다. 두 목록의 항목을 클릭하면 클래스 이름과 3

대신 당신은 또한 간단한 ShowWindow API 사용할 수있는 여분을 SetWindowPos의 응용 프로그램의 제목을 얻을 것이다 :의 PInvoke를 대한 자세한 내용은

[DllImport("coredll.dll")] 
[return: MarshalAs(UnmanagedType.Bool)] 
static extern bool ShowWindow(IntPtr hWnd, ShowWindowCommands nCmdShow); 

enum ShowWindowCommands 
{ 
    Hide = 0, 
    Normal = 1, 
    ShowMinimized = 2, 
    Maximize = 3, // is this the right value? 
    ShowMaximized = 3, 
    ShowNoActivate = 4, 
    Show = 5, 
    Minimize = 6, 
    ShowMinNoActive = 7, 
    ShowNA = 8, 
    Restore = 9, 
    ShowDefault = 10, 
    ForceMinimize = 11 
} 
... 
    IntPtr handle; 

    try 
    { 
    // Find the handle to the window with class name x 
    handle = FindWindowCE("App 3", null); 
    // If the handle is found then show the window 
    if (handle != IntPtr.Zero) 
    { 
     // show the window 
     ShowWindow(handle, ShowWindowCommands.Normal); 
    } 
    } 
    catch 
    { 
     MessageBox.Show("Could not find window."); 
    } 

을 FindWindow 및 SetWindowPos는 pinvoke.net 및 MSDN을 참조하십시오. Win32 프로그래밍에 관한 가장 좋은 책은 Charles Petzold의 Programming Windows입니다.

프로세스를 시작할 때 창을 변경하기 전에 OS에서 응용 프로그램을 정리할 시간이 필요합니다 (1-3 초).