Console width and height, MS Visual C++

P

Piotrek

<<If this message is duplicated, please ignore the previous one, I had
some connection problems>>

Hi,
Could you please tell me how to check width and height of Windows
console program (cmd.exe)in MS Visual C++ 2005 Express Edition?

The goal is something like "more" command. So I print n lines of a file,
where n is number of rows, program waits for a key and prints further
part of that file, etc.

I've found description of "gettextinfo" function [void
gettextinfo(struct text_info *Info); ] in "conio.h". But this is Borland
implementation. I think there's no such function in MS C++.

What's more I want it to be a clean C program, without C++ objects.

Thank you!
 
W

Walter Roberson

Piotrek said:
Could you please tell me how to check width and height of Windows
console program (cmd.exe)in MS Visual C++ 2005 Express Edition?
What's more I want it to be a clean C program, without C++ objects.

There is no way to do what you ask in Standard C. You require
system-specific extensions, which you will need to ask about in
a newsgroup that specializes in your operating system.
 
J

jacob navia

Piotrek a écrit :
<<If this message is duplicated, please ignore the previous one, I had
some connection problems>>

Hi,
Could you please tell me how to check width and height of Windows
console program (cmd.exe)in MS Visual C++ 2005 Express Edition?

The goal is something like "more" command. So I print n lines of a file,
where n is number of rows, program waits for a key and prints further
part of that file, etc.

I've found description of "gettextinfo" function [void
gettextinfo(struct text_info *Info); ] in "conio.h". But this is Borland
implementation. I think there's no such function in MS C++.

What's more I want it to be a clean C program, without C++ objects.

Thank you!

You should look at the GetConsoleXXX API. For instance, a promising
start would be

BOOL GetConsoleScreenBufferInfo(
HANDLE hConsoleOutput,
PCONSOLE_SCREEN_BUFFER_INFO lpConsoleScreenBufferInfo
);

Parameters
hConsoleOutput
[in] Handle to a console screen buffer. The handle must have the
GENERIC_READ access right. For more information, see Console Buffer
Security and Access Rights.
lpConsoleScreenBufferInfo
[out] Pointer to a CONSOLE_SCREEN_BUFFER_INFO structure that receives
the console screen buffer information.
Return Values
If the function succeeds, the return value is nonzero.

If the function fails, the return value is zero. To get extended error
information, call GetLastError.

Remarks
The rectangle returned in the srWindow member of the
CONSOLE_SCREEN_BUFFER_INFO structure can be modified and then passed to
the SetConsoleWindowInfo function to scroll the console screen buffer in
the window, to change the size of the window, or both.

All coordinates returned in the CONSOLE_SCREEN_BUFFER_INFO structure are
in character-cell coordinates, where the origin (0, 0) is at the
upper-left corner of the console screen buffer.
 
W

Walter Roberson

Piotrek a écrit :
You should look at the GetConsoleXXX API. For instance, a promising
start would be
BOOL GetConsoleScreenBufferInfo(
HANDLE hConsoleOutput,
PCONSOLE_SCREEN_BUFFER_INFO lpConsoleScreenBufferInfo
);

Jacob, I must have overlooked something in the C89 or C99 standards;
could you kindly point out the sections in which
GetConsoleScreenBufferInfo() is defined? My memory must be particularily
crappy today, as I also seem to have trouble recalling the
Standard definition of BOOL, HANDLE, and PCONSOLE_SCREEN_BUFFER_INFO.
Which standard header file are those in?

The original poster expressed a particular interest in performing
this function in "clean C", and my memory can't seem to reconcile
your answer with clean C.
 
J

jacob navia

Walter Roberson a écrit :
Jacob, I must have overlooked something in the C89 or C99 standards;
could you kindly point out the sections in which
GetConsoleScreenBufferInfo() is defined? My memory must be particularily
crappy today, as I also seem to have trouble recalling the
Standard definition of BOOL, HANDLE, and PCONSOLE_SCREEN_BUFFER_INFO.
Which standard header file are those in?

The original poster expressed a particular interest in performing
this function in "clean C", and my memory can't seem to reconcile
your answer with clean C.

In the TITLE of the poster message was specified "MS VISUAL C++".

