News:

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

textout...and things...

Started by sixleafclover, February 04, 2006, 01:57:17 AM

Previous topic - Next topic

sixleafclover

Ok i couldnt find any tutorials on this and i did search forum before posting such a silly lil post. I wanted to overlay text onto desktop, like a program i saw, so i tried this. but its confusing me. Its late and i just need some pointers(handy pointers, not programmery pointers) pretty please? the code crashes, but i spose apart from that it works. Also if ppl could help with how to change size/color/style of text. and also if its possible to do it transparently instead of on white? Sorry about such a huge question. Just dont know where to look for info on this sorta thing.


<blahblah includes etc>

.data

buff      db "Hello", 0


.data?
font      LOGFONT <>
deskdc dd ?

.code

start:

    invoke GetDC,0
    mov deskdc,eax
    invoke lstrlen,ADDR buff
    invoke TextOut,deskdc,100,200,OFFSET buff,eax
    invoke ReleaseDC,0,deskdc

end start



zooba

I don't think you should be releasing the desktop window device context.

MichaelW

#2
sixleafclover,

With a call to ExitProcess at the end, the code that you posted should work OK. For the other stuff, it's mostly a matter of setting up and calling the necessary API functions.

; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
    include \masm32\include\masm32rt.inc
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
    .data
      hDC           dd 0
      hFont         dd 0
      hFontDefault  dd 0
      buffer        db "Hello World",0
    .code
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
start:
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««

    invoke GetDC, 0
    mov   hDC, eax

    call  CreateLogicalFont           ; local procedure
    mov   hFont, eax

    invoke SelectObject, hDC, hFont
    mov   hFontDefault, eax

    ;RGB   255, 0, 0                  ; MASM32 macro
    invoke ColorDialog, 0, 0, 0       ; MASM32 procedure
    invoke SetTextColor, hDC, eax

    invoke SetBkMode, hDC, TRANSPARENT

    invoke lstrlen, ADDR buffer
    invoke TextOut, hDC, 0, 0, ADDR buffer, eax

    invoke SelectObject, hDC, hFontDefault
    invoke ReleaseDC, 0, hDC
    invoke DeleteObject, hFont

    ; This only for a console application.
    ;inkey "Press any key to exit..."

    exit

; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««

CreateLogicalFont proc

    LOCAL cf:   CHOOSEFONT
    LOCAL lf:   LOGFONT
    LOCAL hfont:DWORD

    mov   cf.lStructSize, SIZEOF(CHOOSEFONT)
    mov   cf.hwndOwner, NULL
    mov   cf.hDC, NULL
    lea   eax, lf
    mov   cf.lpLogFont, eax
    mov   cf.iPointSize, 0
    mov   cf.Flags, CF_SCREENFONTS or CF_EFFECTS

    RGB   0, 0, 0                     ; MASM32 macro
    mov   cf.rgbColors, eax

    mov   cf.lCustData, 0
    mov   cf.lpfnHook, NULL
    mov   cf.lpTemplateName, NULL
    mov   cf.hInstance, NULL
    mov   cf.lpszStyle, NULL
    mov   cf.nFontType, SCREEN_FONTTYPE
    mov   cf.nSizeMin, 0
    mov   cf.nSizeMax, 0
     
    invoke ChooseFont, ADDR cf

    invoke CreateFontIndirect, cf.lpLogFont

    ret

CreateLogicalFont endp

; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««

end start


http://msdn.microsoft.com/default.aspx

zooba,

That was how it seemed to me at first, but per the ReleaseDC documentation:
Quote
The application must call the ReleaseDC function for each call to the GetWindowDC function and for each call to the GetDC function that retrieves a common DC.
eschew obfuscation

sixleafclover

ahahahahaha, thats how tired i was last night. exitprocess. good move. thanks! :clap: Oh and thanks for all the handy stuff too. wow and i didnt get flamed for asking a dumb question. huzzah!!

Mincho Georgiev

QuoteI wanted to overlay text onto desktop
It smells like hook to me, that's why i'm showing you only how to do it on every top windows including the desktop window whitout hooking:



[attachment deleted by admin]