[comp.sys.amiga.programmer] Window Help

mwilkins@p3.f55.n282.z1.MMUG.EDGAR.MN.ORG (Mike Wilkins) (02/28/91)

I'm having a heck of a time opening a window from workbench. Could
someone please help me on what is probable somthing dumb I'm not doing?
I"m opening a window to workbench, and would like to print some text
in it, then wait & close. If I start it from CLI, all's fine.
But, if I start it from WorkBench via an icon, a small window opens up
at position 10,10, with a size of 320 x 80, with back/front, grag, and
size gadgets with the program name in the title area - Then my window
opens up, but all displays go to the first window!  AAAAAAAACCCKKKKKK!
Were is the smaller window comming from? And how do I print text to my
window?  I know I can open a CON: window and use write() to write to it,
but there has to be a solution to this and I really want to be able to
controll the gadgets in the window. I've even compiled a simple pgm that
only opens a window on the WorkBench screen & closes with the same
results. I use SAS/C on an amiga 500. HELP!

--  

                  Mike Wilkins (mwilkins@mmug.edgar.mn.org)
               UUCP: ...jhereg!tcnet!vware!edgar!mmug!mwilkins
                   FidoNet: 1:282/55.3 - Mike's Diner BBS

--

nj@magnolia.Berkeley.EDU (Narciso Jaramillo) (03/03/91)

In article <0.27CCDBB9@MMUG.EDGAR.MN.ORG> mwilkins@p3.f55.n282.z1.MMUG.EDGAR.MN.ORG (Mike Wilkins) writes:

   I"m opening a window to workbench, and would like to print some text
   in it, then wait & close. If I start it from CLI, all's fine.
   But, if I start it from WorkBench via an icon, a small window opens up
   at position 10,10, with a size of 320 x 80, with back/front, grag, and
   size gadgets with the program name in the title area - Then my window
   opens up, but all displays go to the first window!  AAAAAAAACCCKKKKKK!
   Were is the smaller window comming from? And how do I print text to my
   window?  I know I can open a CON: window and use write() to write to it,
   but there has to be a solution to this and I really want to be able to
   controll the gadgets in the window. I've even compiled a simple pgm that
   only opens a window on the WorkBench screen & closes with the same
   results. I use SAS/C on an amiga 500. HELP!

SAS/C assumes that your program will want ``stdin'' and ``stdout''
attached to a console window.  If you run your program from a CLI
window, stdin and stdout are automatically set to the CLI window.  If
you run your program from Workbench, however, there's no default
console for stdio, so the default SAS startup code will open a window
for you and attach stdin and stdout to that before calling your
program.  In other words, if you don't do anything special, printf and
scanf will always go to either the CLI window you started from, or
that extra window in the Workbench screen.

So you really have two problems--(1) you want to get rid of that
extra window, and (2) you want text to go to your own window.
To solve (1), you need to pass ``DEFINE _main=_tinymain'' as
an option to BLINK.  This tells SAS to link the _tinymain
startup code with your program; _tinymain doesn't open stdin
and stdout.

In order to do this, you'll need to run the linker separately.  So,
instead of doing ``lc -L prog'', you should do

  1> LC prog
  [...]
  1> BLINK FROM lib:c.o prog.o TO prog LIB lib:lc.lib lib:amiga.lib 
     DEFINE _main=_tinymain

(Of course, the DEFINE option needs to be on the same line as the BLINK
command; I just put it on the next line for clarity.)

See the file ``umain.c'' in the lc:/source directory for details, and
the entry for _tinymain on page L264 of the SAS manual.  Remember, if
you use _tinymain, you won't have stdin and stdout, so printf won't
work (unless you open stdin and stdout yourself).  You can still open
files using fopen and use them normally.

Now to problem (2).  If you open a CON: window as an I/O stream, you
can do fprintf's to it.  For example:

  FILE *fp;

  fp = fopen("CON:0/0/640/100/My Window", "w");
  if (fp) {
    fprintf(fp, "Hello World!\n");
    /* ... */
  }

You don't really have any control over a window opened this way, in
terms of being able to put gadgets in it and so forth; all you have a
pointer to is the I/O stream.  You can open an Intuition window and
attach a console.device to it, but then your gadgets will probably be
clobbered by whatever the console device writes.  Since all you really
want to do is print some text, you should probably use the Intuition
text rendering functions, which will write text directly into your
Window's RastPort.  If you need printf()-style formatting, you can use
sprintf() to format the string into a buffer, then pass that in an
IntuiText structure to the text rendering function.  Information on
this stuff is in the RKMs.


nj

mwilkins@p3.f55.n282.z1.mmug.edgar.mn.org (Mike Wilkins) (03/05/91)

Thanks for your help.

--  

                  Mike Wilkins (mwilkins@mmug.edgar.mn.org)
               UUCP: ...jhereg!tcnet!vware!edgar!mmug!mwilkins
                   FidoNet: 1:282/55.3 - Mike's Diner BBS

--