You are on page 1of 13

td_win32asm_610.

asm
;==============================================================================
;
Test Department's WINDOWS 32 BIT x86 ASSEMBLY example's
610
;==============================================================================
;==============================================================================
; ==> Part 610 : Extracting icons from a file and execute a control panel.
;-----------------------------------------------------------------------------;On WM_CREATE we create a ListView window with the LVS_REPORT and the
;LVS_SORTASCENDING style.
;We set the colors for the ListView control, set the column header and
;create an Imagelist.
;We create a Button with the WS_EX_WINDOWEDGE and WS_EX_CLIENTEDGE dwExStyle.
;
;On WM_COMMAND we test if the button is clicked and call the File Routine.
;In this routine we extract the icons from the founded files and assign it
;to the Imagelist.
;
;On WM_NOTIFY in response to a doubleclick inside the ListView window
;we execute the choosen program via API ShellExecute.
;
;An extra info from the MicroSoft help file:
;-------------------------------------------;You can set a background image to a ListView control via LVM_SETBKIMAGE.
;You must use OLE COM objects !?, where do you go today ?
;LVM_SETBKIMAGE wParam = 0, lParam = (LPARAM)(LPLVBKIMAGE) plvbki
;The list view control uses OLE/COM to manipulate the background images.
;The calling application must call CoInitialize or OleInitialize before
;sending this message. It is best to call one of these functions when the
;application is initialized and call either CoUninitialize or OleUninitialize
;when the application is terminating.
;H ?
;
;
;
; Test Department
td@crahkob.com
;==============================================================================
; Assembler directives
;-----------------------------------------------------------------------------.386
; specifies the processor our program want run on
.Model Flat ,StdCall
; always the same for Win9x (32 Bit)
option casemap:none
; case sensitive !!!
;==============================================================================
; Include all files where API functins resist you want use, set correct path
;-----------------------------------------------------------------------------includelib kernel32.lib
includelib user32.lib
includelib gdi32.lib
includelib comctl32.lib
includelib shell32.lib
;==============================================================================
Page 1

td_win32asm_610.asm
; Declaration of used API functions,take a look into WIN32.HLP and *.inc files
;-----------------------------------------------------------------------------GetModuleHandleA
PROTO :DWORD
InitCommonControls
PROTO
CreateSolidBrush
PROTO :DWORD
LoadIconA
PROTO :DWORD,:DWORD
LoadCursorA
PROTO :DWORD,:DWORD
RegisterClassExA
PROTO :DWORD
CreateWindowExA
PROTO :DWORD,:DWORD,:DWORD,:DWORD,:DWORD,:DWORD,:DWORD,
:DWORD,:DWORD,:DWORD,:DWORD,:DWORD
ShowWindow
PROTO :DWORD,:DWORD
UpdateWindow
PROTO :DWORD
GetMessageA
PROTO :DWORD,:DWORD,:DWORD,:DWORD
TranslateMessage
PROTO :DWORD
DispatchMessageA
PROTO :DWORD
PostQuitMessage
PROTO :DWORD
DefWindowProcA
PROTO :DWORD,:DWORD,:DWORD,:DWORD
ExitProcess
PROTO :DWORD
DeleteObject
SendMessageA
ExtractAssociatedIconA

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

ImageList_Create
ImageList_Destroy
ImageList_ReplaceIcon

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

GetSystemDirectoryA
ShellExecuteA
FindFirstFileA
FindNextFileA
FindClose

PROTO
PROTO
PROTO
PROTO
PROTO

lstrcpyA
lstrcatA

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

:DWORD,:DWORD
:DWORD,:DWORD,:DWORD,:DWORD,:DWORD,:DWORD
:DWORD,:DWORD
:DWORD,:DWORD
:DWORD

