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.