title: Finding a window and setting focus on it
body: <p>1.I want to find a window and set focus on it , but window is not taking the focus.</p>
  
  <p>2.If i use HWND_TOP then it does not make the window active and if i use HWND_TOPMOST then  it make window always on top.</p>
  
  <p>Can anyone help me ??</p>
  
  <pre><code>HWND hwndAppDlg = ::FindWindowEx(hwndDesktop,NULL,lpszClass,lpszWindow);
  
      if(hwndAppDlg &amp;&amp; IsWindow(hwndAppDlg))
      {
          CRect rcAppDlg;
          if( 0 == ::GetWindowRect(hwndAppDlg,rcAppDlg))
          {
              OutputDebugString(L"\n GetWindowRect failed...");           
              return FALSE;
          }
          if(0 == ::SetWindowPos(hwndAppDlg,HWND_TOPMOST,rcAppDlg.left,rcAppDlg.top,rcAppDlg.Width(),rcAppDlg.Height(),SWP_SHOWWINDOW))
          {
              OutputDebugString(L"\n SetWindowPos failed...");            
              return FALSE;
          }
          if(0 == ::PostMessage(hwndAppDlg,WM_SETFOCUS,0,0))
          {
              OutputDebugString(L"\n WM_SETFOCUS failed");        
              return FALSE;
          }
  
          return TRUE;
      }
  </code></pre>