[comp.sys.mac.programmer] AddResMenu screwing up the WindowMgr?

ollef@sics.se (Olle Furberg) (01/21/91)

 I'm a beginner in MacProgramming and I'm trying to build an application
with a modeless DLOG and the standard menus: Apple, File and Edit.

  Everything worked fine until I added the menus. I use the same procedure 
as the program sample in IM I, i.e. GetMenu() and AddResMenu(). 
  When I run the program, it runs with no problem; All menus and DA are
there, I could move my DLOG-window, select things in the menu etc.   BUT:
When I click on a window in the background (belonging to another application)
nothing happens!, my DLOG-window is still sitting on the top.

  If I remove the call of AddResMenu(), and leave the Apple-menu without any
DAs,it works fine: whenever I click in a Finder-window, my program is being
put away and the Finder comes in front.


  So my question to you, wise people, is there any natural connection between
these two things (WindowMgr misbehaving and the call of AddResMenu). Does
anybody of you know where I should look for (my) bug?

   /Olle



*******  Some C-code follows *************

My eventloop looks like this:

void EventLoop() {
	extern EventRecord	theEvent;
	extern int itemHit;
	extern DialogPtr theDialog;
	while (itemHit != 22) {
	SystemTask();
	GetNextEvent(everyEvent,& theEvent);
     if (IsDialogEvent(&theEvent)) {
		if (DialogSelect(&theEvent, &theDialog, &itemHit)) {
			HandleConjDialog();	}
      		}
     else {
      	if (theEvent.what==mouseDown)
      	HandleMouseDown(&theEvent);
			/* Handle non-dialog events */
 		}
 	}
}



void HandleMouseDown(EventRecord *theEvent) {
	
	extern int itemHit;
	WindowPtr	theWindow;
	extern	WindowPtr	theDialog;
	Rect	dragRect = {0,0,1024,1024};
	
	
	int windowCode = FindWindow (theEvent->where, &theWindow);
 
    switch (windowCode)
      {
	  case inSysWindow:
	    SystemClick (theEvent, theWindow);
	    break;
	    
	    
	  case inDrag:
	  	if (theWindow == theDialog){
	  	  DragWindow(theDialog, theEvent->where, &dragRect);
	  	  DialogSelect(&theEvent, &theDialog, &itemHit);
	  	  /*for a fast update*/
	  	  }
	  	  break;
	  
	  case inContent:
	  	if (theWindow != FrontWindow())
	  		SysBeep(0);
	  		SelectWindow(theWindow);
	  	break;   
	  	
	  case inMenuBar:
	  	MenuSelect(theEvent->where);
	  	HiliteMenu(0);
	  	/*Do something*/
	  	break;
	  	
	  case inGoAway:
	  	if (theWindow == theDialog && TrackGoAway(theDialog, theEvent->where)){
		  	itemHit = 22; /*get out of the loop */
		  	}
	  	  break;
      }
}

ollef@sics.se (Olle Furberg) (01/21/91)

In <1991Jan20.161803.14751@sics.se> I wrote:


>When I click on a window in the background (belonging to another application)
>nothing happens!, my DLOG-window is still sitting on the top.

>  If I remove the call of AddResMenu(), and leave the Apple-menu without any
>DAs,it works fine: whenever I click in a Finder-window, my program is being
>put away and the Finder comes in front.


 After reading TN 180 about the MultiFinder I've found that this switching
works through a mouseDown-event in the menubar. When I encountered the
problem I hadn't implemented any OpenDeskAcc()-stuff. But I still can't 
understand why it *did* work, when I didn't call AddResMenu() with 'DRVR' 
(There were no problems when I called it with other rsrc-types (e.g. 'FONT').)


Moral: Read the TechNotes, esp. #180.


     /Olle