?? lion-tutorial27.htm
字號:
EnumChild,addr ti <br>
.elseif uMsg==WM_CLOSE <br>
invoke EndDialog,hDlg,NULL
<br>
.else <br>
mov eax,FALSE <br>
ret <br>
.endif <br>
mov eax,TRUE <br>
ret <br>
DlgProc endp EnumChild proc uses edi hwndChild:DWORD,lParam:DWORD
<br>
LOCAL buffer[256]:BYTE <br>
mov edi,lParam <br>
assume edi:ptr TOOLINFO <br>
push hwndChild <br>
pop [edi].uId <br>
or [edi].uFlags,TTF_IDISHWND <br>
invoke GetWindowText,hwndChild,addr buffer,255 <br>
lea eax,buffer <br>
mov [edi].lpszText,eax <br>
invoke SendMessage,hwndTool,TTM_ADDTOOL,NULL,edi
<br>
assume edi:nothing <br>
ret <br>
EnumChild endp SetDlgToolArea proc uses edi esi hDlg:DWORD,lpti:DWORD,lpText:DWORD,id:DWORD,lprect:DWORD
<br>
mov edi,lpti <br>
mov esi,lprect <br>
assume esi:ptr RECT <br>
assume edi:ptr TOOLINFO <br>
.if id==0 <br>
mov [edi].rect.left,0 <br>
mov [edi].rect.top,0 <br>
mov eax,[esi].right <br>
sub eax,[esi].left <br>
shr eax,1 <br>
mov [edi].rect.right,eax
<br>
mov eax,[esi].bottom <br>
sub eax,[esi].top <br>
shr eax,1 <br>
mov [edi].rect.bottom,eax
<br>
.elseif id==1 <br>
mov eax,[esi].right <br>
sub eax,[esi].left <br>
shr eax,1 <br>
inc eax <br>
mov [edi].rect.left,eax
<br>
mov [edi].rect.top,0 <br>
mov eax,[esi].right <br>
sub eax,[esi].left <br>
mov [edi].rect.right,eax
<br>
mov eax,[esi].bottom <br>
sub eax,[esi].top <br>
mov [edi].rect.bottom,eax
<br>
.elseif id==2 <br>
mov [edi].rect.left,0 <br>
mov eax,[esi].bottom <br>
sub eax,[esi].top <br>
shr eax,1 <br>
inc eax <br>
mov [edi].rect.top,eax <br>
mov eax,[esi].right <br>
sub eax,[esi].left <br>
shr eax,1 <br>
mov [edi].rect.right,eax
<br>
mov eax,[esi].bottom <br>
sub eax,[esi].top <br>
mov [edi].rect.bottom,eax
<br>
.else <br>
mov eax,[esi].right <br>
sub eax,[esi].left <br>
shr eax,1 <br>
inc eax <br>
mov [edi].rect.left,eax
<br>
mov eax,[esi].bottom <br>
sub eax,[esi].top <br>
shr eax,1 <br>
inc eax <br>
mov [edi].rect.top,eax <br>
mov eax,[esi].right <br>
sub eax,[esi].left <br>
mov [edi].rect.right,eax
<br>
mov eax,[esi].bottom <br>
sub eax,[esi].top <br>
mov [edi].rect.bottom,eax
<br>
.endif <br>
push lpText <br>
pop [edi].lpszText <br>
invoke SendMessage,hwndTool,TTM_ADDTOOL,NULL,lpti
<br>
assume edi:nothing <br>
assume esi:nothing <br>
ret <br>
SetDlgToolArea endp <br>
end start </blockquote>
Analysis:After the main dialog window is created, we create the tooltip control
with CreateWindowEx.
<blockquote> invoke InitCommonControls <br>
invoke CreateWindowEx,NULL,ADDR ToolTipsClassName,NULL,\ <br>
TTS_ALWAYSTIP,CW_USEDEFAULT,\
<br>
CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,NULL,NULL,\
<br>
hInstance,NULL <br>
mov hwndTool,eax </blockquote>
After that, we proceed to define four tools for each corner of the dialog box.
mov id,0 ; used
as the tool ID <br>
mov ti.cbSize,sizeof TOOLINFO <br>
mov ti.uFlags,TTF_SUBCLASS ; tell the
tooltip control to subclass the dialog window. <br>
push hDlg <br>
pop ti.hWnd ; handle to the window that
contains the tool <br>
invoke GetWindowRect,hDlg,addr rect ;
obtain the dimension of the client area <br>
invoke SetDlgToolArea,hDlg,addr ti,addr MainDialogText1,id,addr
rect
<p>We initialize the members of <b>TOOLINFO </b>structure. Note that we want to
divide the client area into 4 tools so we need to know the dimension of the
client area. That's why we call <b>GetWindowRect</b>. We don't want to relay
mouse messages to the tooltip control ourselves so we specify <b>TIF_SUBCLASS
</b>flag. <br>
<b>SetDlgToolArea</b> is a function that calculates the bounding rectangle of
each tool and registers the tool to the tooltip control. I won't go into gory
detail on the calculation, suffice to say that it divides the client area into
4 areas with the same sizes. Then it sends <b>TTM_ADDTOOL</b> message to the
tooltip control, passing the address of the <b>TOOLINFO</b> structure in the
lParam parameter.
<p><b> invoke SendMessage,hwndTool,TTM_ADDTOOL,NULL,lpti </b>
<p>After all 4 tools are registered, we can go on to the buttons on the dialog
box. We can handle each button by its ID but this is tedious. Instead, we will
use <b>EnumChildWindows</b> API call to enumerate all controls on the dialog
box and then registers them to the tooltip control. <b>EnumChildWindows</b>
has the following syntax:
<blockquote><b>EnumChildWindows proto hWnd:DWORD, lpEnumFunc:DWORD, lParam:DWORD</b></blockquote>
hWnd is the handle to the parent window. lpEnumFunc is the address of the <b>EnumChildProc</b>
function that will be called for each control enumerated. lParam is the application-defined
value that will be passed to the <b>EnumChildProc</b> function. The <b>EnumChildProc</b>
function has the following definition:
<blockquote><b>EnumChildProc proto hwndChild:DWORD, lParam:DWORD</b></blockquote>
hwndChild is the handle to a control enumerated by<b> EnumChildWindows</b>. lParam
is the same lParam value you pass to <b>EnumChildWindows</b>. <br>
In our example, we call<b> EnumChildWindows</b> like this:
<blockquote><b> invoke EnumChildWindows,hDlg,addr EnumChild,addr ti </b></blockquote>
We pass the address of the <b>TOOLINFO</b> structure in the lParam parameter because
we will register each child control to the tooltip control in the <b>EnumChild
</b>function. If we don't use this method, we need to declare <b>ti </b>as a global
variable which can introduce bugs. <br>
When we call<b> EnumChildWindows</b>, Windows will enumerate the child controls
on our dialog box and call the <b>EnumChild</b> function once for each control
enumerated. Thus if our dialog box has two controls, <b>EnumChild</b> will be
called twice. <br>
The EnumChild function fills the relevant members of the TOOLINFO structure and
then registers the tool with the tooltip control.
<blockquote><b> EnumChild proc uses edi hwndChild:DWORD,lParam:DWORD </b>
<br>
<b> LOCAL buffer[256]:BYTE </b> <br>
<b> mov edi,lParam </b> <br>
<b> assume edi:ptr TOOLINFO </b> <br>
<b> push hwndChild </b> <br>
<b> pop [edi].uId ; we use the whole
client area of the control as the tool </b> <br>
<b> or [edi].uFlags,TTF_IDISHWND </b> <br>
<b> invoke GetWindowText,hwndChild,addr buffer,255 </b>
<br>
<b> lea eax,buffer ; use the window
text as the tooltip text </b> <br>
<b> mov [edi].lpszText,eax </b> <br>
<b> invoke SendMessage,hwndTool,TTM_ADDTOOL,NULL,edi </b>
<br>
<b> assume edi:nothing </b> <br>
<b> ret </b> <br>
<b> EnumChild endp </b></blockquote>
Note that in this case, we use a different type of tool: one that covers the whole
client area of the window. We thus need to fill the <b>uID</b> field with the
handle to the window that contains the tool. Also we must specify <b>TTF_IDISHWND</b>
flag in the <b>uFlags</b> member. <strong> </strong>
<hr size="1">
<div align="center"> This article come from Iczelion's asm page, Welcom to <a href="http://asm.yeah.net">http://asm.yeah.net</a></div>
</body>
</html>
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -