Important: The information in this document is obsolete and should not be used for new development.
FindControl
To determine whether a mouse-down event has occurred in a control and, if so, in which part of that control, use theFindControl
function.
FUNCTION FindControl (thePoint: Point; theWindow: WindowPtr; VAR theControl: ControlHandle): Integer;
thePoint
- A point, specified in coordinates local to the window, where the mouse-down event occurred.
theWindow
- A pointer to the window in which the mouse-down event occurred.
theControl
- A handle to the control in which the mouse-down event occurred.
DESCRIPTION
When the user presses the mouse button while the cursor is in a visible, active control,FindControl
returns as its function result a part code identifying the control's part; the function also returns a handle to the control in the parametertheControl
. The part codes thatFindControl
returns, and the constants you can use to represent them, are listed here:
CONST inButton = 10; {button} inCheckBox = 11; {checkbox or radio button} inUpButton = 20; {up arrow for a vertical scroll } { bar, left arrow for a horizontal } { scroll bar} inDownButton = 21; {down arrow for a vertical scroll } { bar, right arrow for a } { horizontal scroll bar} inPageUp = 22; {gray area above scroll box for a } { vertical scroll bar, gray area } { to left of scroll box for a } { horizontal scroll bar} inPageDown = 23; {gray area below scroll box for a } { vertical scroll bar, gray area } { to right of scroll box for a } { horizontal scroll bar} inThumb = 129; {scroll box}The pop-up control definition function does not define part codes for pop-up menus. Instead, your application should store the handles for your pop-up menus when you create them. Your application should then test the handles you store against the handles returned byFindControl
before responding to users' choices in pop-up menus.If the mouse-down event occurs in an invisible or inactive control, or if it occurs outside a control,
FindControl
setstheControl
toNIL
and returns 0 as its function result.When a mouse-down event occurs, your application should call
FindControl
after using the Window Manager functionFindWindow
to ascertain that a mouse-down event has occurred in the content region of a window containing controls.Before calling
FindControl
, use theGlobalToLocal
procedure to convert the point stored in thewhere field (which describes the location of the mouse-down event) of the event record to coordinates local to the window.
Then, when usingFindControl, pass this point in
the parameterthePoint
.In the parameter
theWindow
, pass the window pointer returned by theFindWindow function.
After using
FindControl to determine that
a mouse-down event has occurred in
a control, you generally use theTrackControl function, which automatically
.
follows the movements of the cursor and responds as appropriate until the user releases the mouse buttonSPECIAL CONSIDERATIONS
The Dialog Manager automatically callsFindControl and TrackControl for mouse-down
events inside controls of alert boxes and dialog boxes.The
FindControl
function also returnsNIL
in the parametertheControl
and 0 as
its function result if the window is invisible or if it doesn't contain the given point. (However,FindWindow
won't return a window pointer to an invisible window or to one that doesn't contain the point where the mouse-down event occurred. As long as you callFindWindow
beforeFindControl
, this situation won't arise.)SEE ALSO
Listing 5-10 on page 5-30 illustrates the use ofFindControl
for detecting mouse-down events in a pop-up menu and a button; Listing 5-18 on page 5-48 illustrates its use for detecting mouse-down events in scroll bars.The
FindWindow function is described in the chapter "Window Manager" in this book. The GlobalToLocal procedure
is described in Inside Macintosh: Imaging.The event record is described in the chapter "Event Manager" in this book. See the chapter "Dialog Manager" in this book for more information about including controls in alert boxes and dialog boxes.