replica nfl jerseysreplica nfl jerseyssoccer jerseyreplica nfl jerseys forums.silverfrost.com :: View topic - How to refresh a text buffer in an edit-box window, with SCC
forums.silverfrost.com Forum Index forums.silverfrost.com
Welcome to the Silverfrost forums
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

How to refresh a text buffer in an edit-box window, with SCC

 
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> General
View previous topic :: View next topic  
Author Message
Little-Acorn



Joined: 06 Jul 2008
Posts: 111
Location: San Diego

PostPosted: Wed Nov 28, 2012 1:58 am    Post subject: How to refresh a text buffer in an edit-box window, with SCC Reply with quote

I am putting together a "Status Window" that will be used by a C program as it runs, compiled on the SCC compiler. (I did sometimg similar a year or two ago using Ftn95). It is opened at the beginning of the program, displaying a single short line of text. As the program runs, occasionally more lines will appear below the first line, keeping the user informed of various status items in the program.

I have put together a function that opens the window, using %ca to put the caption "Status Window" in the top bar. It also loads the 1000-long buffer with its opening message, that says "Program started", followed by a \n and a \0. This works adequately, showing that message in the window when the %eb command is given.

For the next step, I would like to append a second line (in this experiment, it simply says "This is the second line") to the buffer, keeping the \n at the end of the "Program started" so that the second line appears below the first.

My questions are:

1.) Is there a way to assign a string directly into a character array? Or, is there a special "string" data type, and ways to convert from that to "char" arrays?

2.) Do I need to remove the \0 from the end of the first line, before I append the second line to it? And do I then need to put a \0 at the end of the second line? Or can I do without \0 characters altogether?

3.) Once I append the characters of the second line, is there a way to "refresh" what is showing in the window displaying that buffer, so that the (new) contents now show in the window? There was such a command in Ftn95, as I recall.
Back to top
View user's profile Send private message
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 8200
Location: Salford, UK

PostPosted: Wed Nov 28, 2012 9:46 am    Post subject: Reply with quote

You probably need to call strcat (see the SCC help file that can be opened from the Plato Help menu).

Updating the screen is usually done by calling window_update (you will find this described in the cwpscc.hlp file found in the same folder as scc.exe - if you have downloaded the driver as described in an earlier post then just double click on cwpscc.hlp in the standard Explorer Window).
Back to top
View user's profile Send private message AIM Address
Little-Acorn



Joined: 06 Jul 2008
Posts: 111
Location: San Diego

PostPosted: Fri Nov 30, 2012 1:31 am    Post subject: Reply with quote

Thank you, Paul. I downloaded the driver, and the HELP file now works fine.

And, strcat works as advertised. Looks like I don't have to worry about inserting or deleting \0 characters.

But for some reason I can't get update_window to work. In the following code, the main program calls a function (drawstatwin) that loads a string variable (statbuf) with a string, then concatenates another string onto it, then opens an %eb window with that string in it. Both strings appear as expected, that part works well.

Then the main program calls another function (writstat) that is supposed to concatenate yet another string onto the end of the previous strings, and make it appear with all three strings in the window. A print statement (that I have now commented out) showed that the third string got correctly concatenated, and that all three strings were now in the "statbuf" variable. But only the first two strings still show up in the window, even after calling update_window.

Actually I expected to see all three strings appear, virtually instantly, since there is no real pause between putting up the first two strings, and concatenating the third string and updating. But the first two strings appear, and the third one never does.

Am I using update_window correctly?

-------------------------------------
Code:
#include <stdio.h>
#pragma windows
#include <windows.h>
#include <string.h>

char statbuf[32000];

int drawstatwin(xulcorner,yulcorner,xwidth,yheight)
{
  int mdi;
  winio("%ca[Status Window]&");      /* Put caption in window's top bar */
  winio("%ap&",xulcorner,yulcorner); /* Place window's upper left corner */
  winio("%ww[no_frame]&");           /* %ww=Window control. Makes window resizeable,
                                          [no_frame] omits thin-line frame inside
                                          window border. Other options available.*/
  winio("%pv&");                     /* %pv=Pivot. Things to right move right, things
                                           below move down when window is resized. */
  winio("%fr&",0,600);               /* %fr=Create MDI frame for child window. */
  winio("%lw&",&mdi);                /* %lw leave the window open as control is
                                          returned to main() */
  winio("%80.30eb",statbuf,32000);   /* Draw the status box as an edit box */
  return(1);
}
 
int writstat(char* newstat) /* char* makes it accept arg of type char, of any length */
{
  int i;
  i=13;
  /*printf("\nFunction writstat has been entered.\nnewstat=%s\n",newstat);*/
  strcat(statbuf,"\n");
  strcat(statbuf,newstat);
  update_window(statbuf);
  /*printf("In writstat, after concatenation statbuf=%s\n",statbuf);*/
  return(i);
}

