[comp.sys.mac.programmer] Windows and controls

resnick@cogsci.uiuc.edu (Pete Resnick) (01/30/91)

OK, easy beginner's question: what's wrong with this picture (I mean,
window)? The following code brings up a window, but none of my controls
appear in it. (The first two are vertical scrollbars, the third is a
panel divider I wrote myself.) Am I missing something?

pr
-------------------
void MakeNewWindow(WindowPtr myWindow, StringPtr windowName);

main()
{
	WindowRecord myWindow;
	EventRecord myEvent;
	
	InitGraf(&thePort);
	InitFonts();
	InitWindows();
	MakeNewWindow((WindowPtr)&myWindow, (StringPtr)"\ptesting");
	while(!WaitNextEvent(mDownMask, &myEvent, 0xFFFFFFFF, 0L));
}

void MakeNewWindow(WindowPtr myWindow, StringPtr windowName)
{
	GetNewWindow(128, myWindow, -1L);
	SetPort(myWindow);
	GetNewControl(128, myWindow);
	GetNewControl(129, myWindow);
	GetNewControl(130, myWindow);
	SetWTitle(myWindow, windowName);
	BeginUpdate(myWindow);
	EraseRect(&myWindow->portRect);
	DrawGrowIcon(myWindow);
	DrawControls(myWindow);
	EndUpdate(myWindow);
	ShowWindow(myWindow);
}
--
Pete Resnick             (...so what is a mojo, and why would one be rising?)
Graduate assistant - Philosophy Department, Gregory Hall, UIUC
System manager - Cognitive Science Group, Beckman Institute, UIUC
Internet/ARPAnet/EDUnet  : resnick@cogsci.uiuc.edu
BITNET (if no other way) : FREE0285@UIUCVMD

mxmora@unix.SRI.COM (Matt Mora) (01/31/91)

Even thought I'm not a C programmer I'll take a stab at it.

In article <1991Jan30.030241.27264@ux1.cso.uiuc.edu> resnick@cogsci.uiuc.edu (Pete Resnick) writes:


>void MakeNewWindow(WindowPtr myWindow, StringPtr windowName)
>{
>	GetNewWindow(128, myWindow, -1L);
>	SetPort(myWindow);
   -->  ShowWindow(myWindow);
>	GetNewControl(128, myWindow);
>	GetNewControl(129, myWindow);
>	GetNewControl(130, myWindow);
>	SetWTitle(myWindow, windowName);
   -->  BeginUpdate(myWindow);
   -->  EraseRect(&myWindow->portRect);
>	DrawGrowIcon(myWindow);
>	DrawControls(myWindow);
   -->  EndUpdate(myWindow);
   -->  ShowWindow(myWindow);
>}

I'm assuming that your are calling every thing correctly and that you do get a 
valid window.

I'm also  assuming that the window is invisible and that your sample program
does not have an update routine. You need to show your window as soon as
possible because you don't service an update event. You also don't need
the beginupdate/endupdate. Even if you did have an update routine those calls
would cancel the update event. (because it assumes that you just did an update)
You don't need to erase the window or the last showwindow either.






Matt




-- 
___________________________________________________________
Matthew Mora                |  my Mac  Matt_Mora@QM.SRI.COM
SRI International           |  my SUN   mxmora@unix.sri.com
___________________________________________________________