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

MichaelW

In general, everything that is supposed to show in the client area of the window must be redrawn on each WM_PAINT cycle. The controls in the client area, other than owner-draw controls, will normally be redrawn automatically and this is one of the advantages of using controls. In this case you are drawing directly on the client area of the window, and because one of the first steps in repainting the client area is to erase the background, for what you draw to stay visible you must redraw it on each  cycle.

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

IDC_SHOW equ 1000
IDC_HIDE equ 1001

;==============================================================================
    .data
        hFont dd 0
        fShow dd 0
        fOn1  dd 0
        fOn2  dd 0
        fOn3  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

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

PaintProc1 proc p:PTR PAINTSTRUCT
    push ebx
    mov ebx, p
    ASSUME ebx:PTR PAINTSTRUCT
    invoke SetTextColor, [ebx].hdc, 000000ffh
    invoke SelectObject, [ebx].hdc, hFont
    push eax
    .IF fShow && fOn1
        invoke SetBkMode, [ebx].hdc, TRANSPARENT
        invoke TextOut, [ebx].hdc, 42, 25, ADDR str1, SIZEOF str1 - 1
    .ENDIF
    pop eax
    invoke SelectObject, [ebx].hdc, eax
    ASSUME ebx:NOTHING
    pop ebx
    ret
PaintProc1 endp

PaintProc2 proc p:PTR PAINTSTRUCT
    push ebx
    mov ebx, p
    ASSUME ebx:PTR PAINTSTRUCT
    invoke SetTextColor, [ebx].hdc, 00ff0000h
    invoke SelectObject, [ebx].hdc, hFont
    push eax
    .IF fShow && fOn2
        invoke SetBkMode, [ebx].hdc, TRANSPARENT
        invoke TextOut, [ebx].hdc, 42, 55, ADDR str1, SIZEOF str1 - 1
    .ENDIF
    pop eax
    invoke SelectObject, [ebx].hdc, eax
    ASSUME ebx:NOTHING
    pop ebx
    ret
PaintProc2 endp

PaintProc3 proc p:PTR PAINTSTRUCT
    push ebx
    mov ebx, p
    ASSUME ebx:PTR PAINTSTRUCT
    invoke SetTextColor, [ebx].hdc, 0000ff00h
    invoke SelectObject, [ebx].hdc, hFont
    push eax
    .IF fShow && fOn3
        invoke SetBkMode, [ebx].hdc, TRANSPARENT
        invoke TextOut, [ebx].hdc, 42, 85, ADDR str1, SIZEOF str1 - 1
    .ENDIF
    pop eax
    invoke SelectObject, [ebx].hdc, eax
    ASSUME ebx:NOTHING
    pop ebx
    ret
PaintProc3 endp

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

IDC_SHOW  equ 1000
IDC_CLEAR equ 1001

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

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

    LOCAL ps:PAINTSTRUCT

    SWITCH uMsg

        CASE WM_INITDIALOG

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

            invoke SetTimer, hwndDlg, 1, 900, NULL
            invoke Sleep, 300
            invoke SetTimer, hwndDlg, 2, 900, NULL
            invoke Sleep, 300
            invoke SetTimer, hwndDlg, 3, 900, NULL

        CASE WM_TIMER

            SWITCH wParam
                CASE 1
                    not fOn1
                CASE 2
                    not fOn2
                CASE 3
                    not fOn3
            ENDSW
            invoke InvalidateRect, hwndDlg, NULL, TRUE

        CASE WM_PAINT

            invoke BeginPaint, hwndDlg, ADDR ps
            invoke PaintProc1, ADDR ps
            invoke PaintProc2, ADDR ps
            invoke PaintProc3, ADDR ps
            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 KillTimer, hwndDlg, 1
            invoke KillTimer, hwndDlg, 2
            invoke KillTimer, hwndDlg, 3

            invoke EndDialog, hwndDlg, 0

    ENDSW

    return 0

DlgProc endp

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

    Dialog "Test", "MS Sans Serif",10, \
           WS_OVERLAPPED or WS_SYSMENU or WS_CLIPCHILDREN 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


Note that I added the WS_CLIPCHILDREN style to the dialog so the buttons would be excluded from the background erase, as otherwise the frequent redraws would make them flicker.

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

dedndave

 :t

except.....
how many brothers named Daryl do you have, Michael ?
that must be the 50th time i have seen you use that - lol

hfheatherfox07

Quote from: MichaelW on August 23, 2012, 12:17:43 PM
Note that I added the WS_CLIPCHILDREN style to the dialog so the buttons would be excluded from the background erase, as otherwise the frequent redraws would make them flicker.

Funny , In one of my examples that I was trying that happened to me , my buttons just disappeared LOL

Nice example :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.

MichaelW

Quote from: dedndave on August 23, 2012, 12:20:33 PM
how many brothers named Daryl do you have, Michael ?

None, that I know of :biggrin:

The phrase was part of an often repeated line in the series Newhart.
Well Microsoft, here's another nice mess you've gotten us into.

hfheatherfox07

Wont work for me when I try to use this method to do the " Draw 2 text with buttons Example"
what am I missing ?
I keep getting errors:

: error A2131: VARARG parameter requires C calling convention
: error A2005: symbol redefinition : p
: error A2006: undefined symbol : p
: error A2006: undefined symbol : p
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

This is crazy ....
Why is it when I try to use that example and I use :
DrawTextProc  proc p: PTR PAINTSTRUCT  I get the

VARARG parameter requires C calling convention   ERROR ????

http://www.masmforum.com/board/index.php?PHPSESSID=786dd40408172108b65a5a36b09c88c0&topic=10673.0
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

There is a problem with your macros and your prototypes.

invokeC macro DrawTextProc2:REQ,vars:VARARG
LOCAL ivars
ivars=0
FOR var, <vars>
ivars=ivars+4
ENDM

invoke DrawTextProc2,vars
add esp,ivars
ENDM
invokeC macro DrawTextProc:REQ,vars:VARARG
LOCAL ivars
ivars=0
FOR var, <vars>
ivars=ivars+4
ENDM

invoke DrawTextProc,vars
add esp,ivars
ENDM
; ¤*¤*¤*¤*¤*¤*¤*¤*¤*¤*¤*¤*¤*¤*¤*¤*¤*¤*¤*¤*¤*¤*¤*¤*¤*¤*¤*¤*¤*¤*¤*¤*¤*¤*¤*¤*¤

; Prototype
; ¤*¤*¤*¤*¤*¤*¤*¤*¤*¤*¤*¤*¤*¤*¤*¤*¤*¤*¤*¤*¤*¤*¤*¤*¤*¤*¤*¤*¤*¤*¤*¤*¤*¤*¤*¤*¤
DialogProc      PROTO : HWND, : UINT, : WPARAM, : LPARAM
DrawTextProc    PROTO C :VARARG
DrawTextProc2   PROTO C :VARARG
Well Microsoft, here's another nice mess you've gotten us into.

hfheatherfox07

I tried with out and I still Get that same Error  :(
That is why I added those

I can not seem to use DrawTextProc  proc p: PTR PAINTSTRUCT

I still have MASM10 is that 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.

hfheatherfox07

NOP
That is not it ....Just tried masm11
It says that it is too far for the jumps in the text area
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.

jj2007

The macros are never being used. Your code needs this:

DrawTextProc  proc C p:VARARG
DrawTextProc2  proc C p:VARARG

hfheatherfox07

@ jj2007
Yap that solved that .....
Thank You !  :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

LOL That did that ......  :icon_redface: :icon_redface:

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

Thanks Again all .....
And Here is  MichaelW's 3 Text example with Proc and with out with rsrc.rc
:biggrin:
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

Quote from: MichaelW on August 23, 2012, 01:10:35 PMThe phrase was part of an often repeated line in the series Newhart.

oh yes - i remember it well
probably the best part of the show - lol
when i watch "Blade Runner", i am always reminded of the Daryls

hfheatherfox07

All of this 3 Flashing text ... Reminds me of that Delphi Nervous text that I tried To convert To masm.....( I think I will have to Bit Bit this)

Am I Blind or all that this Does (From a colour point of view) is flash 3 colours ?
IS there any Blending or just 3 text colours flashing ?

May be I need to screen record this and slow it down
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.