;==============================================================================
; .const = the constants area starts here,constants are defined and fixed
;-----------------------------------------------------------------------------.const
; - Parameter MAIN WINDOW CallBack Procedure ( API=RegisterClassExA ) WP1_CallBack
equ [ebp+4]
;return address
WP1_hWnd
equ [ebp+8]
;handle of window who receives message
WP1_uMsg
equ [ebp+12]
;the message number
WP1_wParam
equ [ebp+16]
;extra info about the message
WP1_lParam
equ [ebp+20]
;extra info about the message
;==============================================================================
; .Data = the data area starts here, datas are defined but not fixed
;-----------------------------------------------------------------------------.Data
ClassName
db "TDClass",0
;name of windows class
WindowName
db "Test Department - www.crahkob.com/td",0;name titel bar
Page 2

td_win32asm_610.asm
"open",0
;used by ShellExecute
"control.exe ",0
;control loader
"\*.cpl",0
;control to find
"BUTTON",0
;predefined ClassName !
"System",0
;button text
"SysListView32",0
;predefined className !
"Done by Test Department",0;

OpenFile
Control
WildCtrl
ButtonClassName
ButtonText
SysListView32ClassName
ColumnText

db
db
db
db
db
db
db

IconIndex

dw 0h

;WORD !!!

align 4
; - WndClassEx Structure cbSize
dd 0h
style
dd 0h
lpfnWndProc
dd 0h
cbclsExtra
dd 0h
cbWndExtra
dd 0h
hInstance
dd 0h
hIcon
dd 0h
hcursor
dd 0h
hbrBackground
dd 0h
lpszMenuName
dd 0h
lpszClassName
dd 0h
hIconSm
dd 0h

;size in bytes of this structure


;window style
;address of user proc function
;extra bytes to allocate set to 0
;extra bytes class directive, rc file
;program handle(API=GetModuleHandleA)
;handle of icon (API=LoadIconA)
;handle of cursor (API=LoadCursor)
;background color, 0=transparent
;name of menu class in resource file
;name of windows this window class
;iconhandle 0=search in resource file

align 4
; - Msg Structure hWnd
message
wParam
lParam
time
xpt
ypt

;handle of window who receives message


;the message number
;extra info about the message
;extra info about the message
;time the message was posted
;cursor x-position, POINT struc
;cursor x-position, POINT struc

dd
dd
dd
dd
dd
dd
dd

0h
0h
0h
0h
0h
0h
0h

;==============================================================================
; .Data? = the data? area starts here, not defined and not fixed
;-----------------------------------------------------------------------------.data?
temp
dd ?
;vars
counter
dd ?
;
hWnd_Button
hWnd_Listview
hWnd_Imagelist

dd ?
dd ?
dd ?

;handle button
;handle listview
;handle image list

h_findfile

dd ?

;file search handle

BufferDir
BufferTmp

db 104h dup (?) ;temp buffer


db 104h dup (?) ;temp buffer

align 4
; - LV_ITEM structure Page 3

LVI_mask
LVI_iItem
LVI_iSubItem
LVI_state
LVI_stateMask
LVI_pszText
LVI_cchTextMax
LVI_iImage
LVI_lParam

dd
dd
dd
dd
dd
dd
dd
dd
dd

?
?
?
?
?
?
?
?
?

align 4
; - LV_COLUMN structure
LVC_mask
LVC_fmt
LVC_cx
LVC_pszText
LVC_cchTextMax
LVC_iSubItem

dd
dd
dd
dd
dd
dd

?
?
?
?
?
?

align 4
; - WIN32_FIND_DATA Structure dwFileAttributes
dd ?
ftCreationTime
dd ?
dd ?
ftLastAccessTime
dd ?
dd ?
ftLastWriteTime
dd ?
dd ?
nFileSizeHigh
dd ?
nFileSizeLow
dd ?
dwReserved0
dd ?
dwReserved1
dd ?
cFileName
db 104h dup (?)
cAlternateFileName
db 14 dup (?)

td_win32asm_610.asm
;look into Win32.hlp

;look into Win32.hlp

;file attributes of the file found