HANDLE is a windows standard for a void * in most cases. Assuming
32 bits windows we could have written:
int GetConsoleScreenBufferInfo(void *,CONSOLE_SCREEN_BUFFER_INFO *);
The CONSOLE_SCREEN_BUFFER is defined elsewhere.

This is as clean as C gets() ... :)

jacob
 
W

Walter Roberson

Walter Roberson a écrit :
In the TITLE of the poster message was specified "MS VISUAL C++".
HANDLE is a windows standard for a void * in most cases. Assuming
32 bits windows we could have written:
int GetConsoleScreenBufferInfo(void *,CONSOLE_SCREEN_BUFFER_INFO *);
The CONSOLE_SCREEN_BUFFER is defined elsewhere.

Defined elsewhere? In a different section of the C89 or C99 standards??

I seem to be having difficulty understanding your answer. A
poster came here and specifically asked for a C response, but
your reference to "32 bits windows" is sounding dangerously
like you answered in terms of a system-specific interface
without noting that the interface was system specific, and without
noting that the response was off-topic. Such responses lead
to confusion about what is part of standard C and what is
part of an OS (and not even covered by -any- official standard.)
 
M

Malcolm McLean

jacob navia said:
Piotrek a écrit :
<<If this message is duplicated, please ignore the previous one, I had
some connection problems>>

Hi,
Could you please tell me how to check width and height of Windows console
program (cmd.exe)in MS Visual C++ 2005 Express Edition?

The goal is something like "more" command. So I print n lines of a file,
where n is number of rows, program waits for a key and prints further
part of that file, etc.

I've found description of "gettextinfo" function [void gettextinfo(struct
text_info *Info); ] in "conio.h". But this is Borland implementation. I
think there's no such function in MS C++.

What's more I want it to be a clean C program, without C++ objects.

Thank you!

You should look at the GetConsoleXXX API. For instance, a promising
start would be

BOOL GetConsoleScreenBufferInfo(
HANDLE hConsoleOutput,
PCONSOLE_SCREEN_BUFFER_INFO lpConsoleScreenBufferInfo
);
I used to program DOS in the olden days. But now I really can't remember all
these sorts of details. So I wouldn't like to say whether your information
is correct or not.
That's the problem with not directing these posts to somewhere more
suitable. The other problem is that if we dealt with every library on every
platform the volume of posts would become unmanageable.
 
R

Richard Heathfield

Malcolm McLean said:
I used to program DOS in the olden days. But now I really can't
remember all these sorts of details. So I wouldn't like to say whether
your information is correct or not.

Well, it isn't a DOS answer. It's a Win32 API answer. Of course, whether
it is a correct answer for Win32 API is a matter more properly directed
to comp.os.ms-windows.programmer.win32
That's the problem with not directing these posts to somewhere more
suitable. The other problem is that if we dealt with every library on
every platform the volume of posts would become unmanageable.

Right.
 
M

Martin Ambuhl

Piotrek said:
<<If this message is duplicated, please ignore the previous one, I had
some connection problems>>

Hi,
Could you please tell me how to check width and height of Windows
console program (cmd.exe)in MS Visual C++ 2005 Express Edition?

With something that is specific to that implementation and that
operating system, and that is completely off-topic in comp.lang.c.
There are almost as many newsgroups for Windows and MSVC as there are
instances of bloat in Windows. Why would you not ask there, where the
experts in that platform live?
The goal is something like "more" command. So I print n lines of a file,
where n is number of rows, program waits for a key and prints further
part of that file, etc.

I've found description of "gettextinfo" function [void
gettextinfo(struct text_info *Info); ] in "conio.h". But this is Borland
implementation. I think there's no such function in MS C++.

There are no such things as "gettextinfo" "struct text_info", or
"conio.h" in C or C++. If there were, you would not be needed to ask
about specific implementations. Since you _are_ asking about a specific
implementation, it makes sense to ask in a newsgroup for that
implementation.
 
R

Richard

Martin Ambuhl said:
Piotrek said:
<<If this message is duplicated, please ignore the previous one, I
had some connection problems>>

Hi,
Could you please tell me how to check width and height of Windows
console program (cmd.exe)in MS Visual C++ 2005 Express Edition?

