⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lion-tutorial27.htm

📁 内有一些代码
💻 HTM
📖 第 1 页 / 共 3 页
字号:
  EnumChild,addr ti  <br>
   &nbsp;&nbsp;&nbsp; .elseif uMsg==WM_CLOSE  <br>
   &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; invoke EndDialog,hDlg,NULL  
  <br>
   &nbsp;&nbsp;&nbsp; .else  <br>
   &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; mov eax,FALSE  <br>
   &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ret  <br>
   &nbsp;&nbsp;&nbsp; .endif  <br>
   &nbsp;&nbsp;&nbsp; mov eax,TRUE  <br>
   &nbsp;&nbsp;&nbsp; ret  <br>
   DlgProc endp   EnumChild proc uses edi hwndChild:DWORD,lParam:DWORD  
  <br>
   &nbsp;&nbsp;&nbsp; LOCAL buffer[256]:BYTE  <br>
   &nbsp;&nbsp;&nbsp; mov edi,lParam  <br>
   &nbsp;&nbsp;&nbsp; assume edi:ptr TOOLINFO  <br>
   &nbsp;&nbsp;&nbsp; push hwndChild  <br>
   &nbsp;&nbsp;&nbsp; pop [edi].uId  <br>
   &nbsp;&nbsp;&nbsp; or [edi].uFlags,TTF_IDISHWND  <br>
   &nbsp;&nbsp;&nbsp; invoke GetWindowText,hwndChild,addr buffer,255  <br>
   &nbsp;&nbsp;&nbsp; lea eax,buffer  <br>
   &nbsp;&nbsp;&nbsp; mov [edi].lpszText,eax  <br>
   &nbsp;&nbsp;&nbsp; invoke SendMessage,hwndTool,TTM_ADDTOOL,NULL,edi  
  <br>
   &nbsp;&nbsp;&nbsp; assume edi:nothing  <br>
   &nbsp;&nbsp;&nbsp; ret  <br>
   EnumChild endp   SetDlgToolArea proc uses edi esi hDlg:DWORD,lpti:DWORD,lpText:DWORD,id:DWORD,lprect:DWORD  
  <br>
   &nbsp;&nbsp;&nbsp; mov edi,lpti  <br>
   &nbsp;&nbsp;&nbsp; mov esi,lprect  <br>
   &nbsp;&nbsp;&nbsp; assume esi:ptr RECT  <br>
   &nbsp;&nbsp;&nbsp; assume edi:ptr TOOLINFO  <br>
   &nbsp;&nbsp;&nbsp; .if id==0  <br>
   &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; mov [edi].rect.left,0  <br>
   &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; mov [edi].rect.top,0  <br>
   &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; mov eax,[esi].right  <br>
   &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sub eax,[esi].left  <br>
   &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; shr eax,1  <br>
   &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; mov [edi].rect.right,eax  
  <br>
   &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; mov eax,[esi].bottom  <br>
   &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sub eax,[esi].top  <br>
   &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; shr eax,1  <br>
   &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; mov [edi].rect.bottom,eax  
  <br>
   &nbsp;&nbsp;&nbsp; .elseif id==1  <br>
   &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; mov eax,[esi].right  <br>
   &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sub eax,[esi].left  <br>
   &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; shr eax,1  <br>
   &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; inc eax  <br>
   &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; mov [edi].rect.left,eax  
  <br>
   &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; mov [edi].rect.top,0  <br>
   &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; mov eax,[esi].right  <br>
   &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sub eax,[esi].left  <br>
   &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; mov [edi].rect.right,eax  
  <br>
   &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; mov eax,[esi].bottom  <br>
   &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sub eax,[esi].top  <br>
   &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; mov [edi].rect.bottom,eax  
  <br>
   &nbsp;&nbsp;&nbsp; .elseif id==2  <br>
   &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; mov [edi].rect.left,0  <br>
   &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; mov eax,[esi].bottom  <br>
   &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sub eax,[esi].top  <br>
   &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; shr eax,1  <br>
   &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; inc eax  <br>
   &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; mov [edi].rect.top,eax  <br>
   &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; mov eax,[esi].right  <br>
   &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sub eax,[esi].left  <br>
   &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; shr eax,1  <br>
   &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; mov [edi].rect.right,eax  
  <br>
   &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; mov eax,[esi].bottom  <br>
   &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sub eax,[esi].top  <br>
   &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; mov [edi].rect.bottom,eax  
  <br>
   &nbsp;&nbsp;&nbsp; .else  <br>
   &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; mov eax,[esi].right  <br>
   &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sub eax,[esi].left  <br>
   &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; shr eax,1  <br>
   &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; inc eax  <br>
   &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; mov [edi].rect.left,eax  
  <br>
   &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; mov eax,[esi].bottom  <br>
   &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sub eax,[esi].top  <br>
   &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; shr eax,1  <br>
   &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; inc eax  <br>
   &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; mov [edi].rect.top,eax  <br>
   &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; mov eax,[esi].right  <br>
   &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sub eax,[esi].left  <br>
   &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; mov [edi].rect.right,eax  
  <br>
   &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; mov eax,[esi].bottom  <br>
   &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sub eax,[esi].top  <br>
   &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; mov [edi].rect.bottom,eax  
  <br>
   &nbsp;&nbsp;&nbsp; .endif  <br>
   &nbsp;&nbsp;&nbsp; push lpText  <br>
   &nbsp;&nbsp;&nbsp; pop [edi].lpszText  <br>
   &nbsp;&nbsp;&nbsp; invoke SendMessage,hwndTool,TTM_ADDTOOL,NULL,lpti  
  <br>
   &nbsp;&nbsp;&nbsp; assume edi:nothing  <br>
   &nbsp;&nbsp;&nbsp; assume esi:nothing  <br>
   &nbsp;&nbsp;&nbsp; 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>
   &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; TTS_ALWAYSTIP,CW_USEDEFAULT,\  
  <br>
   &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,NULL,NULL,\  
  <br>
   &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; hInstance,NULL  <br>
   mov hwndTool,eax </blockquote>
