One of those really stupid questions... (C++)
One of those really stupid questions... (C++)
I need to print a char at a specific position in the console windows, obiously it is possible, but eludes me.
i would like a function like:
draw(x, y, char);
anyone?
i would like a function like:
draw(x, y, char);
anyone?
- AndrewAPrice
- Member
- Posts: 2299
- Joined: Mon Jun 05, 2006 11:00 pm
- Location: USA (and Australia)
Re: One of those really stupid questions... (C++)
Use the console code from Brendon's kernel tutorial from osdevver.net.Zacariaz wrote:I need to print a char at a specific position in the console windows, obiously it is possible, but eludes me.
i would like a function like:
draw(x, y, char);
anyone?
My OS is Perception.
ok, maybe i did find the tutorial after all, but i really dont care to read like a billion line of code that i dont understand just to get this little snippet.
Thank you for your help, but this is definently not usefull. If you can point me to were i should look, then maybe, but otherwise.
And just to make clear, this has nothing to do with osdeving.
as a little non important side thing i allso need to disable the cursor, thingy, stop the screen from scroling and stuff, maybe there is a tutorial somewhere that has to do with all these thing? I havent been able to find one my self.
Thank you for your help, but this is definently not usefull. If you can point me to were i should look, then maybe, but otherwise.
And just to make clear, this has nothing to do with osdeving.
as a little non important side thing i allso need to disable the cursor, thingy, stop the screen from scroling and stuff, maybe there is a tutorial somewhere that has to do with all these thing? I havent been able to find one my self.
C++, as far as the language itself is concerned, does not have such a function. It is a system language, like C, and just like C its standard library covers only the essentials of data handling, and little else - which is left to third-party libraries.
I know this is confusing for people coming from Java or .NET, where there is a "standard library" that is good for everything and your kitchen sink, but those are a different breed of languages. (And while my Java is a mite rusty, I'd daresay you don't have console-positioning in Java, either.)
But of course there are libraries available for the C++ programmer that do what you intend to do. For Unix-alike systems, the "default" choice is ncurses. Don't ask me about pointers to Windows console programming resources, that's sick.
I know this is confusing for people coming from Java or .NET, where there is a "standard library" that is good for everything and your kitchen sink, but those are a different breed of languages. (And while my Java is a mite rusty, I'd daresay you don't have console-positioning in Java, either.)
But of course there are libraries available for the C++ programmer that do what you intend to do. For Unix-alike systems, the "default" choice is ncurses. Don't ask me about pointers to Windows console programming resources, that's sick.
Every good solution is obvious once you've found it.
- AndrewAPrice
- Member
- Posts: 2299
- Joined: Mon Jun 05, 2006 11:00 pm
- Location: USA (and Australia)
Does he mean std::cout? I know there are Windows specific functions (like changing colour, setting position, setting the title) in the Windows SDK.
My OS is Perception.
- Brynet-Inc
- Member
- Posts: 2426
- Joined: Tue Oct 17, 2006 9:29 pm
- Libera.chat IRC: brynet
- Location: Canada
- Contact:
For such "interactive" console applications, I use BSD curses or ncurses..
I heard that Windows users (Among others..) can use pdcurses, but I don't think it supports everything though..
The sourceforge projects summary states: "An implementation of the curses library for Win32, DOS, OS/2, X11 and SDL."
So have fun ... (The ability to port old curses applications to SDL/X11 sounds appealing..)
I heard that Windows users (Among others..) can use pdcurses, but I don't think it supports everything though..
The sourceforge projects summary states: "An implementation of the curses library for Win32, DOS, OS/2, X11 and SDL."
So have fun ... (The ability to port old curses applications to SDL/X11 sounds appealing..)
Nope.Zacariaz wrote:I am using windows yes.
about std::cout im sure yiou can modify color and stuff...
Well, maybe you can squeeze ANSI sequences through cout which happen to be interpreted as color codes by the console driver, but that's not the droid you're looking for.
That's what I said: C++ doesn't offer this in the standard language proper, you need third-party libraries for that. Use one of the pointers given already, or google for "console library Windows" or somesuch to find out what's available that suits your needs., but as for possition... ? i doubt it.
Every good solution is obvious once you've found it.
Code: Select all
#include <windows.h>
int main(){
HANDLE console_handle;
COORD cursor_coord;
char *buffer = "X\n";
DWORD actual = 0;
cursor_coord.X=(40-(strlen(buffer)/2));
cursor_coord.Y=10;
console_handle = GetStdHandle(STD_OUTPUT_HANDLE);
if(SetConsoleCursorPosition(console_handle, cursor_coord)){
WriteConsole(console_handle, buffer, strlen(buffer), &actual, NULL);
}
system("pause");
return 0;
}