SendBehind moves one window behind another. This function is useful when you want to exercise precise control over window ordering.
void SendBehind ( WindowRef window, WindowRef behindWindow );
SendBehind moves window behind behindWindow.
A quick check of MacWindows.h shows that this function is in InterfaceLib for Mac Classic builds. Since the return type is void, we declare it as a subroutine. In keeping with the rest of the chapter, let's wrap it into a WindowManager method.
Sub SendBehind(Extends w as Window, behind as Window) #if targetMacOS Declare Sub SendBehind Lib InterfaceLib (window as WindowPtr, behindWindow as WindowPtr) If behind Is Nil then Return End if SendBehind(w, behind) #endif End Sub
Suppose you are writing a custom control as a Canvas subclass. You may need to change the control appearance when the control's activation state changes. Unfortunately, RectControl does not offer a way to detect when this state change occurs. The best you can do is to call a custom control's Refresh method in its containing window's Activate and Deactivate events. But these events are called before the control's Active property is updated. Thus if you have code in the control's Paint event handler that checks its Active property, it will not draw the control as you like.
For Carbon builds, a workaround is to use the Window Manager function IsWindowActive.
Boolean IsWindowActive ( WindowRef inWindow );
This function does return the correct active state of the window. Here is a bit of sample code that illustrates how to use it.
Sub Paint(g as Graphics) #if targetCarbon Declare Function IsWindowActive Lib CarbonLib (inWindow as WindowPtr) as Boolean If IsWindowActive(me.Window) then //draw enabled control Else //draw disabled control End if #endif End Sub