Click here to Skip to main content
16,011,905 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralResource Error (Opened in another editor) Pin
brdavid24-Sep-04 12:17
brdavid24-Sep-04 12:17 
GeneralRe: Resource Error (Opened in another editor) Pin
Gary R. Wheeler24-Sep-04 16:03
Gary R. Wheeler24-Sep-04 16:03 
GeneralRe: Resource Error (Opened in another editor) Pin
brdavid25-Sep-04 4:43
brdavid25-Sep-04 4:43 
GeneralRe: Resource Error (Opened in another editor) Pin
brdavid25-Sep-04 11:18
brdavid25-Sep-04 11:18 
Generalinteger displayed instead of string Pin
lordmickel24-Sep-04 12:11
lordmickel24-Sep-04 12:11 
GeneralRe: integer displayed instead of string Pin
Alexander M.,24-Sep-04 12:40
Alexander M.,24-Sep-04 12:40 
GeneralRe: integer displayed instead of string Pin
lordmickel25-Sep-04 10:45
lordmickel25-Sep-04 10:45 
GeneralString editing using Borland C++ and AIX in Linux Pin
youngashish24-Sep-04 12:09
youngashish24-Sep-04 12:09 
This is my dtio.h file and after that is the dtio.c file

/**********************************************************
* dtio.h - header file for direct-terminal I/O functions *
* supporting both Borland C and AIX cc platforms *
**********************************************************/

#ifndef _dtio_h_
#define _dtio_h_

#define BORLANDC 1
#define AIXC 2
/* change the following line to support one of the above */
#define PLATFORM AIXC

/* some platform-dependent keys (obtained by experimentation) */
#if PLATFORM == AIXC
#define ENTER_KEY 10
#define UP_KEY 1859
#define DOWN_KEY 1858
#define LEFT_KEY 1860
#define RIGHT_KEY 1861
#define PGUP_KEY 1939
#define PGDN_KEY 1938
#define TAB_KEY 9
#define BS_KEY 8
#define DEL_KEY 1930
#define HOME_KEY 1862
#define END_KEY 1860
#define ESC_KEY 27
#define INS_KEY 1931
#define F1_KEY 1865
#define F2_KEY 1866
#define F3_KEY 1867
#define F4_KEY 1868
#define F5_KEY 1869
#define F6_KEY 1870
#define F7_KEY 1871
#define F8_KEY 1872
#define F9_KEY 1873
#define F10_KEY 1874
#else
#define ENTER_KEY 13
#define UP_KEY 1072
#define DOWN_KEY 1080
#define LEFT_KEY 1075
#define RIGHT_KEY 1077
#define PGUP_KEY 1073
#define PGDN_KEY 1081
#define TAB_KEY 9
#define BS_KEY 8
#define DEL_KEY 1083
#define HOME_KEY 1071
#define END_KEY 1079
#define ESC_KEY 27
#define INS_KEY 1082
#define F1_KEY 1059
#define F2_KEY 1060
#define F3_KEY 1061
#define F4_KEY 1062
#define F5_KEY 1063
#define F6_KEY 1064
#define F7_KEY 1065
#define F8_KEY 1066
#define F9_KEY 1067
#define F10_KEY 1068
#endif

void dt_start(void); /* initializations for dt routines */
void dt_stop(void); /* shutdown of dt routines */
int dt_rows(void); /* find # of rows of screen */
int dt_columns(void); /* find # of columns of screen */
void dt_clear(void); /* clear screen */
void dt_flush(void); /* flush any un-written output */
int dt_getchar(void); /* get one key press */
void dt_cursor(int row, int column); /* move cursor */
void dt_putchar(int c);/* output one character */
void dt_puts(char *s); /* output a string */
void dt_display(const char *s, int row, int column, int length);
int dt_edit(char *s, int row, int col, int flen, int slen, int *ppos,int *poff);
#endif /* end _dtio_h_ */

*************************************************************

This is the dtio.c file:

/**********************************************************
* dtio.c - direct-terminal I/O functions supporting both *
* Borland C and AIX cc platforms. A program that *
* wants to use these should: #include "dtio.h" *
**********************************************************/

#include "dtio.h"
#if PLATFORM == AIXC
#include <curses.h>
#else
#include <conio.h>
#endif

/* Initialize. Note that Borland version does nothing. */
void dt_start(void)
{
#if PLATFORM == AIXC
initscr();
noecho();
cbreak();
keypad(stdscr, 1);
#endif
}

/* Shutdown */
void dt_stop(void)
{
#if PLATFORM == AIXC
refresh();
endwin();
#else
/* we don't want the cursor left in the
middle of a screen. AIX's endwin() handles
this for us, but on the PC we must take care
of this. Clearing the screen is an easy way. */
clrscr();
#endif
}

