Consol hWnd

Started by
5 comments, last by EvilCrap 22 years, 5 months ago
in mvc++, when u make a win32 consol program, this is really wrapped up by MVC, the things such as winmain and stuff, right? how do i get the hwnd of the consol? thanks. also, anyone know a website detailing the workings of all of the consol api? i have msdn, but they it doesnt really explain how they functions relate to each other. when i change the xy pos, and cout, then change it again and cout, and then flush, both couts appear at the most recent place. why is this, and is there a way to fix it without having to flush after each xypos change? sorry i jus realized this is the wrong forum Edited by - evilcrap on November 14, 2001 1:10:31 PM
Advertisement
Acutally, there is no WinMain in console mode. It''s back to good old main. Use SetConsoleCursorPosition to change the cursor position on the console. Look up that function under your MSDN, there will be a link at the bottom of the page that will lead to a list of other console functions. What were you using to change cursor position that didn''t work? I don''t know of a way to grab the hwnd of a console, but you can get the module handle with a call to GetModuleHandle.
You are mistaken in assuming that the Win32 console is tied to the "console" functions like cout and cin. cout and cin read from and write to standard input and standard output respectively. When you create a Win32 Console Application project, stdout and stdin are redirected to your own console.

You can get the handle of this console window that has been created for you by calling GetStdHandle(STD_OUTPUT_HANDLE). If you want to output text at arbitrary positions, use WriteConsoleOutput() or WriteConsoleOutputCharacter().

As for MSDN not explaining how the functions relate to each other, that''s not true. MSDN has very complete Win32 API documentation (IMO the best), but few people know how and where to look. If you type in the name of a console function in the Index panel and bring up that page, at the bottom you''ll find links to related topics (in this case you''ll see "Console Functions" among other things). You can also click the "Locate in Contents" button to show you which book/article/collection the document you''re looking at is in; you''ll often find related material in the same section. Finally there''s the Search, but you have to know how to use it properly. Typing generic strings like "Console functions" might not help you at all (which is why you should first use the Index to obtain some keywords).
quote:Original post by EvilCrap
in mvc++,
when u make a win32 consol program, this is really wrapped up by MVC, the things such as winmain and stuff, right?

Actually, it''s the other way around: main() wraps WinMain(). main() is the defined entry point for all C/C++ applications, so under Windows there is a defined main() which sets up some stuff and then calls your WinMain() function (which you must define.)
goto www.GameTutorials.com they have a good Tutorial on this in the intermediate section. i think you have to set a handle to the input and output buffers. First name the handle variable like this HANDLE hinput, houtput then do this hinput = GetStdHandle (STD_INPUT_HANDLE)im not really that sure about this at the moment because im only a newbie and im not really at this stage of programming at the moment. good luck .
quote:Original post by Oluseyi
As for MSDN not explaining how the functions relate to each other, that''s not true. MSDN has very complete Win32 API documentation (IMO the best), but few people know how and where to look.

This would make sense, since Windows is made by Microsoft!
I think most people are either daunted by MSDN, or think Microsoft is too "evil" to be trusted (so they''d rather find unofficial versions of the same information from some random 15-yr-old with a website).
Personally, I think Microsoft is evil too. But, I''m not going to let that stop me from having THEM explain how to use their software.
quote:Original post by Oluseyi

Actually, it''s the other way around: main() wraps WinMain(). main() is the defined entry point for all C/C++ applications, so under Windows there is a defined main() which sets up some stuff and then calls your WinMain() function (which you must define.)

Not really so. Windowed applications simply doesnt have a main at all. The PE loader calls mainCRTStartup or WinMainCRTStartup depending on whether it is a console mode or a windowed mode app(Incidentally, the source for these two functions are almost identical, with a couple of #ifdef''s scattered around).
This function then sets up the runtime, and calls either main or WinMain as appropriate, with the desired arguments.
The C++ standard does not explicitly require a main either:
quote:C++ Draft 3.6.1.1
A program shall contain a global function called main, which is the designated start of the program. It is
implementationdefined
whether a program in a freestanding environment is required to define a main
function.



"I contend that we are both atheists. I just believe in one fewer god than you do. When you understand why you dismiss all the other possible gods, you will understand why I dismiss yours." - - Stephen Roberts
--AnkhSVN - A Visual Studio .NET Addin for the Subversion version control system.[Project site] [IRC channel] [Blog]

This topic is closed to new replies.

Advertisement