Hey,guys
I want to print a word in the center of a CMD's window

If I can get the size of it,I could calculate the position where I put the word.

Anybody who can help me?

Much Thanks

Assuming this is a console program on MS-Windows operating system.
1. call GetComnsoleWindow() to get the HWND of the window

2. call GetWindowRect() to get the RECT structure that contains the window's size.

Hey,thank you.
But I am not very familiar with Windows API

Could you show me how to implement it ?
Perhaps I need detailed code

Well, its only the two functions I posted. I gave you the links, just read them to see how they are called. Yes I could easily write the code for you, but you will learn a lot more if you read and study those links yourself. Just include windows.h header file.

Edited 5 Years Ago by Ancient Dragon: n/a

Comments
Yes!

Well, its only the two functions I posted. I gave you the links, just read them to see how they are called. Yes I could easily write the code for you, but you will learn a lot more if you read and study those links yourself. Just include windows.h header file.

Well,thanks for your help.
I did have read the MSDN.
But as I said, I know nothing about API.

I tried to define a variable hWnd whose type is HWND

Then I make hWnd equal to the return of GetConsoleWindow()
However , it fails.
I wonder why?

Because, obviously, you did it wrong. Don't you think that showing us what you tried to do would give us some helpful information? This is not the Psychic Programmer's Forum.

This isn't rocket science either. As Walt said you need to post what you did -- the complete program.

>>However , it fails.
What fails? Compiler gives you errors? Or GetConsoleWindow() fails to return a valid HWND pointer?

Also tell us the compiler you are using.

Note that you have to #define _WIN32_WINNT 0x0500 before
including windows.h in order to be able to use GetConsoleWindow.
It says so in the remarks section of the relevant link posted above.

This article has been dead for over six months. Start a new discussion instead.