/* Return number of screen rows */
int dt_rows(void)
{
#if PLATFORM == AIXC
return LINES;
#else
struct text_info x;
gettextinfo(&x);
return x.screenheight;
#endif
}

/* Return number of screen columns */
int dt_columns(void)
{
#if PLATFORM == AIXC
return COLS;
#else
struct text_info x;
gettextinfo(&x);
return x.screenwidth;
#endif
}

/* Clear screen */
void dt_clear(void)
{
#if PLATFORM == AIXC
erase();
#else
clrscr();
#endif
}

/* Bring screen up-to-date. Note that since dt_stop() and
* dt_getchar() both bring the screen up-to-date, programs
* will only have to call this if the screen must be brought
* up-to-date when a long pause (other than waiting for
* input) is expected.
*/
void dt_flush(void)
{
#if PLATFORM == AIXC
refresh();
#endif
}

/* Return one keystroke, bringing screen up-to-date first */
int dt_getchar(void)
{
#if PLATFORM == AIXC
refresh();
return getch();
#else
/* For extended keys in DOS, return 1000 + second key code */
int key;
key = getch();
return key == 0 ? 1000 + getch() : key;
#endif
}

/* Move cursor. (0, 0) is the upper-left corner */
void dt_cursor(int row, int column)
{
#if PLATFORM == AIXC
move(row, column);
#else
gotoxy(column + 1, row + 1);
#endif
}

/* Output one character at cursor location */
void dt_putchar(int c)
{
#if PLATFORM == AIXC
addch(c);
#else
putch(c);
#endif
}

/* Output character string at cursor location */
void dt_puts(char *s)
{
#if PLATFORM == AIXC
addstr(s);
#else
cputs(s);
#endif
}

void dt_display(const char *s, int row, int column, int length)
{
#if PLATFORM == AIXC
int length1=strlen(s);
#if length1 > length
for (i=0;i<length;i++)
{
addch(s[i]);
}
move(LINES,COLS);
#elif length1 < length
int space=length-length1;
addstr(s);
for (i=0;i<space;i++)
{
addch(' ');
}
move(LINES,COLS);
#elif length <= 0
addstr(s);
move(LINES,COLS);
#endif
#else
int length1=strlen(s);
struct text_info x;
gettextinfo(&x);
#if length1 > length
for (i=0;i<length;i++)
{
putch(s[i]);
}
gotoxy(x.screenwidth-1,x.screenheight-1);
#elif length1 < length
int space=length-length1;
addstr(s);
for (i=0;i<space;i++)
{
addch(' ');
}
gotoxy(x.screenwidth-1,x.screenheight-1);
#elif length <= 0
addstr(s);
gotoxy(x.screenwidth-1,x.screenheight-1);
#endif
#endif
}