After that, we proceed to define four tools for each corner of the dialog box. 
 &nbsp;&nbsp;&nbsp; mov id,0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ; used 
as the tool ID  <br>
 &nbsp;&nbsp;&nbsp; mov ti.cbSize,sizeof TOOLINFO  <br>
 &nbsp;&nbsp;&nbsp; mov ti.uFlags,TTF_SUBCLASS&nbsp;&nbsp;&nbsp; ; tell the 
tooltip control to subclass the dialog window.  <br>
 &nbsp;&nbsp;&nbsp; push hDlg  <br>
 &nbsp;&nbsp;&nbsp; pop ti.hWnd&nbsp;&nbsp;&nbsp; ; handle to the window that 
contains the tool  <br>
 &nbsp;&nbsp;&nbsp; invoke GetWindowRect,hDlg,addr rect&nbsp;&nbsp;&nbsp; ; 
obtain the dimension of the client area  <br>
 &nbsp;&nbsp;&nbsp; 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> &nbsp;&nbsp;&nbsp; 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> &nbsp;&nbsp;&nbsp; LOCAL buffer[256]:BYTE </b> <br>
  <b> &nbsp;&nbsp;&nbsp; mov edi,lParam </b> <br>
  <b> &nbsp;&nbsp;&nbsp; assume edi:ptr TOOLINFO </b> <br>
  <b> &nbsp;&nbsp;&nbsp; push hwndChild </b> <br>
  <b> &nbsp;&nbsp;&nbsp; pop [edi].uId&nbsp;&nbsp;&nbsp; ; we use the whole 
  client area of the control as the tool </b> <br>
  <b> &nbsp;&nbsp;&nbsp; or [edi].uFlags,TTF_IDISHWND </b> <br>
  <b> &nbsp;&nbsp;&nbsp; invoke GetWindowText,hwndChild,addr buffer,255 </b> 
  <br>
  <b> &nbsp;&nbsp;&nbsp; lea eax,buffer&nbsp;&nbsp;&nbsp; ; use the window 
  text as the tooltip text </b> <br>
  <b> &nbsp;&nbsp;&nbsp; mov [edi].lpszText,eax </b> <br>
  <b> &nbsp;&nbsp;&nbsp; invoke SendMessage,hwndTool,TTM_ADDTOOL,NULL,edi </b> 
  <br>
  <b> &nbsp;&nbsp;&nbsp; assume edi:nothing </b> <br>
  <b> &nbsp;&nbsp;&nbsp; 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 + -