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

Recommended Answers

All 7 Replies

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.

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.

commented: Yes! +17

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.