HelloWorld
2005.07.27, 07:14 PM
I have a problem with my the mouse down events in my program. It does not quit the program when the close box in the window is clicked.It also does not work if you click in the drag region. Please Help me:
int main(int argc, char* argv[])
{
WindowRef window;
WindowRef window1;
EventRecord Event;
OSStatus err;
IBNibRef nibRef;
EventRef EvntRef;
EventHandlerUPP handlerUPP;
Boolean gotEvent;
err= CreateNibReference(CFSTR("main"), &nibRef);
err = SetMenuBarFromNib(nibRef,CFSTR("MenuBar"));
err = CreateWindowFromNib(nibRef, CFSTR("Window2"), &window1);
err= CreateWindowFromNib(nibRef,CFSTR("MainWindow"),&window);
ShowWindow(window);
ShowWindow(window1);
SetPortWindowPort(window1);
gQuit=false;
Item item(10,"Hello","Jan 30 2005",1);
SetUpFile("Stock.txt");
WriteItem(item);
while(!gQuit)
{
gotEvent = WaitNextEvent(everyEvent,&Event,MAX_UNIT32,NULL);
if(gotEvent)
{
doEvents(&Event);
}
}
return 0;
}
void doEvents(EventRecord * Event)
{
SInt32 menuChoice;
MenuID menuID;
MenuItemIndex MenuItem;
switch(Event->what)
{
case mouseDown:
doMouseDown(Event);
std::cout << "Mouse Down Event"<<std::endl;
break;
case keyDown:
if ((Event->modifiers & cmdKey) !=0)
{
menuChoice=MenuEvent(Event);
menuID =HiWord(menuChoice);
MenuItem = LoWord(menuChoice);
if (menuID==mFile && MenuItem== iQuit)
gQuit=true;
}
break;
case updateEvt:
break;
case autoKey:
break;
case activateEvt:
break;
case osEvt:
break;
case mouseUp:
break;
}
}
void doMouseDown(EventRecord *EvtRec)
{
WindowPartCode partCode;
WindowRef windowRef;
SInt32 menuChoice;
Rect constraintRect, mainScreenRect;
Point standardStateHeightAndWidth;
partCode= FindWindow(EvtRec->where,&windowRef);
switch (partCode)
{
case inMenuBar:
menuChoice=MenuSelect(EvtRec->where);
doMenuChoice(menuChoice);
break;
case inContent:
if (windowRef!=FrontWindow())
SelectWindow(windowRef);
break;
case inDrag:
DragWindow(windowRef,EvtRec->where,NULL);
gQuit=true;
break;
case inGoAway:
if (TrackGoAway(windowRef,EvtRec->where))
gQuit=true;
break;
case inGrow:
constraintRect.top =75;
constraintRect.left =205;
constraintRect.bottom = constraintRect.right = 32767;
ResizeWindow(windowRef,EvtRec->where,&constraintRect,NULL);
gQuit=true;
break;
}
}
int main(int argc, char* argv[])
{
WindowRef window;
WindowRef window1;
EventRecord Event;
OSStatus err;
IBNibRef nibRef;
EventRef EvntRef;
EventHandlerUPP handlerUPP;
Boolean gotEvent;
err= CreateNibReference(CFSTR("main"), &nibRef);
err = SetMenuBarFromNib(nibRef,CFSTR("MenuBar"));
err = CreateWindowFromNib(nibRef, CFSTR("Window2"), &window1);
err= CreateWindowFromNib(nibRef,CFSTR("MainWindow"),&window);
ShowWindow(window);
ShowWindow(window1);
SetPortWindowPort(window1);
gQuit=false;
Item item(10,"Hello","Jan 30 2005",1);
SetUpFile("Stock.txt");
WriteItem(item);
while(!gQuit)
{
gotEvent = WaitNextEvent(everyEvent,&Event,MAX_UNIT32,NULL);
if(gotEvent)
{
doEvents(&Event);
}
}
return 0;
}
void doEvents(EventRecord * Event)
{
SInt32 menuChoice;
MenuID menuID;
MenuItemIndex MenuItem;
switch(Event->what)
{
case mouseDown:
doMouseDown(Event);
std::cout << "Mouse Down Event"<<std::endl;
break;
case keyDown:
if ((Event->modifiers & cmdKey) !=0)
{
menuChoice=MenuEvent(Event);
menuID =HiWord(menuChoice);
MenuItem = LoWord(menuChoice);
if (menuID==mFile && MenuItem== iQuit)
gQuit=true;
}
break;
case updateEvt:
break;
case autoKey:
break;
case activateEvt:
break;
case osEvt:
break;
case mouseUp:
break;
}
}
void doMouseDown(EventRecord *EvtRec)
{
WindowPartCode partCode;
WindowRef windowRef;
SInt32 menuChoice;
Rect constraintRect, mainScreenRect;
Point standardStateHeightAndWidth;
partCode= FindWindow(EvtRec->where,&windowRef);
switch (partCode)
{
case inMenuBar:
menuChoice=MenuSelect(EvtRec->where);
doMenuChoice(menuChoice);
break;
case inContent:
if (windowRef!=FrontWindow())
SelectWindow(windowRef);
break;
case inDrag:
DragWindow(windowRef,EvtRec->where,NULL);
gQuit=true;
break;
case inGoAway:
if (TrackGoAway(windowRef,EvtRec->where))
gQuit=true;
break;
case inGrow:
constraintRect.top =75;
constraintRect.left =205;
constraintRect.bottom = constraintRect.right = 32767;
ResizeWindow(windowRef,EvtRec->where,&constraintRect,NULL);
gQuit=true;
break;
}
}