-
Win32-Console-Application
Hi!
I have a question about Win32-Console-Applications.
If I use 'cout' for example to write a string to screen
it appears always in upper-left of the console.
/------------------------------------------\
|O ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ _ O X|
|------------------------------------------|
|The text appears here! |
| |
| |
| |
| |
| |
\------------------------------------------/
But my question is: How can I output text for
example:
/------------------------------------------\
|O ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ _ O X|
|------------------------------------------|
| |
| |
| |
| HERE! |
| |
| |
\------------------------------------------/
...or somewere else on the screen.
Thanks for helpin' me!
-
Re: Win32-Console-Application
Michael,
I think that functions to move cursor to a specific screen position
are not part of Standard C/C++ Library.
However, as you are using the Windows Environment you can one of the
several Win32 Console Api Library functions. One interesting one is WriteConsoleOutputCharacter,
which has the following signature:
BOOL WriteConsoleOutputCharacter(
HANDLE hConsoleOutput, // handle to a console screen buffer
LPCTSTR lpCharacter, // pointer to buffer to write characters
// from
DWORD nLength, // number of character cells to write to
COORD dwWriteCoord, // coordinates of first cell to write to
LPDWORD lpNumberOfCharsWritten
// pointer to number of cells written to
);
the following snippet shows how the functions works:
#include <windows.h>
#include <tchar.h>
void main()
{
DWORD dwCharsWritten;
COORD coord = {20, 10};// tells where you want to output the string
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
static TCHAR *szMessage = "Hello World";
WriteConsoleOutputCharacter(hConsole,
szMessage,
_tcslen(szMessage),
coord,
&dwCharsWritten);
}
Look at msdn.microsoft.com/library for more help about Win32 Console Api.
Note: this code only works on the windows platform. If you intend to use
Unix/Linux, take a look at ncurses library.
I hope this helps.
Luis Araujo
"Michael" <MichaelBuesch@yahoo.de> wrote:
>
>Hi!
>I have a question about Win32-Console-Applications.
>
>If I use 'cout' for example to write a string to screen
>it appears always in upper-left of the console.
>
>/------------------------------------------\
>|O ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ _ O X|
>|------------------------------------------|
>|The text appears here! |
>| |
>| |
>| |
>| |
>| |
>\------------------------------------------/
>
>
>But my question is: How can I output text for
> example:
>
>/------------------------------------------\
>|O ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ _ O X|
>|------------------------------------------|
>| |
>| |
>| |
>| HERE! |
>| |
>| |
>\------------------------------------------/
>...or somewere else on the screen.
>
>Thanks for helpin' me!
-
Re: Win32-Console-Application
with some effort, you can make cout place the output on a desired screen
position. Look at the setw() function (which sets the width, or total
number of characters a variable occupies on the screen, including
leading or trailing blanks). To lower the output, use cout<<endl;. This
will lower the output by one line at a time. Of course you can use
non-standard graphic libraries such as <conio.h> and <graphics.h> but
they don'y work well with cout.
Danny
Michael wrote:
>
> Hi!
> I have a question about Win32-Console-Applications.
>
> If I use 'cout' for example to write a string to screen
> it appears always in upper-left of the console.
>
> /------------------------------------------\
> |O ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ _ O X|
> |------------------------------------------|
> |The text appears here! |
> | |
> | |
> | |
> | |
> | |
> \------------------------------------------/
>
> But my question is: How can I output text for
> example:
>
> /------------------------------------------\
> |O ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ _ O X|
> |------------------------------------------|
> | |
> | |
> | |
> | HERE! |
> | |
> | |
> \------------------------------------------/
> ..or somewere else on the screen.
>
> Thanks for helpin' me!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Development Centers
-- Android Development Center
-- Cloud Development Project Center
-- HTML5 Development Center
-- Windows Mobile Development Center
|