Reputation: 11
Using MASM32 & a Win32 API function, I want to show a messagebox to explain the purpose of an Edit Control when the mouse hovers over the Edit Control. I've read about WM_MOUSEHOVER but I don't understand how to setup the code. Does anyone have an example of how to do something like what I am trying to do or have other suggestions?
I tried incorporating the TRACKMOUSEEVENT structure (from windows.inc) and the TrackMouseEvent function (from user32.lib) along with the TrackMouseEvent prototype (from user32.inc). The code assembles but produces no output when executed.
In response to comments, I've added the code I modified based on Iczelion's Tutorial #27 that I described in my last comment.
; This example from Iczelion's Tutorial 27 has been modified to display tooltips
; only for the 2 buttons in the dialog box.
.386
.model flat,stdcall
option casemap:none
include \masm32\include\windows.inc
include \masm32\include\kernel32.inc
include \masm32\include\user32.inc
include \masm32\include\comctl32.inc
includelib \masm32\lib\comctl32.lib
includelib \masm32\lib\user32.lib
includelib \masm32\lib\kernel32.lib
DlgProc proto :DWORD,:DWORD,:DWORD,:DWORD
EnumChild proto :DWORD,:DWORD
; The following prototype is not needed fr this example. See comment bellow.
;SetDlgToolArea proto :DWORD,:DWORD,:DWORD,:DWORD,:DWORD
.const
IDD_MAINDIALOG equ 101
IDC_OK equ 1000
IDC_EXIT equ 1001
IDC_InformationBox equ 3000
.data
ToolTipsClassName db "Tooltips_class32",0
; The following 4 string definitions are not needed for this example. See comment below.
;MainDialogText1 db "This is the upper left area of the dialog",0
;MainDialogText2 db "This is the upper right area of the dialog",0
;MainDialogText3 db "This is the lower left area of the dialog",0
;MainDialogText4 db "This is the lower right area of the dialog",0
.data?
hwndTool dd ?
hInstance dd ?
.code
start:
invoke GetModuleHandle,NULL
mov hInstance,eax
invoke DialogBoxParam,hInstance,IDD_MAINDIALOG,NULL,addr DlgProc,NULL
invoke ExitProcess,eax
DlgProc proc hDlg:DWORD,uMsg:DWORD,wParam:DWORD,lParam:DWORD
LOCAL ti:TOOLINFO
; LOCAL id:DWORD
; LOCAL rect:RECT
.if uMsg==WM_INITDIALOG
invoke InitCommonControls
invoke CreateWindowEx,NULL,ADDR ToolTipsClassName,NULL,\
TTS_ALWAYSTIP,CW_USEDEFAULT,\
CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,NULL,NULL,\
hInstance,NULL
mov hwndTool,eax
; mov id,0
mov ti.cbSize,sizeof TOOLINFO
mov ti.uFlags,TTF_SUBCLASS
push hDlg
pop ti.hWnd
; invoke GetWindowRect,hDlg,addr rect
; invoke SetDlgToolArea,hDlg,addr ti,addr MainDialogText1,id,addr rect
; inc id
; invoke SetDlgToolArea,hDlg,addr ti,addr MainDialogText2,id,addr rect
; inc id
; invoke SetDlgToolArea,hDlg,addr ti,addr MainDialogText3,id,addr rect
; inc id
; invoke SetDlgToolArea,hDlg,addr ti,addr MainDialogText4,id,addr rect
invoke EnumChildWindows,hDlg,addr EnumChild,addr ti
.elseif uMsg==WM_CLOSE
invoke EndDialog,hDlg,NULL
.else
mov eax,FALSE
ret
.endif
mov eax,TRUE
ret
DlgProc endp
EnumChild proc uses edi hwndChild:DWORD,lParam:DWORD
LOCAL buffer[256]:BYTE
mov edi,lParam
assume edi:ptr TOOLINFO
push hwndChild
pop [edi].uId
or [edi].uFlags,TTF_IDISHWND ;
or [edi].uFlags,TTF_SUBCLASS ; ADDED TO USE BOTH TTF_IDISHWND & TTF_SUBCLASS flags
invoke GetWindowText,hwndChild,addr buffer,255
lea eax,buffer
mov [edi].lpszText,eax
invoke SendMessage,hwndTool,TTM_ADDTOOL,NULL,edi
assume edi:nothing
ret
EnumChild endp
comment $
********************************************************************************************************************
This procedure is NOT needed for adding ToolTips to specific controls in a dialog box.
SetDlgToolArea proc uses edi esi hDlg:DWORD,lpti:DWORD,lpText:DWORD,id:DWORD,lprect:DWORD
mov edi,lpti
mov esi,lprect
assume esi:ptr RECT
assume edi:ptr TOOLINFO
.if id==0
mov [edi].rect.left,0
mov [edi].rect.top,0
mov eax,[esi].right
sub eax,[esi].left
shr eax,1
mov [edi].rect.right,eax
mov eax,[esi].bottom
sub eax,[esi].top
shr eax,1
mov [edi].rect.bottom,eax
.elseif id==1
mov eax,[esi].right
sub eax,[esi].left
shr eax,1
inc eax
mov [edi].rect.left,eax
mov [edi].rect.top,0
mov eax,[esi].right
sub eax,[esi].left
mov [edi].rect.right,eax
mov eax,[esi].bottom
sub eax,[esi].top
mov [edi].rect.bottom,eax
.elseif id==2
mov [edi].rect.left,0
mov eax,[esi].bottom
sub eax,[esi].top
shr eax,1
inc eax
mov [edi].rect.top,eax
mov eax,[esi].right
sub eax,[esi].left
shr eax,1
mov [edi].rect.right,eax
mov eax,[esi].bottom
sub eax,[esi].top
mov [edi].rect.bottom,eax
.else
mov eax,[esi].right
sub eax,[esi].left
shr eax,1
inc eax
mov [edi].rect.left,eax
mov eax,[esi].bottom
sub eax,[esi].top
shr eax,1
inc eax
mov [edi].rect.top,eax
mov eax,[esi].right
sub eax,[esi].left
mov [edi].rect.right,eax
mov eax,[esi].bottom
sub eax,[esi].top
mov [edi].rect.bottom,eax
.endif
push lpText
pop [edi].lpszText
invoke SendMessage,hwndTool,TTM_ADDTOOL,NULL,lpti
assume edi:nothing
assume esi:nothing
ret
SetDlgToolArea endp
********************************************************************************************************************
$
end start
Upvotes: 0
Views: 67