;FILETIME structure, file creation time
;FILETIME structure, file access time
;FILETIME structure, file write time
;high-order DWORD, file size in bytes
;low-order DWORD, file size in bytes
;reserved for future use
;reserved for future use
;null-terminated stringname of the file
;classic 8.3 (filename.ext) filename

;==============================================================================
; .CODE = our code area starts here
Main=label of our program code
;-----------------------------------------------------------------------------.Code
Main:
;==============================================================================
; Always get your program ID first (API=GetModuleHandleA)
;-----------------------------------------------------------------------------push
0h
;lpModuleHandle, 0=get program handle
call
GetModuleHandleA
;- API Function mov
hInstance,eax
;return value in eax=handle of program
;==============================================================================
; ListView class seems to be part of common controls, force to init...
;-----------------------------------------------------------------------------call
InitCommonControls
;- API Function Page 4

td_win32asm_610.asm
;==============================================================================
; The API function "RegisterClassExA" registers a window class
; This API needs a "WNDCLASSEX" structure so we fill it with correct values
;-----------------------------------------------------------------------------mov
cbSize,30h
;size in bytes of WNDCLASSEX structure
mov
style,3h
;window style, CS_HREDRAW, CS_VREDRAW
mov
lpfnWndProc,OFFSET WP1
;address of user lpfnWndProc function
mov
cbclsExtra,0h
;extra bytes to allocate set to 0
mov
cbWndExtra,0h
;class directive in rc file
mov
hbrBackground,10h
;background color
mov
lpszMenuName,0
;menu name in resource file
mov
lpszClassName,OFFSET ClassName ;name of windows class
;-----------------------------------------------------------------------------; API "LoadIconA" loads an icon defined in the resource file and store the
; handle in the "WNDCLASSEX" structure
;-----------------------------------------------------------------------------push
1000
;icon-string or icon resource id
push
hInstance
;our program handle
call
LoadIconA
;- API Function mov
hIcon,eax
;handle of newly loaded icon
mov
hIconSm,0h
;iconhandle 0=search in rc file
;-----------------------------------------------------------------------------; API "LoadCursorA" loads a default system cursor, in this case we must set
; hInstance to 0 and lpCursorName to a default system cursor value, here 32512
; Then we store the cursor handle in the "WNDCLASSEX" structure
;-----------------------------------------------------------------------------push
32512
;lpCursorName, default value in dezimal
push
0h
;hInstance, 0=default system cursor
call
LoadCursorA
;- API Function mov
hcursor,eax
;store handle of the cursor
;-----------------------------------------------------------------------------; Now, after filled the "WNDCLASSEX" structure we call API "RegisterClassEx"
;-----------------------------------------------------------------------------push
OFFSET cbSize
;pointer to WNDCLASSEX structure
call
RegisterClassExA
;- API Function ;==============================================================================
; API "CreateWindowExA" creates an overlapped, pop-up, or child window with an
; extended style. The return value in EAX is the handle of the new window.
; This API sends a WM_CREATE message to the window procedure (WP1).
;-----------------------------------------------------------------------------push
0h
;lpParam, extra pointer data 0=no data
push
hInstance
;hInstance, handle of our program
push
0h
;hMenu, handle window menu 0=class menu
push
0h
;hWndParent, handle parent window 0=no
push
1F0h
;intnHeight, window height pixel
push
0FAh
;intnWidth, window width pixel
push
60h
;inty, vertical position window
push
120h
;intx, horizontal position window
push
04CA0000h
;dwStyle, look into WIN32.HLP
push
OFFSET WindowName
;lpWindowName, pointer to window name
push
OFFSET ClassName
;lpClassName, pointer to class name
push
0100h
;dwExStyle, extra window style 0=no
Page 5

call
mov

CreateWindowExA
hWnd,eax

td_win32asm_610.asm
;- API Function ;hwnd,return value=handle of window

;==============================================================================
; API "ShowWindow" function sets the specified window's show state.
;-----------------------------------------------------------------------------push
1h
;nCmdShow, show state 1=SW_SHOWNORMAL
push
hWnd
;hwnd, handle of window
call
ShowWindow
;- API Function ;==============================================================================
; API "UpdateWindow" updates the area of the specified window by sending a
; WM_PAINT message to the window if the window's update region is not empty.
;-----------------------------------------------------------------------------push
hWnd
;hwnd, handle of window
call
UpdateWindow
;- API Function ;==============================================================================
; API "GetMessageA" retrieves a message & places it in the specified structure.
;-----------------------------------------------------------------------------LoopGetMessage:
push
0h
;wMsgFilterMax, highest message value
push
0h
;wMsgFilterMin, lowest message value
push
0h
;hWnd, handle of window who gets msg.
push
OFFSET hWnd
;lpMsg, pointer to MSG structure
call
GetMessageA
;- API Function cmp
eax,0h
;check if return value=0 (exit)
je
ExitPrg
;if return value is 0 goto LABEL
;==============================================================================
; API "TranslateMessage" translates key code into ASCII character messages
;-----------------------------------------------------------------------------push
OFFSET hWnd
;lpMSG, pointer to msg structure
call
TranslateMessage
;- API Function - keyboard code
;==============================================================================
; API "DispatchMessageA" function dispatches a message to a window procedure.
;-----------------------------------------------------------------------------push
OFFSET hWnd
;lpMSG, pointer to msg structure
call
DispatchMessageA
;- API Function jmp
LoopGetMessage
;check for message again, goto LABEL
ExitPrg:
;==============================================================================
; Next we terminate our program (API=ExitProcess)
;-----------------------------------------------------------------------------push
hInstance
;push our programm handle to exit
call
ExitProcess
;- API Function ;##############################################################################
; The Window Procedure lpfnWndProc (API=RegisterClassExA) for this window.
;-----------------------------------------------------------------------------WP1:
Page 6

push
mov
pushad

ebp
ebp,esp

td_win32asm_610.asm
;create stack frame
;
;push all register to the stack

mov
eax,WP1_uMsg
;move the message number to eax
;==============================================================================
; WM_CREATE (value=01h) message received ?
;-----------------------------------------------------------------------------WP1_uMsg_01h:
cmp
eax,1h
;check if WM_CREATE message recieved
jne
WP1_uMsg_02h
;if not goto label
;-----------------------------------------------------------------------------; API "CreateWindowExA" creates a window, predefined class name (SysListView32)
;-----------------------------------------------------------------------------push
0h
;lpParam, extra pointer data 0=no data
push
hInstance
;hInstance, handle of our program
push
200h
;hMenu, the child-window ID
push
WP1_hWnd
;hWndParent, handle parent window 0=no
push
198h
;intnHeight, window height pixel
push
0ECh
;intnWidth, window width pixel
push
8h
;inty, vertical position window
push
4h
;intx, horizontal position window
push
50000015h
;dwStyle,WS_CHILD,WS_VISIBLE,LVS_REPORT=1h,
;LVS_SINGLESEL=4h,LVS_SORTASCENDING=10h
push
0h
;lpWindowName, pointer to window name
push
OFFSET SysListView32ClassName;lpClassName, pointer to class name
push
300h
;dwExStyle, look WIN32.HLP + windows.inc
call
CreateWindowExA
;- API Function mov
hWnd_Listview,eax
;hwnd, return value=handle of window
;-----------------------------------------------------------------------------; API "SendMessageA" sets the colors of the ListView control
;-----------------------------------------------------------------------------push
0h
;lParam, color, CLR_NONE=0FFFFFFFFh
push
0h
;wParam, set to 0
push
1001h
;uMsg,LVM_FIRST=1000h|LVM_SETBKCOLOR=1
push
hWnd_Listview
;hwnd, handle of destination window
call
SendMessageA
;- API Function push
0h
;lParam, color,
push
0h
;wParam, set to 0
push
1026h
;uMsg,LVM_FIRST=1000h|LVM_SETTEXTBKCOLOR=38
push
hWnd_Listview
;hwnd, handle of window
call
SendMessageA
;- API Function push
00000D6FFh
;lParam, color
push
0h
;wParam, set to 0
push
1024h
;uMsg,LVM_FIRST=1000h | LVM_SETTEXTCOLOR=36
push
hWnd_Listview
;hwnd, handle of window
call
SendMessageA
;- API Function ;-----------------------------------------------------------------------------; API "SendMessageA" inserts a column to a ListView control
;-----------------------------------------------------------------------------mov
LVC_mask,7h
;LVCF_WIDTH=2h, LVCF_TEXT=4h, LVCF_FMT=1h
mov
LVC_fmt,0h
;LVCFMT_LEFT=0h
mov
LVC_cx,0D8h
;width of the column, in pixels
Page 7

td_win32asm_610.asm
mov
LVC_pszText,OFFSET ColumnText;pointer to text
push
OFFSET LVC_mask
;lParam, pcol, pointer LV_COLUMN structure
push
0h
;wParam, iCol, index of the new column
push
101Bh
;uMsg,LVM_FIRST=1000h | LVM_INSERTCOLUMN=27
push
hWnd_Listview
;hwnd, handle of window
call
SendMessageA
;- API Function ;-----------------------------------------------------------------------------; API "ImageList_Create" creates a new image list.
;-----------------------------------------------------------------------------push
100h
;cGrow, number of images list can grow
push
0h
;cInitial, number of images on initially
push
9h
;flags, ILC_MASK=1h, ILC_COLOR8=8h
push
10h
;cy, height of one bitmap, 20h gets big icon
push
10h
;cx, width of one bitmap, 20h gets bic icon
call
ImageList_Create
;- API Function mov
hWnd_Imagelist,eax
;
;-----------------------------------------------------------------------------; API "SendMessageA" sends a message to the window
;-----------------------------------------------------------------------------push
hWnd_Imagelist
;lParam, himl, handle image list to assign
push
1h
;wParam, iImageList, type, LVSIL_SMALL=1h
push
1003h
;uMsg,LVM_FIRST=1000h | LVM_SETIMAGELIST=3h
push
hWnd_Listview
;hwnd, handle of destination window
call
SendMessageA
;- API Function ;-----------------------------------------------------------------------------; API "CreateWindowExA" here creates a window with a predefined class (BUTTON)
;-----------------------------------------------------------------------------push
0h
;lpParam, extra pointer data 0=no data
push
hInstance
;hInstance, handle of our program
push
0100h
;hMenu, the child-window ID
push
WP1_hWnd
;hWndParent, handle parent window 0=no
push
00000020h
;intnHeight, window height pixel
push
000000ECh
;intnWidth, window width pixel
push
000001A8h
;inty, vertical position window
push
00000004h
;intx, horizontal position window
push
50000000h
;dwStyle, style ( BS_DEFPUSHBUTTON )
push
OFFSET ButtonText
;lpWindowName, pointer to window name
push
OFFSET ButtonClassName ;lpClassName, pointer to class name
push
300h
;dwExStyle,
call
CreateWindowExA
;- API Function mov
hWnd_Button,eax
;return value=handle of window
jmp
WP1_return
;==============================================================================
; WM_DESTROY (value=02h) message received ?
;-----------------------------------------------------------------------------WP1_uMsg_02h:
cmp
eax,2h
;check if value=2h (WM_DESTROY)
jne
WP1_uMsg_4Eh
;if not 2h go to LABEL
call
My_CleanSystem
;- SubRoutine ;-----------------------------------------------------------------------------; API "PostQuitMessage" indicates to Windows a request to terminate
;-----------------------------------------------------------------------------Page 8

push
call
popad
xor
mov
pop
ret

0h
PostQuitMessage
eax,eax
esp,ebp
ebp
10h

td_win32asm_610.asm
;nExitCode, exit code=wParam
;- API Function ;pop all register back from stack
;set eax to 0 to exit our program
;delete stack frame
;
;return and clear stack

;==============================================================================
; WM_NOTIFY (value=4Eh) message received ?
; With a WM_NOTIFY message Windows gives you pointer to a NMHDR structure.
;-----------------------------------------------------------------------------WP1_uMsg_4Eh:
cmp
eax,4Eh
;check if WM_NOTIFY message recieved
jne
WP1_uMsg_111h
;if not goto label
mov
ebx,WP1_lParam
;pointer to struc, given by windows !
;-----------------------------------------------------------------------------; The NMHDR structure contains information about a notification message.
; The POINTER to this structure is specified as lParam member of WM_NOTIFY.
; This POINTER is given to us with the WM_NOTIFY message by Windows.
; hwndFrom = [WP1_lParam+0]
;handle to control sending message
; idFrom
= [WP1_lParam+4]
;identifier of control sending message
; code
= [WP1_lParam+8]
;notification code
;-----------------------------------------------------------------------------mov
eax,[ebx+0]
;get the handle of the control sending msg.
cmp
eax,hWnd_Listview
;is control=ListView
jne
WP1_return
;
mov
eax,[ebx+8]
;get the notification code
cmp
eax,0FFFFFFFDh
;NM_DBLCLK, NMFIRST=0-0-3
je
WM_Notify_Action
;
cmp
eax,0FFFFFFFCh
;NM_RETURN, NMFIRST=0-0-4
jne
WP1_return
;
WM_Notify_Action:
;-----------------------------------------------------------------------------; API "SendMessageA" sends a message to the window
;-----------------------------------------------------------------------------push
2h
;lParam,LVNI_ALL=0,LVNI_FOCUSED=1,LVNI_SELECTED=2
push
-1
;wParam,index item begin search or -1 first
push
100Ch
;uMsg, LVM_FIRST=1000h | LVM_GETNEXTITEM=12
push
hWnd_Listview
;hwnd, handle of destination window
call
SendMessageA
;- API Function cmp
eax,-1
;error=-1
je
WP1_return
;exit
mov
LVI_iSubItem,0h
;
mov
LVI_pszText,OFFSET BufferTmp;
mov
LVI_cchTextMax,104h
;
;-----------------------------------------------------------------------------; API "SendMessageA" sends a message to the window
;-----------------------------------------------------------------------------push
OFFSET LVI_mask ;lParam, pcol, pointer LV_ITEM structure
push
eax
;wParam, Index of the list view item
push
102Dh
;uMsg, LVM_FIRST=1000h | LVM_GETITEMTEXT=45
push
hWnd_Listview
;hwnd, handle of destination window
Page 9

td_win32asm_610.asm
call
SendMessageA
;- API Function cmp
eax,0h
;error ?, NULL string
je
WP1_return
;exit
;-----------------------------------------------------------------------------; API "ShellExecute" opens or prints a specified file, executable or a document
;-----------------------------------------------------------------------------push
1h
;nShowCmd, whether file is shown, SW_SHOWNORMAL
push
OFFSET BufferDir
;lpDirectory, pointer string default directory
push
OFFSET BufferTmp
;lpParameters, pointer to exe-file parameters
push
OFFSET Control
;lpFile, pointer to filename string
push
OFFSET OpenFile
;lpOperation, specifies operation to perform
push
WP1_hWnd
;hwnd, handle to parent window
call
ShellExecuteA
;- API Function jmp
WP1_return
;==============================================================================
; WM_COMMAND (value=111h) message recieved ?
;-----------------------------------------------------------------------------WP1_uMsg_111h:
cmp
eax,111h
;check if WM_COMMAND message recieved
jne
WP1_uMsg_112h
;if not goto label
mov
eax,WP1_wParam
;
and
eax,0FFFFh
;get item, control, or accelerator identifier
cmp
eax,0100h
;Button id
jne
WP1_return
call
My_GetFileControls ;- SubRoutine - read system dir and extract icons
jmp
WP1_return
;==============================================================================
; WM_SYSCOMMAND (value=112h) message recieved ?
;-----------------------------------------------------------------------------WP1_uMsg_112h:
cmp
eax,112h
;check if WM_COMMAND message recieved
jne
WP1_return
;if not goto label
mov
eax,WP1_wParam
;extra info about the message
cmp
eax,0F060h
;SC_CLOSE=0F060h received ?
jne
WP1_return
;
call
My_CleanSystem
;- SubRoutine jmp
WP1_return
;==============================================================================
; API "DefWindowProcA" calls the window procedure to provide default processing
; for any window messages that an application does not process.
; This function ensures that every message is processed.
; It is called with the same parameters received by the window procedure.
;-----------------------------------------------------------------------------WP1_return:
popad
;pop all register from stack
push
WP1_lParam
;extra info about the message
push
WP1_wParam
;extra info about the message
push
WP1_uMsg
;the message number
push
WP1_hWnd
;handle of window who receives message
call
DefWindowProcA ;- API Function Page 10

td_win32asm_610.asm
mov
esp,ebp
;delete stack frame
pop
ebp
;
ret
10h
;return and clear stack
;##############################################################################
;******************************************************************************
; My own subroutine(s) for a compacter code resist here ...
;-----------------------------------------------------------------------------My_CleanSystem:
;-----------------------------------------------------------------------------; API "ImageList_Destroy" destroys an image list.
;-----------------------------------------------------------------------------push
hWnd_Imagelist
;nExitCode, exit code=wParam
call
ImageList_Destroy
;- API Function ret
My_GetFileControls:
;-----------------------------------------------------------------------------; API "GetSystemDirectory" retrieves the path of the Windows system directory.
;-----------------------------------------------------------------------------push
104h
;uSize, size of directory buffer
push
OFFSET BufferDir
;lpBuffer, address of buffer for system directory
call
GetSystemDirectoryA
;- API Function ;-----------------------------------------------------------------------------; API "lstrcat" appends one string to another.
;-----------------------------------------------------------------------------push
OFFSET WildCtrl
;lpString2, address string to add to string1
push
OFFSET BufferDir
;lpString1, buffer for concatenated strings
call
lstrcatA
;- API Function ;-----------------------------------------------------------------------------; API "SendMessageA" inserts a column to a ListView control
;-----------------------------------------------------------------------------mov
LVC_mask,5h
;LVCF_TEXT=4h, LVCF_FMT=1h
mov
LVC_fmt,0h
;LVCFMT_LEFT=0h
mov
LVC_pszText,OFFSET BufferDir;pointer to text
push
OFFSET LVC_mask
;lParam, pcol, pointer LV_COLUMN structure
push
0h
;wParam, iCol, index of the new column
push
101Ah
;uMsg,LVM_FIRST=1000h | LVM_SETCOLUMN=26
push
hWnd_Listview
;hwnd, handle of window
call
SendMessageA
;- API Function ;-----------------------------------------------------------------------------; API "SendMessageA" sends a message to the window
;-----------------------------------------------------------------------------push
0h
;lParam, set to 0
push
0h
;wParam, set to 0
push
1009h
;uMsg,LVM_FIRST=1000h|LVM_DELETEALLITEMS=9
push
hWnd_Listview
;hwnd, handle of destination window
call
SendMessageA
;- API Function mov
temp,0h
;var,
mov
counter,0h
;var,
;-----------------------------------------------------------------------------; API "FindFirstFile" searches a directory for a file whose name matches the
; specified filename. It examines subdirectory names as well as filenames.
Page 11

td_win32asm_610.asm
;-----------------------------------------------------------------------------push
OFFSET dwFileAttributes
;lpFindFileData, address of returned infos
push
OFFSET BufferDir
;lpFileName, name of file to search for
call
FindFirstFileA
;- API Function mov
h_findfile,eax
;handle
cmp
eax,-1
;INVALID_HANDLE_VALUE=-1
je
My_GetFileControls_Return
;exit
My_GetFileControls_Loop:
and
dwFileAttributes,10h
;FILE_ATTRIBUTE_DIRECTORY=10h
jne
My_GetFileControls_Next
;goto label if a directory
;-----------------------------------------------------------------------------; API "lstrcpyA" copy's a string from source to destination.
;-----------------------------------------------------------------------------push
OFFSET cFileName
;source address of string
push
OFFSET BufferTmp
;destination address of string
call
lstrcpyA
;- API Function mov
LVI_mask,1h
;LVIF_TEXT=1h
mov
IconIndex,0h
;reset IconIndex
;-----------------------------------------------------------------------------; API "ExtractAssociatedIcon" returns the handle of an indexed icon found in a
; file or an icon found in an associated executable file.
;-----------------------------------------------------------------------------push
OFFSET IconIndex
;lpiIcon, pointer to icon index, WORD
push
OFFSET BufferTmp
;lpIconPath, path + filename of file wanted
push
hInstance
;hInst, application instance handle
call
ExtractAssociatedIconA ;- API Function mov
temp,eax
;
cmp
eax,0h
;if 0 no associated icon found
je
My_GetFileControls_Icon ;goto label
;-----------------------------------------------------------------------------; API "ImageList_ReplaceIcon" replaces an image with an icon or cursor.
;-----------------------------------------------------------------------------push
eax
;hicon, icon or cursor handle for the new image
push
-1
;i, index of the image to replace, -1 (!?)
push
hWnd_Imagelist
;himl, handle to the image list
call
ImageList_ReplaceIcon
;- API Function mov
LVI_iImage,eax
;founded icon, eax=index image
;-----------------------------------------------------------------------------; API "DeleteObject" deletes a bitmap freeing all associated system resources
;-----------------------------------------------------------------------------push
temp
;hObject, handle of graphic object
call
DeleteObject
;- API Function or
LVI_mask,2h
;LVIF_IMAGE=2h
My_GetFileControls_Icon:
mov
ebx,OFFSET cFileName
;pointer to dirname/filename found
mov
LVI_pszText,ebx
;pointer to text
mov
LVI_iSubItem,0h
;not a SubItem
mov
eax,counter
;temp var
mov
LVI_iItem,eax
;index of item
;-----------------------------------------------------------------------------; API "SendMessageA" sends a message to the window
;-----------------------------------------------------------------------------push
OFFSET LVI_mask
;lParam, pcol, pointer LV_ITEM structure
Page 12

td_win32asm_610.asm
push
0h
;wParam, set to 0
push
1007h
;uMsg, LVM_FIRST=1000h | LVM_INSERTITEM=7
push
hWnd_Listview
;hwnd, handle of destination window
call
SendMessageA
;- API Function inc
counter
;
My_GetFileControls_Next:
;-----------------------------------------------------------------------------; API "FindNextFile" continues file search from previous call to FindFirstFile
;-----------------------------------------------------------------------------push
OFFSET dwFileAttributes ;lpFindFileData, address of returned infos
push
h_findfile
;hFindFile, handle of search
call
FindNextFileA
;- API Function cmp
eax,1h
;success ?
je
My_GetFileControls_Loop ;loop
My_GetFileControls_Return:
;-----------------------------------------------------------------------------; API "FindClose" closes the specified search handle.
;-----------------------------------------------------------------------------push
h_findfile
;hFindFile, handle of search
call
FindClose
;- API Function ret
;******************************************************************************
;==============================================================================
; end Main = end of our program code
;-----------------------------------------------------------------------------end Main
;end of our program code, entry point
;==============================================================================
; To create the exe file use this commands with your Microsoft Assembler/Linker
;-----------------------------------------------------------------------------; ml.exe /c /coff td_win32asm_610.asm
;asm command
; rc.exe /v rsrc.rc
;rc command
; cvtres.exe /machine:ix86 rsrc.res
; link.exe /subsystem:windows td_win32asm_610.obj rsrc.obj ;link command
;==============================================================================

Page 13

You might also like