home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / lang / c / 18414 < prev    next >
Encoding:
Text File  |  1992-12-15  |  2.4 KB  |  81 lines

  1. Newsgroups: comp.lang.c
  2. Path: sparky!uunet!gatech!asuvax!cs.utexas.edu!geraldo.cc.utexas.edu!slcs.slb.com!PJONES@128.58.42.3
  3. From: pjones@asl.slb.com
  4. Subject: Passing variable length arguments -twice- ... revisited.
  5. Message-ID: <1992Dec15.164604.19705@slcs.slb.com>
  6. Sender: news@slcs.slb.com (News Administrator)
  7. Nntp-Posting-Host: 129.87.186.2
  8. Reply-To: pjones@asl.slb.com
  9. Organization: Schlumberger/Anadrill Sugar Land, TX
  10. Date: Tue, 15 Dec 92 16:46:04 GMT
  11. Lines: 68
  12.  
  13.  
  14.  
  15. This is the same question as before, but with the necessary details.  Thanks
  16. to all who answered with the vprintf() suggestions ... I learned something
  17. there.  The problem with vprintf() is that it prints only in black and white
  18. ... it ignores the textcolor() and textbackground() settings that I am 
  19. using.  So the new questions are:
  20.  
  21.  1. Can I pass the arguments to cprintf()?  The code below does not work
  22.     with cprintf() (I didn't expect it to),  but it does work with vprintf().
  23.  
  24.  2. If the answer to #1 is "No",  can I get vprintf() to print in the
  25.     colors already selected?
  26.  
  27. I am using Borland C++ 3.1,  and I have called the help desk. I've also 
  28. looked in FAQ and only vprintf() is mentioned.
  29.  
  30. If any of you are offended with some flaw in my programming style,  I bow
  31. before you in shame and hope that one day you may forgive my transgressions.
  32.  
  33. -----
  34.  
  35. void disp_error(char *msg, ...)
  36. {
  37.   box error_box( double_line, DOS_COLOR, WARNING_COLOR );
  38.   struct text_info ti;
  39.   int top=10, left=10, bottom=14, right=70;
  40.   char underneath[800];
  41.   va_list ap;
  42.  
  43.   // Handle variable parameters.
  44.   va_start(ap,msg);
  45.  
  46.   // Get the current settings ... to be restored later.
  47.   gettextinfo(&ti);
  48.  
  49.   // Save what will be under the box
  50.   gettext(left, top, right, bottom, underneath);
  51.  
  52.   // Reset screen to full size,  and draw the box.
  53.   window(1,1, ti.screenwidth, ti.screenheight);
  54.   error_box.draw(top, bottom, left, right);
  55.  
  56.   // Write 'Error' in the window
  57.   gotoxy(((right-left)>>1)+left-4, top);
  58.   cprintf("  ERROR  ");
  59.  
  60.   // Set the window just inside the box borders, then print the message.
  61.   window(left+1, top+1, right-1, bottom-1);
  62.   gotoxy(1,1);
  63.   vprintf(msg, ap);  // CAN I USE cprint() SOMEHOW???
  64.  
  65.   // Wait for key press
  66.   window(left, top, right, bottom);
  67.   press_any_key((right-left)/2 - 19, bottom-top+1);
  68.  
  69.   // Restore stuff underneath
  70.   puttext(left, top, right, bottom, underneath);
  71.  
  72.   restore_settings(&ti);
  73.  
  74.   va_end(ap);
  75. }
  76. ----
  77.  
  78. Thanks in advance,
  79. Phil Jones
  80. pjones@asl.sinet.slb.com
  81.