Results 1 to 10 of 10

Thread: Handle from AllocConsole

  1. #1

    Thread Starter
    Junior Member
    Join Date
    May 2001
    Posts
    19

    Handle from AllocConsole

    I need to recieve the windowhandle for my window created with the api AllocConsole. You know how?

    regards,
    Cyth

  2. #2
    Fanatic Member
    Join Date
    May 2001
    Posts
    837
    Code:
    hConsole = AllocConsole
    i guess thats it, unless you mean something different

  3. #3

    Thread Starter
    Junior Member
    Join Date
    May 2001
    Posts
    19
    Can't the windowhandle change during runtime? Are you really sure that's th window handle?

    /Cyth

  4. #4
    Fanatic Member
    Join Date
    May 2001
    Posts
    837
    A window handle stays constant for as long as that window exists

  5. #5

    Thread Starter
    Junior Member
    Join Date
    May 2001
    Posts
    19
    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

  6. #6
    Fanatic Member
    Join Date
    May 2001
    Posts
    837
    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

  7. #7

    Thread Starter
    Junior Member
    Join Date
    May 2001
    Posts
    19
    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

  8. #8
    Frenzied Member Vlatko's Avatar
    Join Date
    Aug 2000
    Location
    Skopje, Macedonia
    Posts
    1,409
    It doesen't seem to me that AllocCOnsole returns the handle:
    Code:
    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).
    I am become death, the destroyer of worlds.
    mail:[email protected]

    • Visual Basic 6.0 & .NET
    • Visual C++ 6.0 & .NET
    • ASP
    • LISP
    • PROLOG
    • C
    • Pascal

  9. #9
    Frenzied Member Vlatko's Avatar
    Join Date
    Aug 2000
    Location
    Skopje, Macedonia
    Posts
    1,409
    Try the GetStdHandle API:
    Code:
    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.
    I am become death, the destroyer of worlds.
    mail:[email protected]

    • Visual Basic 6.0 & .NET
    • Visual C++ 6.0 & .NET
    • ASP
    • LISP
    • PROLOG
    • C
    • Pascal

  10. #10

    Thread Starter
    Junior Member
    Join Date
    May 2001
    Posts
    19
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width