A User Item in a Dialog
A User Item in a Dialog
// A user item in a dialog
// An example of placing a user item in a modal dialog
// Make sure that the user item in the dialog is enabled.
// Assumes inclusion of
#include
void ToolBoxInit (void);
void DialogInit (void);
pascal void myItem (WindowPtr theWindow, short itemNo);
void MainLoop (void);
Rect gButtonRect;
Boolean gDone;
DialogPtr gTheDialog;
main ()
{
ToolBoxInit ();
DialogInit ();
MainLoop ();
}
void ToolBoxInit ()
{
InitGraf (&thePort);
TEInit ();
}
pascal void myItem (WindowPtr theWindow, short itemNo)
{
Point beginPoint;
Str255 buttonStr = "\pOh!";
FontInfo fInfo;
PenSize (1,1);
FrameRoundRect (&gButtonRect, 16, 16);
beginPoint.h = gButtonRect.left + (gButtonRect.right - gButtonRect.left)/2
- StringWidth(buttonStr)/2;
GetFontInfo (&fInfo);
beginPoint.v = gButtonRect.top + (gButtonRect.bottom - gButtonRect.top)/2
+ (fInfo.ascent)/2;
MoveTo (beginPoint.h, beginPoint.v);
DrawString ("\pOh!");
PenSize (3,3);
InsetRect (&gButtonRect, -4, -4);
FrameRoundRect (&gButtonRect, 16, 16);
}
void DialogInit ()
{
short itemType;
Rect itemRect;
Handle itemHandle;
gTheDialog = GetNewDialog ( 128, nil, (WindowPtr) -1);
if (gTheDialog) {
GetDItem ( gTheDialog, 1, &itemType, &itemHandle, &itemRect );
gButtonRect = itemRect;
SetDItem (gTheDialog, 1, itemType, (Handle) myItem, &itemRect);
}
else
exit (1);
}
void MainLoop ()
{
EventRecord theEvent;
short itemHit;
gDone = FALSE;
ShowWindow (gTheDialog);
while (gDone == FALSE )
{
ModalDialog(nil, &itemHit );
switch (itemHit) {
case 1:
gDone = TRUE;
break;
}
}
}
/* A Rez description file for the 'DLOG' and 'DITL' resources used by the User Item
* example above
*/
#include "Types.r
resource 'DLOG' (128) {
{40, 40, 240, 280},
dBoxProc,
invisible,
noGoAway,
0x0,
128,
};
resource 'DITL' (128) {
{ /* array DITL array: 1 elements */
/* [1] */
{80, 79, 120, 161},
UserItem {
enabled
}
}
};