News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

Draw Text with Button To show & Remove

Started by hfheatherfox07, August 18, 2012, 05:20:11 PM

Previous topic - Next topic

hfheatherfox07

Hi
I am Trying To draw Text with show text and Remove Text Buttons ...I am using a thread instead of invoking the proc and no timer

It is not working  :( any ideas ?

Thank you!
Your code and your skills will be assimilated. Your programming language is irrelevant.
We are the ASM Borg and you will become part of us. Compile and be assembled.

hfheatherfox07

#1
ARG!!!!

What is the handle of the drawn text ???
I thought of drawing it out than use "INVOKE ShowWindow ,hText,SW_HIDE"
and toggle between show and hide Buttons

EDIT:
I am trying to draw this without a static!!! how do I go about doing it this way?
Your code and your skills will be assimilated. Your programming language is irrelevant.
We are the ASM Borg and you will become part of us. Compile and be assembled.

MichaelW

I can't see any point to using a timer or a thread, so I created a simple MASM32 In Memory dialog example that draws text on the client are of the dialog window.

;==============================================================================
    include \masm32\include\masm32rt.inc
;==============================================================================

IDC_SHOW equ 1000
IDC_HIDE equ 1001

;==============================================================================
    .data
        hFont dd 0
        fShow dd 0
        str1  db "my other brother darryl",0
    .code

;==============================================================================

;------------------------------------------------------------------
; This is a modification of the MakeFont procedure from the MASM32
; examples, with the height and width specifications replaced with
; a point size specification.
;------------------------------------------------------------------

MakeFont proc pointSize:dword,weight:dword,italic:dword,lpFontName:dword

    invoke GetDC, 0
    invoke GetDeviceCaps, eax, LOGPIXELSY
    mul   pointSize
    xor   edx, edx
    mov   ecx, 72
    div   ecx

    invoke CreateFont,eax,0,NULL,NULL,weight,italic,NULL,NULL,
                      DEFAULT_CHARSET,OUT_TT_PRECIS,CLIP_DEFAULT_PRECIS,
                      PROOF_QUALITY,DEFAULT_PITCH or FF_DONTCARE,
                      lpFontName
    ret

MakeFont endp

;==============================================================================

IDC_SHOW  equ 1000
IDC_CLEAR equ 1001

;==============================================================================

DlgProc proc uses ebx hwndDlg:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM

    LOCAL ps:PAINTSTRUCT, rc:RECT, hdc:HDC

    SWITCH uMsg

        CASE WM_INITDIALOG

            invoke MakeFont, 24, FW_NORMAL, TRUE, chr$("Arial Narrow")
            mov hFont, eax

        CASE WM_PAINT

            invoke BeginPaint, hwndDlg, ADDR ps
            invoke SetTextColor, ps.hdc, 000000ffh
            invoke SelectObject, ps.hdc, hFont
            push eax
            .IF fShow
                invoke SetBkMode, ps.hdc, TRANSPARENT
                invoke TextOut, ps.hdc, 42, 50, ADDR str1, SIZEOF str1 - 1
            .ENDIF
            pop eax
            invoke SelectObject, ps.hdc, eax
            invoke EndPaint, hwndDlg, ADDR ps

        CASE WM_COMMAND

            SWITCH wParam
                CASE IDC_SHOW
                    mov fShow, 1
                    invoke InvalidateRect, hwndDlg, NULL, TRUE
                CASE IDC_HIDE
                    mov fShow, 0
                    invoke InvalidateRect, hwndDlg, NULL, TRUE
                CASE IDCANCEL
                    invoke EndDialog, hwndDlg, 0
            ENDSW

        CASE WM_CLOSE

            invoke DeleteObject, hFont

            invoke EndDialog, hwndDlg, 0

    ENDSW

    return 0

DlgProc endp

;==============================================================================
start:
;==============================================================================

    Dialog "Test", "MS Sans Serif",10, \
           WS_OVERLAPPED or WS_SYSMENU or DS_CENTER, \
           2,0,0,150,100,1024
    DlgButton "&Show",WS_TABSTOP,35,60,25,10,IDC_SHOW
    DlgButton "&Hide",WS_TABSTOP,85,60,25,10,IDC_HIDE
    CallModalDialog 0,0,DlgProc,0
    exit

;==============================================================================
end start

Well Microsoft, here's another nice mess you've gotten us into.

hfheatherfox07

Thank You MichaelW !  :biggrin:

That is so elegant....
Your code and your skills will be assimilated. Your programming language is irrelevant.
We are the ASM Borg and you will become part of us. Compile and be assembled.

hfheatherfox07

Here is another version of that , using CreateFontIndirect


I just have to figure out how to have the  WM_PAINT in it's own separate  proc......
I am already using WM_PAINT for something else so I need a separate proc
Your code and your skills will be assimilated. Your programming language is irrelevant.
We are the ASM Borg and you will become part of us. Compile and be assembled.

hfheatherfox07

#5
OK ...
Here is a version with a Proc ....

Why am I losing the text when I minimize ...Not catching it now :(


EDIT
Attachment removed see Last post
Your code and your skills will be assimilated. Your programming language is irrelevant.
We are the ASM Borg and you will become part of us. Compile and be assembled.

hfheatherfox07

#6
I cleaned it up a bit and it is worse ... Why?
what does minimize have to do with text?
:(


Attachment removed see Last post
Your code and your skills will be assimilated. Your programming language is irrelevant.
We are the ASM Borg and you will become part of us. Compile and be assembled.

hfheatherfox07

#7
and yet another try with ebx as hdc
same results, I Feel Like I am losing my mind  :(


Attachment removed see Last post
Your code and your skills will be assimilated. Your programming language is irrelevant.
We are the ASM Borg and you will become part of us. Compile and be assembled.

dedndave

if you want to modify Michael's code to use a seperate proc for WM_PAINT...
wmPaint PROTO :HWND
;
;
;
        CASE WM_PAINT

            invoke wmPaint, hwndDlg
;
;
;
wmPaint PROC hWnd:HWND

    LOCAL ps:PAINTSTRUCT

    invoke BeginPaint, hWnd, ADDR ps
    invoke SetTextColor, ps.hdc, 000000ffh
    invoke SelectObject, ps.hdc, hFont
    push eax
    .IF fShow
        invoke SetBkMode, ps.hdc, TRANSPARENT
        invoke TextOut, ps.hdc, 42, 50, ADDR str1, SIZEOF str1 - 1
    .ENDIF
    pop eax
    invoke SelectObject, ps.hdc, eax
    invoke EndPaint, hWnd, ADDR ps
    ret

wmPaint ENDP

notice that you no longer need the local PAINTSTRUCT in DlgProc

if you want to change to a different proc, use a dword variable to hold the address of wmPaint

hfheatherfox07

That Worked  Great!!!!
:greenclp:


I uploaded a copy of a working example in case any body ever runs into this....

P.S
Also removed the bad attachments ...I noticed when hutch collected all the attachments from the old forum to archive ....the examples that are not working got also posted ...people who download those would think they are good examples   


Here is a Good example .....Thank You dedndave!!!! :t
Your code and your skills will be assimilated. Your programming language is irrelevant.
We are the ASM Borg and you will become part of us. Compile and be assembled.

hfheatherfox07

OK ....
I decided to swap out one of the buttons to draw other text instead of just removing it ......

Why am I losing the 2nd text after it is drawn ?

Your code and your skills will be assimilated. Your programming language is irrelevant.
We are the ASM Borg and you will become part of us. Compile and be assembled.

dedndave

i am not sure exactly what you are trying to do - lol
i guess it's hard to describe, sometimes

i think you want to try...
        INVOKE  SetBkMode,hdc,TRANSPARENT
before drawing the text

hfheatherfox07

Quote from: dedndave on August 22, 2012, 07:56:23 PM
i am not sure exactly what you are trying to do - lol
i guess it's hard to describe, sometimes
What I am trying to do is instead of just removing the text with button 2 I figure draw another text  :biggrin:
Quote from: dedndave on August 22, 2012, 07:56:23 PM
i think you want to try...
        INVOKE  SetBkMode,hdc,TRANSPARENT
before drawing the text

Were ?
All that does is remove the transparent back ground ?

I have tried numerous other (Combining the two in one Draw Text proc but could not do it ) ways but no success  :(
Your code and your skills will be assimilated. Your programming language is irrelevant.
We are the ASM Borg and you will become part of us. Compile and be assembled.

hfheatherfox07

I know the problem is with WM_PAINT ...
I need to be able to initiate both drawtext procs there is that possible?

:dazzled:

Your code and your skills will be assimilated. Your programming language is irrelevant.
We are the ASM Borg and you will become part of us. Compile and be assembled.

hfheatherfox07

Solved  :greenclp:

MichaelW was right about Drawing  both from The WM_PAINT handler   :icon_redface:

I Got hung up with this proc thing .......  :icon_redface:

Here is a copy if any body wants to use it

Your code and your skills will be assimilated. Your programming language is irrelevant.
We are the ASM Borg and you will become part of us. Compile and be assembled.