News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Obtaining the handle of a console window

Started by Vortex, March 08, 2009, 12:40:51 PM

Previous topic - Next topic

Vortex

Based on this MS article, I coded a function to retrieve the handle of a console window :


; Reference :
; How To Obtain a Console Window Handle (HWND)
; http://support.microsoft.com/kb/124103

include GetConsHandle.inc

BUFFER_SIZE = 256

.data

TitleFormat1  db '%d-%d',0

.code

GetConsHandle PROC USES esi

LOCAL szConsTitle[BUFFER_SIZE]:BYTE
LOCAL buffer[BUFFER_SIZE]:BYTE

    lea     esi,[buffer]
    invoke  GetConsoleTitle,ADDR szConsTitle,BUFFER_SIZE

    invoke  GetCurrentProcessId
    push    eax
    invoke  GetTickCount
    push    eax
    push    OFFSET TitleFormat1
    push    esi
    call    wsprintf
    add     esp,4*4

    invoke  SetConsoleTitle,esi
    invoke  Sleep,50
    invoke  FindWindow,0,esi
    mov     esi,eax
   
    invoke  SetConsoleTitle,ADDR szConsTitle
    mov     eax,esi
    ret

GetConsHandle ENDP

END

[attachment deleted by admin]

Vortex

Windows 2000 and the successor operating systems are providing the GetConsoleWindow API function to obtain the console window handle.