With something that is specific to that implementation and that
operating system, and that is completely off-topic in
comp.lang.c. There are almost as many newsgroups for Windows and MSVC
as there are instances of bloat in Windows. Why would you not ask
there, where the experts in that platform live?
The goal is something like "more" command. So I print n lines of a
file, where n is number of rows, program waits for a key and prints
further part of that file, etc.

I've found description of "gettextinfo" function [void
gettextinfo(struct text_info *Info); ] in "conio.h". But this is
Borland implementation. I think there's no such function in MS C++.

There are no such things as "gettextinfo" "struct text_info", or
"conio.h" in C or C++. If there were, you would not be needed to ask
about specific implementations. Since you _are_ asking about a
specific implementation, it makes sense to ask in a newsgroup for that
implementation.

How many ways do you need to say "off topic"? Kicking a man when he is
down is considered pretty "off topic" in civilised circles.
 
R

Richard

There is no way to do what you ask in Standard C. You require
system-specific extensions, which you will need to ask about in
a newsgroup that specializes in your operating system.

You felt the need to post 3 replies in this thread. All saying the same
thing. When it had already been done by another poster. Well done for
wasting everyones time.
 
K

Keith Thompson

jacob navia said:
Walter Roberson a écrit :
Jacob, I must have overlooked something in the C89 or C99 standards;
could you kindly point out the sections in which
GetConsoleScreenBufferInfo() is defined?
[...]
In the TITLE of the poster message was specified "MS VISUAL C++".
[...]

The "Newsgroups": header says "comp.lang.c". As you know perfectly
well, the OP's question cannot be completely answered in the context
of this newsgroup. Providing system-specific details here, where they
cannot necessarily be checked by other participants, clutters this
newsgroup and is a disservice to the original poster.

I suspect that comp.os.ms-windows.programmer.win32 is full of people
who know all about this stuff. Why did you not bother to mention that
newsgroup in your response? (One might suspect that you're trying to
show off your knowledge of Windows programming in a forum with minimal
competition.)
 
K

Keith Thompson

Piotrek said:
Could you please tell me how to check width and height of Windows
console program (cmd.exe)in MS Visual C++ 2005 Express Edition?
[...]

Sorry, we can't. Standard C, which is what we discuss here, has no
facilities for this kind of thing.

Section 19 of the comp.lang.c FAQ, <http://www.c-faq.com/>, might be
helpful, particularly question 19.4, though the information there
seems to be mostly specific to Unix and, to a lesser extent, MS-DOS
(it's fairly old).

You can probably get better information in
comp.os.ms-windows.programmer.win32. If that's not the correct forum,
they can probably direct you to a better one Before posting there, see
if you can find a FAQ list for that newsgroup; your question may
already have been answered.
 
W

Walter Roberson

(e-mail address removed)-cnrc.gc.ca (Walter Roberson) writes:
You felt the need to post 3 replies in this thread. All saying the same
thing. When it had already been done by another poster. Well done for
wasting everyones time.

You should check out the timestamps before making such a claim.
My posting that you were replying to as if it were a duplication of
effort, was in fact the first reply, approximately 10 minutes before
Jacob's reply.
Well done for wasting everyones time.

You could always put me in your kill file if you find my
contributions unsatisfactory.
 
R

Richard Heathfield

Richard said:
You made your point.

But isn't there a "std" C group too where you would be better off
lecturing repeatedly?

comp.std.c is for discussions about the document that defines the C
language. It's all about defect reports, clarifications of wording, the
mythical C0x revision, and so on.

comp.lang.c, on the other hand, is for discussions about the C language.

Windows programming is adequately covered by
comp.os.ms-windows.programmer.win32
 
K

Keith Thompson

Richard said:
You made your point.

But isn't there a "std" C group too where you would be better off
lecturing repeatedly?
[...]

No. comp.std.c is for discussion of the C standard; comp.lang.c is
for discussion of the language defined by that standard (and earlier
incarnations of it). OS-specific details are off-topic in either
group.
 
J

jacob navia

Richard Heathfield a écrit :
comp.lang.c, on the other hand, is for discussions about the C language.

This is just your opinion.
This group has no chart.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top