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

📄 lion-tutorial18.htm

📁 内有一些代码
💻 HTM
📖 第 1 页 / 共 2 页
字号:
<html>

<head>
<link rel="stylesheet" href="../../asm.css">

<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>Iczelion's win32 asm tutorial</title>
</head>

<body bgcolor="#FFFFFF" background="../../images/back01.jpg">
<p align="center">Tutorial 18: Common Controls</p>
<hr size="1">
<strong> </strong> We will learn what common controls are and how to use them. 
This tutorial will be a quick introduction to them only. <br>
Download the example source code<a href="files/tut18.zip"> here</a>. 
<h3> Theory:</h3>
Windows 95 comes with several user-interface enhancements over Windows 3.1x. They 
make the GUI richer. Several of them are in widely used before Windows 95 hit 
the shelf, such as status bar, toolbars etc. Programmers have to code them themselves. 
Now Microsoft has included them with Windows 9x and NT. We will learn about them 
here. <br>
These are the new controls: 
<ul>
  <li> Toolbar</li>
  <li> Tooltip</li>
  <li> Status bar</li>
  <li> Property sheet</li>
  <li> Property page</li>
  <li> Tree view</li>
  <li> List view</li>
  <li> Animation</li>
  <li> Drag list</li>
  <li> Header</li>
  <li> Hot-key</li>
  <li> Image list</li>
  <li> Progress bar</li>
  <li> Right edit</li>
  <li> Tab</li>
  <li> Trackbar</li>
  <li> Up-down</li>
</ul>
Since there are many of them, loading them all into memory and registering them 
would be a waste of resource. All of them, with the exception of rich edit control, 
are stored in comctl32.dll with applications can load when they want to use the 
controls. Rich edit control resides in its own dll, richedXX.dll, because it's 
very complicated and hence larger than its brethren. <br>
You can load comctl32.dll by including a call to <b>InitCommonControls</b> in 
your program. InitCommonControls is a function in comctl32.dll, so referring to 
it anywhere in your code will make PE loader load comctl32.dll when your program 
runs.<b>You don't have to execute it, just include it in your code somewhere</b>. 
This function does <b>NOTHING!</b> Its only instruction is "ret". Its sole purpose 
is to include reference to comctl32.dll in the import section so that PE loader 
will load it whenever the program is loaded. The real workhorse is the DLL entrypoint 
function which registers all common control classes when the dll is loaded. Common 
controls are created based on those classes just like other child window controls 
such as edit, listbox etc. <br>
Rich edit is another matter entirely. If you want to use it, you have to call 
LoadLibrary to load it explicitly and call FreeLibrary to unload it. <br>
Now we learn how to create them. You can use a resource editor to incorporate 
them into dialog boxes or you can create them yourself. Nearly all common controls 
are created by calling CreateWindowEx or CreateWindow, passing it the name of 
the control class. Some common controls have specific creation functions , however, 
they are just wrappers around CreateWindowEx to make it easier to create those 
controls. Existing specific creation functions are listed below: 
<ul>
  <li> CreateToolbarEx</li>
  <li> CreateStatusWindow</li>
  <li> CreatePropertySheetPage</li>
  <li> PropertySheet</li>
  <li> ImageList_Create</li>
</ul>
In order to create common controls, you have to know their class names. They are 
listed below: <br>
&nbsp; 
<center>
  <table BORDER width="62%" >
    <tr bgcolor="#3366FF"> 
      <td> 
        <center>
          Class Name 
        </center>
      </td>
      <td> 
        <center>
          Common Control 
        </center>
      </td>
    </tr>
    <tr> 
      <td>ToolbarWindow32</td>
      <td>Toolbar</td>
    </tr>
    <tr> 
      <td>tooltips_class32</td>
      <td>Tooltip</td>
    </tr>
    <tr> 
      <td>msctls_statusbar32</td>
      <td>Status bar</td>
    </tr>
    <tr> 
      <td>SysTreeView32</td>
      <td>Tree view</td>
    </tr>
    <tr> 
      <td>SysListView32</td>
      <td>List view</td>
    </tr>
    <tr> 
      <td>SysAnimate32</td>
      <td>Animation</td>
    </tr>
    <tr> 
      <td>SysHeader32</td>
      <td>Header</td>
    </tr>
    <tr> 
      <td>msctls_hotkey32</td>
      <td>Hot-key</td>
    </tr>
    <tr> 
      <td>msctls_progress32</td>
      <td>Progress bar</td>
    </tr>
    <tr> 
      <td>RICHEDIT</td>
      <td>Rich edit</td>
    </tr>
    <tr> 
      <td>msctls_updown32</td>
      <td>Up-down</td>
    </tr>
    <tr> 
      <td>SysTabControl32</td>
      <td>Tab</td>
    </tr>
  </table>