main()

  int i;
  /*printf("Hello, world! \n\n");*/
  strcpy(statbuf,"Does the status window work?");
  strcat(statbuf,"\nTime will tell!");
  drawstatwin(0,0,10,10);
  writstat("Here's a string sent to writstat.");
  printf("writstat has been called and completed.\n");
   update_window(statbuf);
 return(0);
}
---------------------------------------
Back to top
View user's profile Send private message
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 8200
Location: Salford, UK

PostPosted: Fri Nov 30, 2012 8:42 am    Post subject: Reply with quote

The relevant update function is called window_update not update_window.
You should pass a pointer which is OK in this context because you will pass a char*. For scalar int etc. you would need to pass &x.
Back to top
View user's profile Send private message AIM Address
LitusSaxonicum



Joined: 23 Aug 2005
Posts: 2402
Location: Yateley, Hants, UK

PostPosted: Fri Nov 30, 2012 3:59 pm    Post subject: Reply with quote

The use of update_window@ instead of window_update@ or vice versa is the source of otherwise hard to find problems. I can never remember which is which.

E
Back to top
View user's profile Send private message
Little-Acorn



Joined: 06 Jul 2008
Posts: 111
Location: San Diego

PostPosted: Fri Nov 30, 2012 4:52 pm    Post subject: Reply with quote

Works great now! Thank you, Paul and Eddie, for catching one of my sillier stupidities.

Strange how I didn't get a compile-time error for misspelling it. Perhaps there actually is another function called update_window, that does something else?
Back to top
View user's profile Send private message
LitusSaxonicum



Joined: 23 Aug 2005
Posts: 2402
Location: Yateley, Hants, UK

PostPosted: Fri Nov 30, 2012 8:16 pm    Post subject: Reply with quote

Yes, there are both functions - which is why it is easy to forget which is which! window_update@ needs a variable passed to it, while update_window@ needs the window's handle (which you won't have if you don't ask for it explicitly).

Eddie
Back to top
View user's profile Send private message
Little-Acorn



Joined: 06 Jul 2008
Posts: 111
Location: San Diego

PostPosted: Fri Nov 30, 2012 9:04 pm    Post subject: Reply with quote

(oops, duplicate post, sorry)

Last edited by Little-Acorn on Fri Nov 30, 2012 9:05 pm; edited 1 time in total
Back to top
View user's profile Send private message
Little-Acorn



Joined: 06 Jul 2008
Posts: 111
Location: San Diego

PostPosted: Fri Nov 30, 2012 9:04 pm    Post subject: Reply with quote

Now I just need to figure out a way to place this window where I want on the screen.

The drawstatwin function puts up a window, that has the Edit Box in it. But I was surprised to find that the %ap command in that function, only controls where the Edit Box goes INSIDE the window. The window itself, is always centered on the screen I was hoping to control where the window itself goes.

Is there some way to specify where the window itself goes on the screen?
Back to top
View user's profile Send private message
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 8200
Location: Salford, UK

PostPosted: Fri Nov 30, 2012 11:29 pm    Post subject: Reply with quote

%sp
Back to top
View user's profile Send private message AIM Address
Little-Acorn



Joined: 06 Jul 2008
Posts: 111
Location: San Diego

PostPosted: Sat Dec 01, 2012 1:36 am    Post subject: Reply with quote

Bingo, thank you Paul!
Back to top
View user's profile Send private message
LitusSaxonicum



Joined: 23 Aug 2005
Posts: 2402
Location: Yateley, Hants, UK

PostPosted: Sat Dec 01, 2012 5:35 am    Post subject: Reply with quote

Reading the descriptions of format codes in FTN95.CHM sounds about as interesting as reading the phone directory, but it is rather useful. There is a list of codes in alphabetical order, and judicious use of the navigation in this helpfile also gets you to format codes listed by function. The Help menu of Plato goes straight to the right part of FTN95.CHM You may also find some help by reading Cwplus.enh, which is a plain text file installed in the DOC folder of FTN95, as the description there of format codes is sometimes different to the description in FTN95.CHM (not better or worse, just different).

These format codes are the same in SCC as they are in FTN95 (obvious really).

There is also an alphabetically ordered list of associated subroutines and functions. (returning to the earlier discussion, UPDATE_WINDOW@ is in this alphabetic list, but WINDOW_UPDATE@ isn't - a notable omission in my view).

Complementing %sp there is also %gp (get position). Years ago Paul helped me with this. You can use %gp when you close a window (put it in the callback to a %cc control) and save the coordinates for use in %sp next time you open that window - then it pops up in the same place as it was last time it was closed.

Eddie
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> General All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group