2014-01-27 1 views
0

내 응용 프로그램에 자동 로그 오프 기능이 있습니다. 설정에 따라 활성화됩니다. 사용자가 다른 사용자 이름으로 다시 로그인하면 기존 양식을 폐기해야합니다.Windows Mobile 6.5에서 SetForegroundWindow가 작동하지 않습니다.

여기에 주요 문제가 있습니다. 사용자가 모바일의 파일 브라우저에서 응용 프로그램을 열고 다른 사용자 이름으로 다시 로그인하면 응용 프로그램이 백그라운드로 이동합니다. 파일 탐색기가 앞에옵니다.

이 문제를 극복하기 위해 coredll.dll의 SetForegroundWindow를 사용했습니다. 하지만 작동하지 않습니다.

나는 현재의 과정을 추적했다. 그리고 그것을 세계 곳곳에 두었다.

[DllImport("coredll.dll")] 
static extern bool SetForegroundWindow(IntPtr hWnd); 

if (_autoLogOff) 
{ 
    if (cboUsers.Text != Globals.UserName) 
    { 
     List<frmAutoLogOff> openedForms = Globals.OpenedForms; 
     for (int i = openedForms.Count - 1; i >= 0; i--) 
     { 
      if (openedForms[i] != null && openedForms[i].Name != "frmMenu1") 
      { 
       //openedForms[i].SuspendLayout(); 
       openedForms[i].Dispose(); 
      } 
     } 
    } 

    SetForegroundWindow(currentProcess); 
    Globals.UserName = cboUsers.Text; 
    CDataAccess.ShowMessageForUser();  
} 

어떤 제안이나 해결책이든 받아 들여질 것입니다.

답변

1

사용를 FindWindow는 "MAINMENU을"가정 UR frmMainMenu1.cs의

// For Windows Mobile, replace user32.dll with coredll.dll 
     [DllImport("coredll.dll", SetLastError = true)] 
     static extern IntPtr FindWindow(string lpClassName, string lpWindowName); 

설정 텍스트를 SetForgroundWindow 적절한 장소

public int FindWindow(string windowName, bool wait) 
     { 
      int hWnd = FindWindow(null, windowName).ToInt32(); 
      while (wait && hWnd == 0) 
      { 
       System.Threading.Thread.Sleep(500); 
       hWnd = FindWindow(null, windowName).ToInt32(); 
      } 

      return hWnd; 
     } 

에서 그들에게 전화 그리고이

int hWnd = FindWindow("MainMenu", wait); 
      if (hWnd != 0) 
      { 
       return SetForegroundWindow((IntPtr)hWnd); 
      } 
+0

감사를 호출합니다. 그것의 완벽하게 작동합니다. – SKD

관련 문제