preload

Desktop Window operations (WinRunner, TSL)

Posted by Albert Gareev on Oct 15, 2007 | Categories: DesktopSource code

Declarations

#
extern int IsIconic(in int);
#
extern int IsZoomed(in int);
#

Restore window

public function wg_win_restore(in wname) {
 auto hwnd;
 
 win_get_info(wname, "handle", hwnd);   

 if (IsIconic(hwnd) == 1)
  win_restore(wname);

 if (IsZoomed(hwnd) == 1)
  win_restore(wname);
}

Minimize window

public function wg_win_min(in wname) {
 auto hwnd;
 
 win_get_info(wname, "handle", hwnd);   

 if (IsIconic(hwnd) != 1)
  win_min(wname);

}

Maximize window

public function wg_win_max(in wname) {
 auto hwnd;
 
 win_get_info(wname, "handle", hwnd);   
 if (IsZoomed(hwnd) != 1) win_max(wname);
}

Window synchronization

public function wg_win_sync(in wname, in state, in timeout) {
 auto rc, t;
 if (timeout == "") timeout = _WG_timeout;
 state = toupper(state);
 t = get_time();

 while(1) {
  rc = wg_win_ready(wname);
  if (state == "APPEAR")
   if (rc == E_OK)
    return(E_OK);

  rc = win_exists(wname);
  if (state == "DISAPPEAR") {  
   if (rc == E_NOT_FOUND)
    return(E_OK);
   if (rc == E_NOT_DISPLAYED)
    return(E_OK);
   }

  if ((get_time()-t) > timeout)
   return(E_GENERAL_ERROR);
   
  wait(1);
  }
}

Close window

public function wg_win_close(in wname) {
 auto rc, hwnd;
 
# see no window
 rc = win_exists(wname);
 if (rc != E_OK) return(rc);

 win_close(wname);
 wg_win_sync(wname, "DISAPPEAR");
 
# check if closed now
 rc = win_exists(wname);
 if (rc != E_OK) return(E_OK);
 
# still open? Force close
 win_get_info(wname, "handle", hwnd);   
 shut_down(hwnd);
 wg_win_sync(wname, "DISAPPEAR");
 
# check if closed now
 rc = win_exists(wname);
 return(rc);
}


Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported
This work by Albert Gareev is licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported.