Tutorials to .com

Tutorials to .com » Software » Asm » WIN32 compilation: 18. Common control

WIN32 compilation: 18. Common control

Print View , by: iSee ,Total views: 60 ,Word Count: 2559 ,Date: Wed, 6 May 2009 Time: 8:29 PM

General Controls 18th lesson


This lesson we will learn what the general controls and how to use them.

Theory:

WIN95 vis-à-vis a number of WIN3X enhanced user interface controls. In fact, before the official release of WIN95 on the use of these controls, such as: the status of articles, tools and so on. Previous programmers programming for them to use them, and now Microsoft has the WIN9X they contain and in the WINNT.
  • Toolbar Toolbar ---
  • Tooltip --- prompt text
  • Status bar Status bar ---
  • Property sheet --- Single Property Page
  • Property page --- Property Pages
  • Tree view Tree view ---
  • List view List view ---
  • Animation Animation ---
  • Drag list --- able to handle the Drag-Drop List Box
  • Header ---
  • Hot-key --- hotkey
  • Image Image list --- list
  • Progress bar --- the process of the status of Article
  • Right edit ---
  • Tab --- jump table
  • Article tracking Trackbar ---
  • Up-down --- scroll bar
Because GM is more than the number of controls, put them into the memory and register them is a waste of memory. In addition to "RTF text editor" outside the control of other controls are placed on the executable code in comctl32.dll, so other applications can use them. "RTF text editor" in richedXX.dll control, because of the very complex control, so control than any other major.
Comctl32.dll to load in your application to call function InitCommonControls. InitCommonControls dynamic link library function is a function in comctl32.dll, so long as the procedure in your local reference any of the function on, the procedure will make WINDOWS Loader PE Loader to load the library. In fact, there is only one function InitCommonControls command "ret", its sole purpose is to make a call to the function of the executable file the application of the PE header of the "introduction" paragraph contains comctl32.dll, so no matter what when the application will load the database for you. So the real task is to initialize the library to do the entrance point, where all registered common control type, and then all of the common controls can be carried out in these types of creation, this is like the creation of other sub-window as controls.
RTF text editor control is different. If you want to use it, it is necessary to call the LoadLibrary function to dynamically load and call FreeLibrary to unload dynamically.
Now we learn how to create these common controls. You can use resource editor put them in a dialog box, or you can call the relevant function to manually create them. Almost all the common controls are calling CreateWindowEx or CreateWindow function to create and you can pass in which GM can control the class name. There are some common controls to create some special function, but in fact all these functions in-house call the CreateWindowEx, after only a function of packaging is more convenient to use it. After a function of packaging are:
  • CreateToolbarEx
  • CreateStatusWindow
  • CreatePropertySheetPage
  • PropertySheet
  • ImageList_Create
In order to create a universal control you need to know their class name, we have ranked in the following categories:
Class name
General Controls
ToolbarWindow32 Toolbar
tooltips_class32 Tooltip
msctls_statusbar32 Status bar
SysTreeView32 Tree view
SysListView32 List view
SysAnimate32 Animation
SysHeader32 Header
msctls_hotkey32 Hot-key
msctls_progress32 Progress bar
RICHEDIT Rich edit
msctls_updown32 Up-down
SysTabControl32 Tab

Property sheets, property pages and the image list control have to create their own function. Drag list can actually be stretching the listbox control, it does not have its own class name. Above the class name is vc + + of the resources provided by the editor, they and Borland's Guide to WIN32 API's are not the same, and Petzold's book "Programming Windows 95" are not the same. We can be sure that the categories listed above were absolutely accurate. These generic generic controls can be some kind of window styles, such as for example, WS_CHILD. Of course they have other specific style, such as tree-view control, there TVS_XXXXX style, style list control LVS_xxxx there. Find the best concrete the WIN32 API function guide. Since we already know how to create a common control, we can discuss these controls as well as between GM and their parent window is how communication between the. Unlike sub-window controls, common controls in some state of change but not by sending a WM_COMMAND message sent WM_NOTIFY communication and parent window. Parent window can send messages to control the behavior of sub-window. For those new generic controls, as well as some new types of information. You can refer to your manual WIN32 API.

In the example below we are going to experiment like the progress bar and status article.

Example code:

.386
. model flat, stdcall
option casemap: none
include \ masm32 \ include \ windows.inc
include \ masm32 \ include \ user32.inc
include \ masm32 \ include \ kernel32.inc
include \ masm32 \ include \ comctl32.inc
includelib \ masm32 \ lib \ comctl32.lib
includelib \ masm32 \ lib \ user32.lib
includelib \ masm32 \ lib \ kernel32.lib

WinMain PROTO: DWORD,: DWORD,: DWORD,: DWORD

. const
IDC_PROGRESS equ 1; control IDs
IDC_STATUS equ 2
IDC_TIMER equ 3

. data
ClassName db "CommonControlWinClass", 0
AppName db "Common Control Demo", 0
ProgressClass db "msctls_progress32", 0; the class name of the progress bar
Message db "Finished!", 0
TimerID dd 0

. data?
hInstance HINSTANCE?
hwndProgress dd?
hwndStatus dd?
CurrentStep dd?
. code
start:
invoke GetModuleHandle, NULL
mov hInstance, eax
invoke WinMain, hInstance, NULL, NULL, SW_SHOWDEFAULT
invoke ExitProcess, eax
invoke InitCommonControls

WinMain proc hInst: HINSTANCE, hPrevInst: HINSTANCE, CmdLine: LPSTR, CmdShow: DWORD
LOCAL wc: WNDCLASSEX
LOCAL msg: MSG
LOCAL hwnd: HWND

mov wc.cbSize, SIZEOF WNDCLASSEX
mov wc.style, CS_HREDRAW or CS_VREDRAW
mov wc.lpfnWndProc, OFFSET WndProc
mov wc.cbClsExtra, NULL
mov wc.cbWndExtra, NULL
push hInst
pop wc.hInstance
mov wc.hbrBackground, COLOR_APPWORKSPACE
mov wc.lpszMenuName, NULL
mov wc.lpszClassName, OFFSET ClassName
invoke LoadIcon, NULL, IDI_APPLICATION
mov wc.hIcon, eax
mov wc.hIconSm, eax
invoke LoadCursor, NULL, IDC_ARROW
mov wc.hCursor, eax
invoke RegisterClassEx, addr wc
invoke CreateWindowEx, WS_EX_CLIENTEDGE, ADDR ClassName, ADDR AppName, \
WS_OVERLAPPED + WS_CAPTION + WS_SYSMENU + WS_MINIMIZEBOX + WS_MAXIMIZEBOX + WS_VISIBLE, CW_USEDEFAULT, \
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, \
hInst, NULL
mov hwnd, eax
. while TRUE
invoke GetMessage, ADDR msg, NULL, 0,0
. BREAK. IF (! Eax)
invoke TranslateMessage, ADDR msg
invoke DispatchMessage, ADDR msg
. endw
mov eax, msg.wParam
ret
WinMain endp

WndProc proc hWnd: HWND, uMsg: UINT, wParam: WPARAM, lParam: LPARAM
. if uMsg == WM_CREATE
invoke CreateWindowEx, NULL, ADDR ProgressClass, NULL, \
WS_CHILD + WS_VISIBLE, 100, \
200,300,20, hWnd, IDC_PROGRESS, \
hInstance, NULL
mov hwndProgress, eax
mov eax, 1000; the lParam of PBM_SETRANGE message contains the range
mov CurrentStep, eax
shl eax, 16; the high range is in the high word
invoke SendMessage, hwndProgress, PBM_SETRANGE, 0, eax
invoke SendMessage, hwndProgress, PBM_SETSTEP, 10,0
invoke CreateStatusWindow, WS_CHILD + WS_VISIBLE, NULL, hWnd, IDC_STATUS
mov hwndStatus, eax
invoke SetTimer, hWnd, IDC_TIMER, 100, NULL; create a timer
mov TimerID, eax
. elseif uMsg == WM_DESTROY
invoke PostQuitMessage, NULL
. if TimerID! = 0
invoke KillTimer, hWnd, TimerID
. endif
. elseif uMsg == WM_TIMER; when a timer event occurs
invoke SendMessage, hwndProgress, PBM_STEPIT, 0,0; step up the progress in the progress bar
sub CurrentStep, 10
. if CurrentStep == 0
invoke KillTimer, hWnd, TimerID
mov TimerID, 0
invoke SendMessage, hwndStatus, SB_SETTEXT, 0, addr Message
invoke MessageBox, hWnd, addr Message, addr AppName, MB_OK + MB_ICONINFORMATION
invoke SendMessage, hwndStatus, SB_SETTEXT, 0,0
invoke SendMessage, hwndProgress, PBM_SETPOS, 0,0
. endif
. else
invoke DefWindowProc, hWnd, uMsg, wParam, lParam
ret
. endif
xor eax, eax
ret
WndProc endp
end start

Analysis:

    invoke WinMain, hInstance, NULL, NULL, SW_SHOWDEFAULT
    invoke ExitProcess, eax
    invoke InitCommonControls
I deliberately put InitCommonControls function after ExitProcess, so call to verify the function only to procedures in our PE executable file of the introduction of the first paragraph quoted Add comctl32.dll information. You can see that even if the function does not do anything, we have a common dialog control can still work properly.
    . if uMsg == WM_CREATE
    invoke CreateWindowEx, NULL, ADDR ProgressClass, NULL, \
    WS_CHILD + WS_VISIBLE, 100, \
    200,300,20, hWnd, IDC_PROGRESS, \
    hInstance, NULL
    mov hwndProgress, eax
Here we create a common control. Attention to the parameters in the CreateWindowEx function hWnd is the parent window handle. In addition it also specifies a generic control ID. Because we directly use the control's window handle, so there would be no use of the ID. All must have the WS_CHILD window style.
    mov eax, 1000
    mov CurrentStep, eax
    shl eax, 16
    invoke SendMessage, hwndProgress, PBM_SETRANGE, 0, eax
    invoke SendMessage, hwndProgress, PBM_SETSTEP, 10,0
In the creation of a progress bar before we set the scope of it. Default range is 0-100. If you are not satisfied, you can reset it through the transmission of information to achieve PBM_SETRANGE. LParam parameter contains a range of values, which at the end of words and high words were the beginning and the end of the scope of value. You can specify the progress bar in each frame of each moving step. This example the step set to 10, means that every message sent to a PBM_STEPIT progress, it will move the display pointer 10. Of course you can call directly PBM_SETPOS to set the progress bar on the location of the pointer. You can use the information more easily set up a progress bar.
    invoke CreateStatusWindow, WS_CHILD + WS_VISIBLE, NULL, hWnd, IDC_STATUS
    mov hwndStatus, eax
    invoke SetTimer, hWnd, IDC_TIMER, 100, NULL; create a timer
    mov TimerID, eax
We call the following to create a state of CreateStatusWindow article. Good understanding of the call, no need for me to explain. Be created in the state we create a timer. In this case, we update every 100 milliseconds on a progress bar. Create the following in mind when the time's function prototype:
    SetTimer PROTO hWnd: DWORD, TimerID: DWORD, TimeInterval: DWORD, lpTimerProc: DWORD
hWnd: parent window handle.
TimerID: timer ID. You can specify a unique non-zero value.
TimerInterval: in milliseconds time interval.
lpTimerProc: the address of the timer callback function. Whenever the time interval to time, the function will be system calls. If the value is NULL, the timer would WM_TIMER message is sent to the parent window.

If successful SetTimer call timer ID will be returned to its value, otherwise return 0. That is why the timer must be the ID number of the reasons for non-zero value.

    . elseif uMsg == WM_TIMER
    invoke SendMessage, hwndProgress, PBM_STEPIT, 0,0
    sub CurrentStep, 10
    . if CurrentStep == 0
    invoke KillTimer, hWnd, TimerID
    mov TimerID, 0
    invoke SendMessage, hwndStatus, SB_SETTEXT, 0, addr Message
    invoke MessageBox, hWnd, addr Message, addr AppName, MB_OK + MB_ICONINFORMATION
    invoke SendMessage, hwndStatus, SB_SETTEXT, 0,0
    invoke SendMessage, hwndProgress, PBM_SETPOS, 0,0
    . endif
When the specified time to time, the timer will be sent WM_TIMER news. You can deal with the message to make appropriate arrangements. This case we will update the progress bar and progress bar to check whether it exceeds the maximum value. If exceeded, we SB_SETTEXT by sending a message to be set up in the status text. At that time, pop up a dialog box when the user closes the dialog box out, we have to get rid of the progress bar and status text article.


Assembly Language Tutorial Articles


Can't Find What You're Looking For?


Rating: Not yet rated

Comments

No comments posted.