TITLE
    Using the Windows NT Wait Cursor With OPENSTEP
Article ID:
Created:
Modified:
72616
2/1/99
2/1/99

TOPIC

    Applications built with OpenStep 4.2 Enterprise will not automatically call the Windows NT wait cursor during long operations such as launching applications and loading frameworks. If you know your application is about to begin a long operation, however, you can bring up the NT wait cursor manually. This document contains sample code for calling the NT wait cursor.


DISCUSSION

    The following sample code demonstrates how to call the Windows NT wait cursor on OPENSTEP 4.2 Enterprise.

    #ifdef WIN32

    #import <Windows.h>
    // Apple OpenStep Enterprise NSCursor private initializer method
    @interface NSCursor (Secret)
    - (id) initWithCursorHandle: (HCURSOR) handle;
    @end

    #endif


    @implementation NSCursor (waitCursor)

    + (NSCursor *) waitCursor

    {
    static NSCursor *waitCursor = nil;

    #ifdef WIN32
    if (!waitCursor) {
    HCURSOR cursor = LoadCursor(NULL, IDC_WAIT);

    if (cursor && [NSCursor instancesRespondToSelector: @selector(initWithCursorHandle:)])
    waitCursor = [[NSCursor alloc] initWithCursorHandle: cursor];
    }
    #endif
    return waitCursor;
    }

    @end

    // some class implementation wanting to use a wait cursor

    - (void) deactivateWaitCursor

    {
    #ifdef WIN32
    NSCursor * const waitCursor = [NSCursor waitCursor];
    NSArray * const windows = [NSApp windows];
    const int count = [windows count];
    int i;

    [waitCursor setOnMouseEntered: NO];
    for (i = 0; i < count; i++)
    [[windows objectAtIndex: i] resetCursorRects];
    #endif
    return;
    }

    - (void) activateWaitCursor

    {
    #ifdef WIN32
    NSCursor * const waitCursor = [NSCursor waitCursor];
    NSArray * const windows = [NSApp windows];
    const int count = [windows count];
    int i;

    [waitCursor setOnMouseEntered: YES];
    for (i = 0; i < count; i++) {
    NSWindow * const window = [windows objectAtIndex: i];
    NSView * const contentView = [window contentView];

    [window enableCursorRects];
    [contentView addCursorRect: [contentView frame] cursor: waitCursor];
    }
    #endif
    return;
    }

Document Information
Product Area: Apple Software
Category: OPENSTEP
Sub Category: Development

Copyright © 2000 Apple Computer, Inc. All rights reserved.