// Under program control:
// Minimize, maximize, restore a window
// Arrange the icons, and determine if a window is minimized or maximized
// Bring a child window to the top
// Move and resize a window
//
// Note: to be able to arrange the minimized windows, they must have
//    the child window attribute set

// Windows API function calls
declare pfunc ShowWindow returning integer in dll user.exe
declare pfunc ArrangeIconicWindows returning integer in dll user.exe
declare pfunc IsIconic returning integer in dll user.exe
declare pfunc IsZoomed returning integer in dll user.exe
declare pfunc BringWindowToTop returning integer in dll user.exe
declare pfunc FindWindow returning integer in dll user.exe
declare pfunc SetFocus returning integer in dll user.exe
declare pfunc MoveWindow returning integer in dll user.exe

// actions that can be performed on a window, passed to ShowWindow
#define SW_HIDE					0
#define SW_SHOW					5
#define SW_MAXIMIZE				3
#define SW_MINIMIZE				6	
#define SW_RESTORE				9	

// Get the window handle of the CONSOLE window
hConsoleWin = HWND()

// Get the window handle for CA-dBFast itself.
// 'CA-dBFast' can be replaced by a linked apps window name
// which can then be used to max, min or restore the entire app
// if passed to a ShowWindow().
// The 'tolong(0)' is used to pass a NULL to the function
// so it looks through all classes
hdBFast = FindWindow(tolong(0), 'CA-dBFast')

set window type to 8192+4096+32+1+512+16
create window 'Window 1' from 0,40 to 10,70
hWnd1 =  HWND()
wait 'Click here to minimize...'

ShowWindow(toint(hWnd1), toint(SW_MINIMIZE))

select window 'CONSOLE'
set window type to 8192+4096+32+1+512+16
create window 'Window 2' from 7,45 to 17,75
hWnd2 =  HWND()
wait 'Click here to minimize...'

ShowWindow(toint(hWnd2), toint(SW_MINIMIZE))
select window 'CONSOLE'
wait 'Now move icons around, then click...'

// Arrange the minimized child windows
select window 'CONSOLE'
// The return value is the height of one row of icons if the function is successful, otherwise, it is zero. 
? ArrangeIconicWindows(toint(hConsoleWin))
wait 'Icons arranged.  Click...'

// IsIconic returns non-zero if the window is minimized, otherwise, it is zero
if (IsIconic(toint(hwnd2)))
	? 'Window 2 is minimized'
else
	? 'Window 2 is not minimized'
endif

// IsZoomed returns non-zero if the window is maximized, otherwise, it is zero
if (IsZoomed(toint(hwnd1)))
	? 'Window 1 is maximized'
else
	? 'Window 1 is not maximized'
endif

wait 'State of windows determined.  Click...'

// Restore both windows
ShowWindow(toint(hWnd1), toint(SW_RESTORE))
ShowWindow(toint(hWnd2), toint(SW_RESTORE))

wait 'Both windows restored.  Click...'

// Bring window 1 to the top
BringWindowToTop(toint(hWnd1))
// Make the window the active window
SetFocus(toint(hWnd1))

wait 'Window 1 brought to the top.  Click...'

// Change the position and size of a window
// All coordinates are in pixels
// Parms: window handle, left, top, width, height, repaint
MoveWindow(toint(hWnd1), toint(100), toint(50), toint(300), toint(100), .T.)
SetFocus(toint(hWnd1))

wait 'Window 1 moved and resized.  Done.'