Author Topic: Draw Text with Button To show & Remove  (Read 14919 times)

hfheatherfox07

  • Member
  • ***
  • Posts: 464
Draw Text with Button To show & Remove
« on: August 18, 2012, 05:20:11 PM »
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

  • Member
  • ***
  • Posts: 464
Re: Draw Text with Button To show & Remove
« Reply #1 on: August 19, 2012, 12:56:12 AM »
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?
« Last Edit: August 19, 2012, 02:27:55 AM by hfheatherfox07 »
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

  • Global Moderator
  • Member
  • *****
  • Posts: 1209
Re: Draw Text with Button To show & Remove
« Reply #2 on: August 19, 2012, 02:12:09 PM »
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.
Code: [Select]
;==============================================================================
    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

  • Member
  • ***
  • Posts: 464
Re: Draw Text with Button To show & Remove
« Reply #3 on: August 19, 2012, 04:10:30 PM »
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

  • Member
  • ***
  • Posts: 464
Re: Draw Text with Button To show & Remove
« Reply #4 on: August 20, 2012, 05:21:07 AM »
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

  • Member
  • ***
  • Posts: 464
Re: Draw Text with Button To show & Remove
« Reply #5 on: August 20, 2012, 02:30:20 PM »
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
« Last Edit: August 22, 2012, 12:48:04 AM by hfheatherfox07 »
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

  • Member
  • ***
  • Posts: 464
Re: Draw Text with Button To show & Remove
« Reply #6 on: August 21, 2012, 01:23:51 PM »
I cleaned it up a bit and it is worse ... Why?
what does minimize have to do with text?
 :(


Attachment removed see Last post
« Last Edit: August 22, 2012, 12:48:22 AM by hfheatherfox07 »
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

  • Member
  • ***
  • Posts: 464
Re: Draw Text with Button To show & Remove
« Reply #7 on: August 21, 2012, 01:55:58 PM »
and yet another try with ebx as hdc
same results, I Feel Like I am losing my mind  :(


Attachment removed see Last post
« Last Edit: August 22, 2012, 12:48:42 AM by hfheatherfox07 »
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

  • Member
  • *****
  • Posts: 8821
  • Still using Abacus 2.0
    • DednDave
Re: Draw Text with Button To show & Remove
« Reply #8 on: August 21, 2012, 11:54:02 PM »
if you want to modify Michael's code to use a seperate proc for WM_PAINT...
Code: [Select]
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

  • Member
  • ***
  • Posts: 464
Re: Draw Text with Button To show & Remove
« Reply #9 on: August 22, 2012, 12:52:42 AM »
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

  • Member
  • ***
  • Posts: 464
Re: Draw Text with Button To show & Remove
« Reply #10 on: August 22, 2012, 06:34:14 PM »
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

  • Member
  • *****
  • Posts: 8821
  • Still using Abacus 2.0
    • DednDave
Re: Draw Text with Button To show & Remove
« Reply #11 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

i think you want to try...
Code: [Select]
        INVOKE  SetBkMode,hdc,TRANSPARENTbefore drawing the text

hfheatherfox07

  • Member
  • ***
  • Posts: 464
Re: Draw Text with Button To show & Remove
« Reply #12 on: August 23, 2012, 04:18:34 AM »
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:
i think you want to try...
Code: [Select]
        INVOKE  SetBkMode,hdc,TRANSPARENTbefore 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

  • Member
  • ***
  • Posts: 464
Re: Draw Text with Button To show & Remove
« Reply #13 on: August 23, 2012, 04:37:29 AM »
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

  • Member
  • ***
  • Posts: 464
Re: Draw Text with Button To show & Remove
« Reply #14 on: August 23, 2012, 06:20:31 AM »
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.