int dt_edit(char *s, int row, int col, int flen, int slen, int *ppos,int *poff)
{
#if PLATFORM == AIXC


************************************************************
This is what is required please help me:

void dt_start(void)
initializes the full screen routines. This should be called before
calling any of the other "dt" functions (and may only be called once
before dt_stop() is called to stop using the full screen rountines).

void dt_stop(void)
shuts down the use of the terminal control routines, and ensures
that the cursor is not left in the middle of screen full of stuff.
Note that a program which has called dt_start() (defined above) must
call this function before terminating.

int dt_rows(void)
returns the number of rows on the screen.

int dt_columns(void)
returns the number of columns on the screen.

void dt_clear(void)
clears the screen, ensuring the cursor is in the upper left corner
when finished.

void dt_flush(void)
ensures that any full screen output which has been sent to the
screen actually gets there (i.e. this "flushes the output buffer").

int dt_getchar(void)
flushes screen output (if there is any pending output which has not
yet been displayed), waits for a key to be pressed and returns an
int value uniquely identifying the key pressed. Note that for
non-ASCII keys, the value for a key is system dependent, but the
following symbolic names should be set up appropriately (in dtio.h):

UP_KEY - the value for the up arrow key
DOWN_KEY - the value for the down arrow key
LEFT_KEY - the value for the left arrow key
RIGHT_KEY - the value for the right arrow key
PGUP_KEY - the value for the page up (or previous screen) key
PGDN_KEY - the value for the page down (or next screen) key
ENTER_KEY - the value for the enter (or carriage return) key
TAB_KEY - the value for the tab key
BS_KEY - the value for the backspace key
DEL_KEY - the value for the delete key
HOME_KEY - the value for the home key
END_KEY - the value for the end key
ESC_KEY - the value for the escape key
INS_KEY - the value for the insert key
F1_KEY, F2_KEY, ... F10_KEY - the values for the F1 through
F10 keys, respectively

void dt_cursor(int row, int column)
positions the cursor at the row and column specified, where row 0 is
the top row and column 0 is the left-most column. (Note that the
results are not defined if the row or column is invalid. Note also
that on systems where output is buffered, this function does NOT
flush the output buffer.)

void dt_putchar(int c)
outputs the character, with the ASCII code stored in "c", at the
current position on the screen. This function advances the cursor by
one position, although the results are system dependent if the
cursor is already at the right edge of the screen. (Note that on
systems where output is buffered, this function does not flush the
output buffer).

void dt_puts(const char *s)
outputs the null-terminated string pointed to by "s", starting at
the current position on the screen. Afterwards, the cursor position
is just after the last character that was displayed. The results are
not defined if the length of the string exceeds the available space
left on the current line of output. (Note that on systems where
output is buffered, this function does not flush the output buffer,
and that if the last character of the string appears on the last
column of the string, the position of the cursor will be system
dependent).

void dt_display(const char *s, int row, int column, int length)
outputs the null-terminated string pointed to by "s", in a field of
the screen starting at row "row" and column "column" of the screen,
for a length of "length" characters. As with dt_cursor, 0 is the top
row, and 0 is the leftmost column. If the string is longer than
"length", then only "length" characters are displayed, but if it is
shorter than "length", then the entire string is displayed, followed
by enough trailing spaces to fill out the field. However, if
"length" is 0 or less, then the field length is considered to be the
actual length of the string (i.e. the entire string is displayed).
Afterwards, the cursor is positioned after the last position of the
field. (Note that on systems where output is buffered, this function
does not flush the output buffer, and that if the last character of
the string appears on the last column of the string, the position of
the cursor will be system dependent). The results are undefined if
the specified values indicate a field which does not fit on the
screen.

int dt_edit(char *s, int row, int col, int flen, int slen, int *ppos,
int *poff)
allows the user to perform full screen editing of a null-terminated
string in a single-line field on the screen. The parameters are:
s - points to the string being edited.
row - the row of the screen for the field, where 0 is the top row
of the screen.
col - the starting column for the field, where 0 is the left-most
column of the screen.
flen - the length of the field in which editing is performed, or
0, in which case the initial length of "s" determines the
field length. Note that the field length determines the
maximum number of characters from the string that can be
displayed at the same time.
slen - the maximum possible length for the string, or 0, in which
case the field length is also the maximum string length. If
this is larger than the field length, then it will be
possible for the user to enter a string larger than what can
be displayed in the field, and so the string will have to be
"scrolled" as it it edited so that the position of the
cursor within the string will always be visible.
ppos - this is either NULL or it points to an int containing the
current position of the cursor within the field, where 0
means that the cursor is on the first position of the field.

If it is non-NULL, note that this parameter has two uses: it
determines the starting location of the cursor within the
field and it is used to communicate back to the calling
function where the cursor was when editing stopped.

If this parameter is NULL, the cursor initially is placed on
the first character of the field, and the calling function
will not be able to know where the cursor was when editing
stopped.
poff - this is either NULL or it points to an int containing the
index of the character from the string which appears in the
first position of the field, i.e. the offset by which the
string is scrolled.

If it is non-NULL, note that this parameter has two uses: it
determines the initial scrolling offset when editing starts
and it is used to communicate back to the calling function
how much the string was scrolled when editing stopped.

If this parameter is NULL, the first character of the string
is initially displayed in the first position of the field,
and the calling function will not be able to find out how
much the string was scrolled when editing stopped.

The cursor is never allowed to move before the start of the field or
more than one position past the last character in the string or the
field, whichever comes first. Additionally, in the case where the
field ends at the edge of the screen, the cursor is not allowed past
the edge of the screen.

Editing is terminated by pressing ENTER_KEY, TAB_KEY, ESC_KEY,
UP_KEY, DOWN_KEY, PGUP_KEY, PGDN_KEY or any of the function keys
F1_KEY to F10_KEY. (You may extend this to include all function
keys, if you wish). If ESC_KEY is used to terminate editing, then
editing is aborted - the string is left containing the data
originally passed to dt_edit(), the variables pointed to by ppos and
poff (if any) retain their original values, and the original string
value is redisplayed.

The function returns an int identifying the the key that was pressed
to exit. (This function uses the same key codes as dt_getchar()
above).

The function takes no action (other than perhaps beeping) if the
user tries to enter too many characters (if, for example, the string
is full in insert mode, or the cursor is positioned after the last
character of a full string in overstrike mode).

The function handles at least the following special keys:

LEFT_KEY - move left one character, if possible.
RIGHT_KEY - move right one character, if possible.
HOME_KEY - go to the beginning of the string.
END_KEY - go to the end of the data in the string, i.e. just
past the last character in the string. (If the last
character is at the edge of the screen, then END goes to
that character).
INS_KEY - toggle Insert/Overstrike mode (the default is Insert).
In Insert mode, printable characters are inserted into the
string, moving the remainder of the string to the right to
make room. In Overstrike mode, printable characters
overwrite existing characters (if any). Note that if you are
past the end of the string, printable characters are
appended to the string (as long as the string isn't full)
regardless of the mode. Also note that, regardless of the
mode, the cursor advances as printable characters are typed
into the string.
DEL_KEY - eat the current character and move all subsequent
characters one position to the left.
BS_KEY - move the rest of the string (including the cursor) one
position to the left, if possible, eating the previous
character.

Any normal printable key is simply placed into the string according
to the rules laid out in the discussion of the INS_KEY key above.
(The keys from the space character to the tilde character in the
ASCII table are considered "printable".)

The dt_edit() function always shows blanks in any the part of the
field that is not occupied by the data in the string. UNDER NO
CIRCMUSTANCES DOES THE FUNCTION CHANGE ANY POSITION ON THE SCREEN
OUTSIDE OF THE FIELD. For example, it is important that you don't
display status information (such as "INS" or "OVR") elsewhere on the
screen, since this will limit the programmer's ability to design
screen layouts.

Like most C library functions, your dt_edit() may assume that it is
the calling program's reponsibility to ensure that the array is
large enough to handle the specified number of characters, and that
the starting screen position provides enough room (on the screen)
for the field, etc.

Technical Note: in order to be able to restore the string to its
original value, you will need a backup copy of it. Since you won't
be able to predict the size of the string to be edited at compile
time, the only safe way to do this is by using dynamic memory
allocation. Investigate the functions strdup(), malloc() and free()
to learn how to do this in C.

These functions are to be declared in a file named dtio.h along with the
symbolic key codes mentioned above. The functions are to be defined in a
file named dtio.c. They should compile and work properly (according to
the specs above) in both the "Command Prompt box" under Windows (you may
use either the Borland C++ compiler or the Microsoft Visual C++
compiler, although you are on your own for technical help with Visual
C++), the AIX cc environment on phobos, and the Linux cc (gcc)
environment on matrix. At most one or two lines of dtio.h should need to
be modified when changing from one environment to another.
GeneralRe: String editing using Borland C++ and AIX in Linux Pin
Aamir Butt24-Sep-04 20:13
Aamir Butt24-Sep-04 20:13 
GeneralRe: String editing using Borland C++ and AIX in Linux Pin
Anonymous25-Sep-04 11:05
Anonymous25-Sep-04 11:05 
QuestionGetMenuItemInfo didn't work in WinNT 4.0, why? Pin
Cyrus Dang24-Sep-04 11:50
Cyrus Dang24-Sep-04 11:50 
AnswerRe: GetMenuItemInfo didn't work in WinNT 4.0, why? Pin
David Crow24-Sep-04 12:07
David Crow24-Sep-04 12:07 
AnswerRe: GetMenuItemInfo didn't work in WinNT 4.0, why? Pin
Michael Dunn24-Sep-04 12:34
sitebuilderMichael Dunn24-Sep-04 12:34 
GeneralRe: GetMenuItemInfo didn't work in WinNT 4.0, why? Pin
Cyrus Dang24-Sep-04 12:56
Cyrus Dang24-Sep-04 12:56 
GeneralBypassing Declarative Security Pin
Chef Jeff24-Sep-04 11:40
sussChef Jeff24-Sep-04 11:40 
QuestionHow to change wchar string to CString easily Pin
sixiang24-Sep-04 11:12
sixiang24-Sep-04 11:12 
AnswerRe: How to change wchar string to CString easily Pin
Alexander M.,24-Sep-04 12:35
Alexander M.,24-Sep-04 12:35 
GeneralRe: How to change wchar string to CString easily Pin
sixiang24-Sep-04 13:49
sixiang24-Sep-04 13:49 
GeneralRe: How to change wchar string to CString easily Pin
Alexander M.,25-Sep-04 0:20
Alexander M.,25-Sep-04 0:20 
AnswerRe: How to change wchar string to CString easily Pin
Michael Dunn24-Sep-04 12:36
sitebuilderMichael Dunn24-Sep-04 12:36 
General#define SOMETHING in new configuration type Pin
BlackDice24-Sep-04 9:09
BlackDice24-Sep-04 9:09 
GeneralRESOLVED Pin
BlackDice24-Sep-04 9:32
BlackDice24-Sep-04 9:32 
QuestionHow to go about this... Pin
mirano24-Sep-04 9:04
mirano24-Sep-04 9:04 
AnswerRe: How to go about this... Pin
Henry miller24-Sep-04 10:20
Henry miller24-Sep-04 10:20 
AnswerRe: How to go about this... Pin
Neville Franks24-Sep-04 12:29
Neville Franks24-Sep-04 12:29 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.