</center>
Property sheets and property pages and image list control have their own specific 
creation functions. Drag list control are souped-up listbox so it doesn't have 
its own class. The above class names are verified by checking resource script 
generated by Visual C++ resource editor. They differ from the class names listed 
by Borland's win32 api reference and Charles Petzold's Programming Windows 95. 
The above list is the accurate one. <br>
Those common controls can use general window styles such as WS_CHILD etc. They 
also have their own specific styles such as TVS_XXXXX for tree view control, LVS_xxxx 
for list view control, etc. Win32 api reference is your best friend in this regard. 
<br>
Now that we know how to create common controls, we can move on to communication 
method between common controls and their parent. Unlike child window controls, 
common controls don't communicate with the parent via WM_COMMAND. Instead they 
send WM_NOTIFY messages to the parent window when some interesting events occur 
with the common controls. The parent can control the children by sending messages 
to them. There are also many new messages for those new controls. You should consult 
your win32 api reference for more detail. <br>
Let's examine progress bar and status bar controls in the following example. 
<h4> Sample code:</h4>
 <b>.386</b> <br>
<b>.model flat,stdcall</b> <br>
<b>option casemap:none</b> <br>
<b>include \masm32\include\windows.inc</b> <br>
<b>include \masm32\include\user32.inc</b> <br>
<b>include \masm32\include\kernel32.inc</b> <br>
<b>include \masm32\include\comctl32.inc</b> <br>
<b>includelib \masm32\lib\comctl32.lib</b> <br>
<b>includelib \masm32\lib\user32.lib</b> <br>
<b>includelib \masm32\lib\kernel32.lib</b> 
<p><b>WinMain PROTO :DWORD,:DWORD,:DWORD,:DWORD</b> 
<p><b>.const</b> <br>
  <b>IDC_PROGRESS equ 1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
  ; control IDs</b> <br>
  <b>IDC_STATUS equ 2</b> <br>
  <b>IDC_TIMER&nbsp; equ 3</b> 
<p><b>.data</b> <br>
  <b>ClassName&nbsp; db "CommonControlWinClass",0</b> <br>
  <b>AppName&nbsp;&nbsp;&nbsp; db "Common Control Demo",0</b> <br>
  <b>ProgressClass&nbsp; db "msctls_progress32",0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
  ; the class name of the progress bar</b> <br>
  <b>Message&nbsp; db "Finished!",0</b> <br>
  <b>TimerID&nbsp; dd 0</b> 
<p><b>.data?</b> <br>
  <b>hInstance&nbsp; HINSTANCE ?</b> <br>
  <b>hwndProgress dd ?</b> <br>
  <b>hwndStatus dd ?</b> <br>
  <b>CurrentStep dd ?</b> <br>
  <b>.code</b> <br>
  <b>start:</b> <br>
  <b>&nbsp;&nbsp;&nbsp; invoke GetModuleHandle, NULL</b> <br>
  <b>&nbsp;&nbsp;&nbsp; mov&nbsp;&nbsp;&nbsp; hInstance,eax</b> <br>
  <b>&nbsp;&nbsp;&nbsp; invoke WinMain, hInstance,NULL,NULL, SW_SHOWDEFAULT</b> 
  <br>
  <b>&nbsp;&nbsp;&nbsp; invoke ExitProcess,eax</b> <br>
  <b>&nbsp;&nbsp;&nbsp; invoke InitCommonControls</b> 
<p><b>WinMain proc hInst:HINSTANCE,hPrevInst:HINSTANCE,CmdLine:LPSTR,CmdShow:DWORD</b> 
  <br>
  <b>&nbsp;&nbsp;&nbsp; LOCAL wc:WNDCLASSEX</b> <br>
  <b>&nbsp;&nbsp;&nbsp; LOCAL msg:MSG</b> <br>
  <b>&nbsp;&nbsp;&nbsp; LOCAL hwnd:HWND</b> 
<p><b>&nbsp;&nbsp;&nbsp; mov&nbsp;&nbsp; wc.cbSize,SIZEOF WNDCLASSEX</b> <br>
  <b>&nbsp;&nbsp;&nbsp; mov&nbsp;&nbsp; wc.style, CS_HREDRAW or CS_VREDRAW</b> 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -