If you are using an edit control just to display text but can't use a static because the text may be too long for it all to display this subclassing procedure will allow copy and paste as well as scrolling. It also displays a tooltip with the complete text.

SubClassEdit FRAME hwnd,uMsg,wParam,lParam
uses ebx
LOCAL hMenu :D
LOCAL pt :POINT
LOCAL ti :TOOLINFO

cmp D,WM_SETTEXT
jne >
// Add this control to the tooltip
mov D,SIZEOF TOOLINFO
mov D,TTF_IDISHWND + TTF_SUBCLASS
mov eax,
mov ,eax
mov ,eax
mov eax,
mov ,eax
mov D,LPSTR_TEXTCALLBACK
// Remove the control if it is already added
invoke SendMessage,,TTM_DELTOOL,0,ADDR ti
invoke SendMessage,,TTM_ADDTOOL,0,ADDR ti
jmp >>.DEFPROC
:

cmp D,WM_DESTROY
jne >
// Remove this control to the tooltip
mov D,SIZEOF TOOLINFO
mov eax,
mov ,eax
mov ,eax
mov D,LPSTR_TEXTCALLBACK
invoke SendMessage,,TTM_DELTOOL,0,ADDR ti
jmp >>.DEFPROC
:

cmp D,WM_NOTIFY
jne >
mov ebx,
cmp D,TTN_GETDISPINFO
jne >>.DEFPROC
invoke SendMessage,,WM_GETTEXT,MAX_PATH,offset szBuffer
mov D, offset szBuffer
ret

:
cmp D,WM_PASTE
jne >
// Pasting text is not allowed
xor eax,eax
ret
:
cmp D,WM_CHAR
jne >
// Typing is not allowed
xor eax,eax
ret
:
cmp D,WM_CUT
jne >
// Cutting text is not allowed
xor eax,eax
ret
:
cmp D,WM_CONTEXTMENU
jne >>.DEFPROC
// Do not allow anything but "Select All" and "Copy" to appear on edit context menu
// For the start up folder allow also "Open this folder"
mov eax,
movzx edx,ax
mov ,edx
shr eax,16
movzx edx,ax
mov ,edx
invoke CreatePopupMenu
mov ,eax
invoke AppendMenu,,MF_STRING + MF_ENABLED,100,"Copy"
invoke AppendMenu,,MF_SEPARATOR,0,0
invoke AppendMenu,,MF_STRING + MF_ENABLED,101,"Select all"
invoke TrackPopupMenu,,TPM_LEFTALIGN + TPM_RETURNCMD, \
,,NULL,,NULL
mov ebx,eax

cmp ebx,100
jne >.SELALL
invoke PostMessage,,WM_COPY,0,0
jmp >>.MENUEND

.SELALL
cmp ebx,101
jne >.MENUEND
invoke PostMessage,,EM_SETSEL,0,-1

.MENUEND
invoke DestroyMenu,
xor eax,eax
ret

.DEFPROC
invoke CallWindowProc,,,,,
RET
ENDF


To create the tool tip use the following at the start of your program...

invoke InitCommonControls
invoke CreateWindowEx,0,"tooltips_class32","tooltips_class32",TTS_ALWAYSTIP, \
0,0,0,0,0,0,,0
mov ,eax
invoke SendMessage,,TTM_ACTIVATE,TRUE,0


Be sure to clean up when done by destroying the tooltip control

invoke DestroyWindow,


Now, to subclass your edit control just add the following to your code, this can be used for multiple edit controls on the same dialog or window...

invoke SetWindowLong,,GWL_WNDPROC,OFFSET SubClassEdit
mov ,eax
Posted on 2006-04-08 19:54:03 by donkey