[comp.sys.mac.programmer] modeless dialog box cannot move, help

vanderpool@cals.enet.dec.com (Russ Vanderpool) (03/21/91)

    I've just started digging my hands into modeless dialog boxes, and 
    am having a problem being able to move the dialog box around, and 
    also closing it. I can't.

    Is there anything obvious missing(I think there is). I've read
    everything in IM-I on IsDialogEvent() & DialogSelect().

    In the program below, these routines seem to work. When I click
    on a user item, the Boolean flags correctly get set. I just can't
    move the thing around. Under Multifinder, I can switch back to the
    desktop, so that part is working. 

    In RESEdit, I've tried various combinations with setting
    the check boxes:  "Initially visible" and "Close box", without
    any success.

What's missing?
+Russ

===========================================================================
/*
 *   Using THINK C
 *   DLOG ID: 2777 (just contains a couple of radio buttons and a static text)
*/

#include <stdio.h>

#define 	ALERT_DLG_ID	3017
#define		MODELESS	2777
#define		NIL_POINTER 	0L
#define		MOVE_TO_FRONT	-1L

/*
 *  For debugging purposes
 */
#define		HALT		asm{_Debugger}

void 						ShowSelection(char *s);
void 						Init(void);
void 						EventLoop(void);
void 						GoModeless(void);

/*
 *   Globals variables for event loop
 */
 Boolean		gDone;
 unsigned short gmask;   /* using everyEvent */
 EventRecord 	gevent;
 unsigned long  gsleep;
 DialogPtr		myDialog;


main()
{     
    Init();
    GoModeless();
}


void Init()
{
   InitGraf( &thePort );
   InitFonts();
   FlushEvents( everyEvent, 0 );
   InitWindows();
   InitMenus();
   TEInit();
   InitDialogs( 0L );
   InitCursor();
 }


/*
 *    Handle events for the modeless dialog box
 */
void EventLoop()
{
    Boolean   	isDLGevent, isITEMhit;
    int 		i;
    int 		itemHit;

   WaitNextEvent( everyEvent, &gevent, gsleep, NIL_POINTER);
   isDLGevent = IsDialogEvent( &gevent );
   if(isDLGevent)
     {
        isITEMhit = DialogSelect( &gevent, &myDialog, &itemHit);
        if(isITEMhit)
           {
           /*   HALT;*/
           }
     }


   switch( gevent.what )
   {
   		case keyDown:
   		  /*   HALT;*/
   		     gDone = TRUE;
       default:
            break;
                /* do nothing, all other events will hit here */
    }
}

void GoModeless()
{
    /*
     * Set up modeless dialog box
     */
    myDialog = GetNewDialog( MODELESS, NIL_POINTER, MOVE_TO_FRONT );
    ShowWindow( myDialog );

    gDone = FALSE;
    while( gDone == FALSE )
      {           
         EventLoop();
       }

     DisposDialog(myDialog);
}

/*
 *  Shows alert dialog box
 */     
void ShowSelection(s)
	char *s;
{
	Str255 tStr;

	GetIndString(&tStr,256,4);
	ParamText(s,0,0,0);
	NoteAlert(ALERT_DLG_ID, 0);
};