PDA

Click to See Complete Forum and Search --> : Handle from AllocConsole


Cyth
May 29th, 2001, 06:41 PM
I need to recieve the windowhandle for my window created with the api AllocConsole. You know how?

regards,
Cyth

DNA7433
May 29th, 2001, 06:54 PM
hConsole = AllocConsole


i guess thats it, unless you mean something different

Cyth
May 29th, 2001, 07:59 PM
Can't the windowhandle change during runtime? Are you really sure that's th window handle?

/Cyth

DNA7433
May 29th, 2001, 08:04 PM
A window handle stays constant for as long as that window exists

Cyth
May 29th, 2001, 08:07 PM
A guy who's really good and experienced in vb and program developing claimed that the handle actually could change. But if you are really sure..

Now I only need to confirm if AllocConsole returns a windowhandle and not something else.

regards,
Cyth

DNA7433
May 29th, 2001, 08:12 PM
Can a window change its handle? Can a window take another window's handle?

Once a window is opened it will keep the same handle until it is closed. It is possible that if a window is closed, and another window is opened, that the new window will have the same handle as the old one. It is unlikely, but it is possible. It isn't possible for a new application to take the window handle assigned to window that is still open.

-http://www.mods.com.au/FAQ/faqs/winhandlechange.htm


As i said before, a window handle does not change, there is no logical reason for it to change. and that function does return a handle and nothing else

Cyth
May 30th, 2001, 07:21 AM
Thanks, DNA7433

Since I got a clear answer from that other guy declaring exactly the opposite you're saying I had to be really sure.

cheers,
Cyth

Vlatko
May 30th, 2001, 07:37 AM
It doesen't seem to me that AllocCOnsole returns the handle:

AllocConsole
The AllocConsole function allocates a new console for the calling process.

BOOL AllocConsole(VOID)

Parameters
This function has no parameters.

Return Values
If the function succeeds, the return value is nonzero.

If the function fails, the return value is zero. To get extended error information, call GetLastError.


Remarks
A process can be associated with only one console, so the AllocConsole function fails if the calling process already has a console. A process can use the FreeConsole function to detach itself from its current console, and then it can call AllocConsole to create a new console. If the calling process creates a child process, the child inherits the new console.

AllocConsole also sets up standard input, standard output, and standard error handles for the new console. The standard input handle is a handle to the console's input buffer, and the standard output and standard error handles are handles to the console's screen buffer. To retrieve these handles, use the GetStdHandle function.

This function is primarily used by graphics applications to create a console window. Graphics applications are initialized without a console. Console applications are normally initialized with a console, unless they are created as detached processes (by calling the CreateProcess function with the DETACHED_PROCESS flag).

Vlatko
May 30th, 2001, 07:39 AM
Try the GetStdHandle API:

GetStdHandle
The GetStdHandle function returns a handle for the standard input, standard output, or standard error device.

HANDLE GetStdHandle(
DWORD nStdHandle // input, output, or error device
);

Parameters
nStdHandle
Specifies the device for which to return the handle. This parameter can have one of the following values: Value Meaning
STD_INPUT_HANDLE Standard input handle
STD_OUTPUT_HANDLE Standard output handle
STD_ERROR_HANDLE Standard error handle


Return Values
If the function succeeds, the return value is a handle to the specified device.

If the function fails, the return value is the INVALID_HANDLE_VALUE flag. To get extended error information, call GetLastError.

Cyth
May 30th, 2001, 07:46 AM
Yupp, on my computer it returns 1 every time. It succeeded. It's not a handle. Note that I already got the input, output and error handles I want the windowhandle so I can modify it with setwindowrect and such api's.

When I say windowhandle I mean the value corresponding to ie me.hWnd but for the console.

Thanks,
Cyth