[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.c

Getting console window's hWnd

Quentin Pope

8/13/2011 8:41:00 PM

Hello

I am writing a console app for Windows (running on Vista 32 bit at
present)

I would like to be able to resize the DOS window the program is running
in, from within my code

For this I would need to get that window's hWnd

Can anyone advise how to do this?

Many Thanks.
16 Answers

Ben Bacarisse

8/13/2011 9:19:00 PM

0

Quentin Pope <qp19433@hotmail.NOSPAM.com> writes:

> I am writing a console app for Windows (running on Vista 32 bit at
> present)
>
> I would like to be able to resize the DOS window the program is running
> in, from within my code
>
> For this I would need to get that window's hWnd
>
> Can anyone advise how to do this?

People in a Windows group are a good bet. I think

comp.os.ms-windows.programmer.win32
comp.os.msdos.programmer

might be worth a try, but do some work first. I searched for "console
window handle" and the top result looked perfectly acceptable.

--
Ben.

Bartc

8/13/2011 9:44:00 PM

0



"Quentin Pope" <qp19433@hotmail.NOSPAM.com> wrote in message
news:j26ngo$v68$1@speranza.aioe.org...

> I would like to be able to resize the DOS window the program is running
> in, from within my code
>
> For this I would need to get that window's hWnd
>
> Can anyone advise how to do this?

You need MSDN, perhaps start here:

http://msdn.microsoft.com/en-us/librar...(v=VS.85).aspx

or search for msdn console.

I think I once used something like GetStdHandle(STD_OUTPUT_HANDLE).

--
Bartc

Dave \Crash\ Dummy

8/14/2011 1:43:00 AM

0


"BartC" <bc@freeuk.com> schrieb im Newsbeitrag
news:j26r8b$oad$1@dont-email.me...
....
> I think I once used something like GetStdHandle(STD_OUTPUT_HANDLE).
....
yep.
I agree.
But I am not expirienced in Win64.

Geoff

8/14/2011 2:24:00 AM

0

On Sat, 13 Aug 2011 20:40:56 +0000 (UTC), Quentin Pope
<qp19433@hotmail.NOSPAM.com> wrote:

>Hello
>
>I am writing a console app for Windows (running on Vista 32 bit at
>present)
>
>I would like to be able to resize the DOS window the program is running
>in, from within my code
>
>For this I would need to get that window's hWnd
>
>Can anyone advise how to do this?
>
>Many Thanks.

A Windows console app doesn't have an hWnd as such, you can't call the
Windows API functions to resize the window and you don't have a
message pump to receive resize messages if the user resizes you.

Others have already sent you to the console API reference. The handles
to your console will be available via GetStdHandle, the screen buffer
info via GetConsoleScreenBufferInfo and you also need to set a console
control handler via SetConsoleCtrlHandler.

For more detail you should look at the Microsoft forums or windows
programming newsgroups.

jacob navia

8/14/2011 8:03:00 AM

0

Le 13/08/11 22:40, Quentin Pope a écrit :
> Hello
>
> I am writing a console app for Windows (running on Vista 32 bit at
> present)
>
> I would like to be able to resize the DOS window the program is running
> in, from within my code
>
> For this I would need to get that window's hWnd
>
> Can anyone advise how to do this?
>
> Many Thanks.

1) Find the title of the console
2) Findthe window with that title

#include <windows.h>

int main()
{
char title[500]; // to hold title
HWND hwnd;

GetConsoleTitle( title, 500 );
hwnd = FindWindow( NULL, title );
printf("The hwnd of the console is: %p\n",hwnd);
}

This supposes that the title of the console is less than 500 chars

Harald van D?k

8/14/2011 8:24:00 AM

0

On Aug 14, 10:03 am, jacob navia <ja...@spamsink.net> wrote:
> [...]
>    GetConsoleTitle( title, 500 );
>    hwnd = FindWindow( NULL, title );
> [...]
> This supposes that the title of the console is less than 500 chars

And this supposes that the console title uniquely identifies the
window. Haven't you ever started two instances of the same application?

Geoff

8/14/2011 8:48:00 AM

0

On Sun, 14 Aug 2011 10:03:00 +0200, jacob navia <jacob@spamsink.net>
wrote:

>Le 13/08/11 22:40, Quentin Pope a écrit :
>> Hello
>>
>> I am writing a console app for Windows (running on Vista 32 bit at
>> present)
>>
>> I would like to be able to resize the DOS window the program is running
>> in, from within my code
>>
>> For this I would need to get that window's hWnd
>>
>> Can anyone advise how to do this?
>>
>> Many Thanks.
>
>1) Find the title of the console
>2) Findthe window with that title
>
>#include <windows.h>
>
>int main()
>{
> char title[500]; // to hold title
> HWND hwnd;
>
> GetConsoleTitle( title, 500 );
> hwnd = FindWindow( NULL, title );
> printf("The hwnd of the console is: %p\n",hwnd);
>}
>
>This supposes that the title of the console is less than 500 chars

It also supposes that the window title is unique.

jacob navia

8/14/2011 9:13:00 AM

0

Le 14/08/11 10:24, Harald van Dijk a écrit :
> On Aug 14, 10:03 am, jacob navia<ja...@spamsink.net> wrote:
>> [...]
>> GetConsoleTitle( title, 500 );
>> hwnd = FindWindow( NULL, title );
>> [...]
>> This supposes that the title of the console is less than 500 chars
>
> And this supposes that the console title uniquely identifies the
> window. Haven't you ever started two instances of the same application?

If you need more sphistication use EnumWindows directly. Then you
will find ALL windows with the given name.

In this example I wanted to keep this simple. Actually FindWindow
calls indirectly EnumWindows.

Harald van D?k

8/14/2011 9:37:00 AM

0

On Aug 14, 11:13 am, jacob navia <ja...@spamsink.net> wrote:
> Le 14/08/11 10:24, Harald van D?k a écrit :
> > On Aug 14, 10:03 am, jacob navia<ja...@spamsink.net>  wrote:
> >> [...]
> >>     GetConsoleTitle( title, 500 );
> >>     hwnd = FindWindow( NULL, title );
> >> [...]
> >> This supposes that the title of the console is less than 500 chars
>
> > And this supposes that the console title uniquely identifies the
> > window. Haven't you ever started two instances of the same application?
>
> If you need more sphistication use EnumWindows directly. Then you
> will find ALL windows with the given name.

In which case you don't know which one's yours, so it is unsuitable
for resizing the window. Take BartC's post, follow the link to MSDN,
and you will see that there is a more direct way of getting the window
handle. Which still doesn't really do anything useful for you, but
that's for other reasons :)

robertwessel2@yahoo.com

8/14/2011 10:14:00 AM

0

On Sun, 14 Aug 2011 11:13:20 +0200, jacob navia <jacob@spamsink.net>
wrote:

>Le 14/08/11 10:24, Harald van D?k a écrit :
>> On Aug 14, 10:03 am, jacob navia<ja...@spamsink.net> wrote:
>>> [...]
>>> GetConsoleTitle( title, 500 );
>>> hwnd = FindWindow( NULL, title );
>>> [...]
>>> This supposes that the title of the console is less than 500 chars
>>
>> And this supposes that the console title uniquely identifies the
>> window. Haven't you ever started two instances of the same application?
>
>If you need more sphistication use EnumWindows directly. Then you
>will find ALL windows with the given name.
>
>In this example I wanted to keep this simple. Actually FindWindow
>calls indirectly EnumWindows.


Which doesn't address the problem - which of (potentially) multiple
windows with the same name is the console window for the current
application. GetConsoleWindow() is likely more appropriate.