News:

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

SuperEditClass and Cursor

Started by six_L, January 18, 2008, 11:26:51 AM

Previous topic - Next topic

six_L

hello, all
1. question
after it's gone sometimes, the background of superclass edit is being changed from black to white.

EditWndProc PROC hEdit:DWORD,uMsg:DWORD,wParam:DWORD,lParam:DWORD
local ps:PAINTSTRUCT
local rt:RECT
LOCAL buffer[32]:byte
LOCAL mdc:DWORD
LOCAL hdc:HDC
LOCAL hBmp:DWORD

mov eax,uMsg
.if eax==WM_PAINT
invoke BeginPaint,hEdit,addr ps
mov hdc,eax
invoke  CreateCompatibleDC,eax
mov     mdc,eax
invoke GetClientRect,hEdit,addr rt
invoke  CreateCompatibleBitmap,ps.hdc,rt.right,rt.bottom
mov     hBmp,eax
invoke  SelectObject,mdc,eax
invoke CreateSolidBrush,0h
invoke  FillRect,mdc,addr rt,eax

invoke SelectObject,mdc,hFont
invoke SetBkMode,mdc,TRANSPARENT
invoke SetTextColor,mdc,Red

invoke  RtlZeroMemory,addr buffer,sizeof buffer
invoke GetWindowText,hEdit,addr buffer,32
invoke lstrlen,addr buffer
mov ebx,eax
invoke DrawText,mdc,addr buffer,ebx,addr rt,DT_VCENTER or DT_SINGLELINE or DT_CENTER
invoke  BitBlt,hdc,0,0,rt.right,rt.bottom,mdc,0,0,SRCCOPY
invoke  DeleteDC,mdc
invoke  DeleteObject,hBmp

invoke EndPaint,hEdit,addr ps
.else
invoke CallWindowProc,OldWndProc,hEdit,uMsg,wParam,lParam
ret
.endif
xor eax,eax
ret
EditWndProc endp
;---------------------------------------------------------------------
cEditText proc hParent:DWORD, x:DWORD,y:DWORD,w:DWORD,h:DWORD,ID:DWORD
LOCAL @wc:WNDCLASSEX

mov @wc.cbSize,sizeof WNDCLASSEX
invoke GetClassInfoEx,NULL,SADD("EDIT"),addr @wc

m2m OldWndProc,@wc.lpfnWndProc
mov @wc.lpfnWndProc, OFFSET EditWndProc
m2m @wc.hInstance,hInstance
mov @wc.lpszClassName,SADD("SUPEREDITCLASS")

invoke RegisterClassEx, addr @wc

invoke CreateWindowEx,WS_EX_CLIENTEDGE,S("SUPEREDITCLASS"),NULL,\
      WS_CHILD+WS_VISIBLE+WS_BORDER,x,y,w,h,\
hParent,ID,hInstance,NULL
ret

cEditText endp
;---------------------------------------------------------------------
; one second to do the following
...
invoke SetDlgItemText, hWnd, ID_EDIT,addr dataBuffer
...

2. question
if the mouse does not moving, the cursor can be changed.
...
;---------------------------------------------------------------------
invoke LoadCursor, hInstance, ID_CURSOR1
invoke SetClassLong, hWin, GCL_HCURSOR, eax
invoke UpdateWindow, hWin
;---------------------------------------------------------------------
...
regards

donkey

Everything looks alright with the code, my only comment is that with DrawText you do not need to get the string length as the returned string from GetWindowText is NULL terminated...

mov  BYTE PTR buffer, 0
invoke GetWindowText,hEdit,addr buffer,32
invoke DrawText,mdc,addr buffer,-1,addr rt,DT_VCENTER or DT_SINGLELINE or DT_CENTER


If you use -1 as the string length for DrawText it assumes a NULL terminated string, note that the documentation at MSDN is wrong for this function. Also there is no need to set the entire buffer to 0 with RtlZeroMemory, only the first byte as GetWindowText does not modify the buffer in cases where there is an error. Generally I like to keep WM_PAINT subclassing pretty lean and mean so I cut out all extra API calls within it.
"Ahhh, what an awful dream. Ones and zeroes everywhere...[shudder] and I thought I saw a two." -- Bender
"It was just a dream, Bender. There's no such thing as two". -- Fry
-- Futurama

Donkey's Stable

six_L

Hello,donkey
thanks your response.
the problem is still there.
mov  BYTE PTR buffer, 0
invoke GetWindowText,hEdit,addr buffer,32
invoke DrawText,mdc,addr buffer,-1,addr rt,DT_VCENTER or DT_SINGLELINE or DT_CENTER
regards