You are on page 1of 14

td_win32asm_015.

asm
;==============================================================================
;
Test Department's WINDOWS 32 BIT x86 ASSEMBLY example
015
;==============================================================================
;==============================================================================
; ==> Part 015 : ListView class and Clipboard usuage
;-----------------------------------------------------------------------------; Hello,
; today you are on your own.
;
; Test Department
td@crahkob.com
;==============================================================================
; Assembler directives
;-----------------------------------------------------------------------------.386
; specifies the processor our program want run on
.Model Flat ,StdCall
; Flat for Win9x (32 Bit), Calling Convention
option casemap:none
; case sensitive !
;==============================================================================
; Include all files where API functins resist you want use, set correct path
;-----------------------------------------------------------------------------include D:\Masm32\include\windows.inc
includelib kernel32.lib
includelib user32.lib
includelib comctl32.lib
;==============================================================================
; Declaration of used API functions,take a look into WIN32.HLP and *.inc files
;-----------------------------------------------------------------------------GetModuleHandleA
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
DestroyWindow
PROTO :DWORD
SendMessageA
PROTO :DWORD,:DWORD,:DWORD,:DWORD
SetFocus
PROTO :DWORD
lstrcpy
PROTO :DWORD,:DWORD
InvalidateRect
PROTO :DWORD,:DWORD,:DWORD
InitCommonControls
PROTO
CreatePopupMenu
AppendMenuA

PROTO
PROTO :DWORD,:DWORD,:DWORD,:DWORD
Page 1

GetCursorPos
TrackPopupMenuEx
DestroyMenu

td_win32asm_015.asm
PROTO :DWORD
PROTO :DWORD,:DWORD,:DWORD,:DWORD,:DWORD,:DWORD
PROTO :DWORD

GlobalAlloc
GlobalLock
GlobalUnlock
GlobalFree

PROTO
PROTO
PROTO
PROTO

OpenClipboard
EmptyClipboard
SetClipboardData
CloseClipboard

PROTO :DWORD
PROTO
PROTO :DWORD,:DWORD
PROTO

: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
IconName
db "TDIcon",0
;icon name in resource
Class
db "TDWinClass",0
;name of window class
WindowName
db "Test Department - http://surf.to/TestD",0
class_SysListView32
db "SysListView32",0
;predefined class
Column0
Column1
Column2
Column3
Item0
Item1
SubItem01
SubItem02
SubItem03

db
db
db
db
db
db
db
db
db

"Column 0",0
"Column 1",0
"Column 2",0
"Column 3",0
"Main Item 0",0
"Main Item 1",0
"SubItem 01",0
"SubItem 02",0
"SubItem 03",0

;
;
;
;
;
;
;
;
;

MenuItem_Copy
MenuItem_Cancel

db "Copy to Clipboard",0;
db "Cancel",0
;

;==============================================================================
; .Data?
= the data? area starts here, not defined and not fixed
;-----------------------------------------------------------------------------.data?
hWnd_ListView
dd ?
;handle listbox window,
hPopup
dd ?
;handle popup menu
Page 2

h_Memory
p_Memory
Buffer

td_win32asm_015.asm
dd ?
;handle global memory object
dd ?
;pointer global memory
db 104h dup (?) ;buffer

align 4
; - WndClassEx Structure ( API=RegisterClassExA ) cbSize
dd ?
;size in bytes of this structure
style
dd ?
;window style
lpfnWndProc
dd ?
;address of user proc function
cbclsExtra
dd ?
;extra bytes to allocate set to 0
cbWndExtra
dd ?
;extra bytes class directive, rc file
hInstance
dd ?
;program handle(API=GetModuleHandleA)
hIcon
dd ?
;handle of icon (API=LoadIconA)
hcursor
dd ?
;handle of cursor (API=LoadCursor)
hbrBackground
dd ?
;background color, 0=transparent
lpszMenuName
dd ?
;name of menu class in resource file
lpszClassName
dd ?
;name of windows this window class
hIconSm
dd ?
;iconhandle 0=search in resource file
hdcDest
dd ?
;handle of dest. device context
align 4
; - Msg Structure ( API=GetMessageA ) - member POINT = POINT structure
hWnd
dd ?
;handle of window who receives message
message
dd ?
;the message number
wParam
dd ?
;extra info about the message
lParam
dd ?
;extra info about the message
time
dd ?
;time the message was posted
xpt
dd ?
;cursor x-position, POINT struc
ypt
dd ?
;cursor x-position, POINT struc
align 4
; - _LV_COLUMN structure LVC_mask
dd ?
LVC_fmt
dd ?
LVC_cx
dd ?
LVC_pszText
dd ?
LVC_cchTextMax
dd ?
LVC_iSubItem
dd ?
align 4
; - _LV_ITEM structure LVI_mask
dd ?
LVI_iItem
dd ?
LVI_iSubItem
dd ?
LVI_state
dd ?
LVI_stateMask
dd ?
LVI_pszText
dd ?
LVI_cchTextMax
dd ?
LVI_iImage
dd ?
LVI_lParam
dd ?

;look into Win32.hlp

;look into Win32.hlp

;==============================================================================
; .CODE
= our code area starts here
Main = label of our program code
Page 3

td_win32asm_015.asm
;-----------------------------------------------------------------------------.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 ;==============================================================================
; 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
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,0h
;menu name in resource file,0=no menu
mov
lpszClassName,OFFSET Class ;name of windows class
mov
hIconSm,0h
;iconhandle 0=search in rc file
;-----------------------------------------------------------------------------; API "LoadIconA" loads an icon defined in the resource file and stores the
; handle in the "WNDCLASSEX" structure
;-----------------------------------------------------------------------------push
OFFSET IconName
;icon-string or icon resource id
push
hInstance
;our program handle
call
LoadIconA
;- API Function mov
hIcon,eax
;store handle of newly loaded icon
;-----------------------------------------------------------------------------; 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 ;==============================================================================
Page 4

td_win32asm_015.asm
; 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
074h
;intnHeight, window height pixel
push
1D6h
;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 Class
;lpClassName, pointer to class name
push
0100h
;dwExStyle, extra window style 0=no
call
CreateWindowExA
;- API Function mov
hWnd,eax
;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 LoopGetMessage:
;==============================================================================
; API "GetMessageA" retrieves a message + places it in the specified structure.
;-----------------------------------------------------------------------------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 virtual-key messages in 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.
Page 5

td_win32asm_015.asm
;-----------------------------------------------------------------------------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 (API=RegisterClassExA) for this registered window.
;-----------------------------------------------------------------------------WP1:
push
ebp
;create stack frame
mov
ebp,esp
;
pushad
;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)
; The return value in EAX is the handle of the new window.
;-----------------------------------------------------------------------------push
0h
;lpParam, extra pointer data 0=no data
push
hInstance
;hInstance, handle of our program
push
500h
;hMenu, the child-window ID
push
WP1_hWnd
;hWndParent, handle parent window 0=no
push
48h
;intnHeight, window height pixel
push
1C8h
;intnWidth, window width pixel
push
08h
;inty, vertical position window
push
4h
;intx, horizontal position window
push
54000005h
;dwStyle, LVS_SINGLESEL=4h | LVS_REPORT=1h
push
0h
;lpWindowName, pointer to window name
push
OFFSET class_SysListView32 ;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
push
0h
;wParam, set to 0
push
1001h
;uMsg,LVM_FIRST=1000h|LVM_SETBKCOLOR=1
push
hWnd_ListView
;hwnd, handle of destination window
Page 6

call
push
push
push
push
call
push
push
push
push
call

SendMessageA
0h
0h
1026h
hWnd_ListView
SendMessageA
00000D6FFh
0h
1024h
hWnd_ListView
SendMessageA

td_win32asm_015.asm
;- API Function ;lParam, color
;wParam, set to 0
;uMsg,LVM_FIRST=1000h|LVM_SETTEXTBKCOLOR=38
;hwnd, handle of window
;- API Function ;lParam, color
;wParam, set to 0
;uMsg,LVM_FIRST=1000h | LVM_SETTEXTCOLOR=36
;hwnd, handle of window
;- 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,0ACh
;width of the column, in pixels
mov
LVC_pszText,OFFSET Column0 ;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 mov
LVC_cx,058h
;width of the column, in pixels
mov
LVC_pszText,OFFSET Column1 ;pointer to text
push
OFFSET LVC_mask
;lParam, pcol, pointer LV_COLUMN structure
push
1h
;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 mov
LVC_cx,058h
;width of the column, in pixels
mov
LVC_pszText,OFFSET Column2 ;pointer to text
push
OFFSET LVC_mask
;lParam, pcol, pointer LV_COLUMN structure
push
2h
;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 mov
LVC_cx,058h
;width of the column, in pixels
mov
LVC_pszText,OFFSET Column3 ;pointer to text
push
OFFSET LVC_mask
;lParam, pcol, pointer LV_COLUMN structure
push
3h
;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 "SendMessageA" inserts an item to the ListView control
;-----------------------------------------------------------------------------mov
LVI_mask,1h
;LVIF_TEXT=1h
mov
LVI_iItem,0h
;item number
mov
LVI_iSubItem,0h
;no subitem
mov
LVI_pszText,OFFSET Item0
;pointer to text
Page 7

push
push
push
push
call
mov
mov
push
push
push
push
call

OFFSET LVI_mask
0h
1007h
hWnd_ListView
SendMessageA
LVI_iItem,1h
LVI_pszText,OFFSET Item1
OFFSET LVI_mask
0h
1007h
hWnd_ListView
SendMessageA

td_win32asm_015.asm
;lParam, pcol, pointer LV_ITEM structure
;wParam, set to 0
;uMsg, LVM_FIRST=1000h | LVM_INSERTITEM=7
;hwnd, handle of window
;- API Function ;item number
;pointer to text
;lParam, pcol, pointer LV_ITEM structure
;wParam, set to 0
;uMsg, LVM_FIRST=1000h | LVM_INSERTITEM=7
;hwnd, handle of window
;- API Function -

;-----------------------------------------------------------------------------; API "SendMessageA" inserts a subitem to the ListView control


;-----------------------------------------------------------------------------mov
LVI_mask,1h
;LVIF_TEXT=1h
mov
LVI_iItem,0h
;item number
mov
LVI_iSubItem,1h
;subitem number
mov
LVI_pszText,OFFSET SubItem01;pointer to text
push
OFFSET LVI_mask
;lParam, pointer to LV_ITEM structure
push
0h
;wParam, set to 0
push
1006h
;uMsg, LVM_FIRST=1000h | LVM_SETITEM=6
push
hWnd_ListView
;hwnd, handle of destination window
call
SendMessageA
;- API Function mov
LVI_iSubItem,2h
;subitem number
mov
LVI_pszText,OFFSET SubItem02;pointer to text
push
OFFSET LVI_mask
;lParam, pointer to LV_ITEM structure
push
0h
;wParam, set to 0
push
1006h
;uMsg, LVM_FIRST=1000h | LVM_SETITEM=6
push
hWnd_ListView
;hwnd, handle of destination window
call
SendMessageA
;- API Function mov
LVI_iSubItem,3h
;subitem number
mov
LVI_pszText,OFFSET SubItem03;pointer to text
push
OFFSET LVI_mask
;lParam, pointer to LV_ITEM structure
push
0h
;wParam, set to 0
push
1006h
;uMsg, LVM_FIRST=1000h | LVM_SETITEM=6
push
hWnd_ListView
;hwnd, handle of destination window
call
SendMessageA
;- API Function ;-----------------------------------------------------------------------------; API "SendMessageA" ensures that the selected item is visible
;-----------------------------------------------------------------------------push
0h
;lParam, fPartialOK, TRUE or FALSE
push
0h
;wParam, i, index of the list view item
push
1013h
;uMsg, LVM_FIRST=1000h|LVM_ENSUREVISIBLE=19
push
hWnd_ListView
;hwnd, handle of destination window
call
SendMessageA
;- API Function mov
LVI_state,3h
;
mov
LVI_stateMask,3h
;
;-----------------------------------------------------------------------------; API "SendMessageA" sets the selected item state
;-----------------------------------------------------------------------------Page 8

td_win32asm_015.asm
push
OFFSET LVI_mask
;lParam, pointer to LV_ITEM structure
push
0h
;wParam, index of the list view item
push
102Bh
;uMsg,LVM_FIRST=1000h | LVM_SETITEMSTATE=43
push
hWnd_ListView
;hwnd, handle of destination window
call
SendMessageA
;- API Function ;-----------------------------------------------------------------------------; API "SetFocus" sets the keyboard focus to the specified window.
;-----------------------------------------------------------------------------push
hWnd_ListView
;hwnd, handle of window to receive focus
call
SetFocus
;- API Function ;-----------------------------------------------------------------------------; API "CreatePopupMenu" creates an empty popup menu
;-----------------------------------------------------------------------------call
CreatePopupMenu
;- API Function mov
hPopup,eax
;return value=handle of popup menu
;-----------------------------------------------------------------------------; API "AppendMenuA" appends a new menu item to the end of the specified menu
; uIDNewItem --> menu items ID's are a free value of your choice
;-----------------------------------------------------------------------------push
OFFSET MenuItem_Copy
;lpNewItem, menu item content
push
01h
;uIDNewItem,menu item id or menu handle
push
0h
;uFlags, menu item flags, 0h=MF_STRING
push
hPopup
;hMenu, handle of popup menu
call
AppendMenuA
;- API Function push
OFFSET MenuItem_Cancel
;lpNewItem, menu item content
push
02h
;uIDNewItem,menu item id or menu handle
push
0h
;uFlags, menu item flags, 0h=MF_STRING
push
hPopup
;hMenu, handle of popup menu
call
AppendMenuA
;- API Function 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
;-----------------------------------------------------------------------------push
0h
;nExitCode, exit code=wParam
call
PostQuitMessage
;- API Function popad
;pop all register back from stack
xor
eax,eax
;set eax to 0 to exit our program
mov
esp,ebp
;delete stack frame
pop
ebp
;
ret
10h
;return and clear stack
;==============================================================================
; WM_NOTIFY (value=4Eh) message
; With a WM_NOTIFY message Windows gives you pointer to a NMHDR structure.
;-----------------------------------------------------------------------------Page 9

td_win32asm_015.asm
WP1_uMsg_4Eh:
cmp
eax,4Eh
;check if WM_NOTIFY message recieved
jne
WP1_uMsg_7Eh
;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.
; - NMHDR structure ; 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
;
;-----------------------------------------------------------------------------; The NM_LISTVIEW structure contains infos about a list view notification msg.
; - NM_LISTVIEW structure ; hdr
= placeholder for NMHDR ;required for all WM_NOTIFY messages
; iItem
= [WP1_lParam+12]
;list view item, or -1 if not used
; iSubItem = [WP1_lParam+16]
;subitem, or zero if none
; uNewState = [WP1_lParam+20]
;new item state, if not used 0
; uOldState = [WP1_lParam+24]
;old item state, if not used 0
; uChanged = [WP1_lParam+28]
;item attributes that have changed
; ptAction = [WP1_lParam+32]
;location event occurred, POINT structure
;
= [WP1_lParam+36]
;ypos, POINT structure
; lParam
= [WP1_lParam+40]
;32 bit value
;-----------------------------------------------------------------------------mov
eax,[ebx+8]
;move code ( NMHDR structure ) into eax
cmp
eax,0FFFFFF94h
;is code LVN_FIRST | LVN_COLUMNCLICK
jne
WP1_return
;if not skip
;-----------------------------------------------------------------------------; API "SendMessageA" sends a message to the main window procedure
;-----------------------------------------------------------------------------push
1h
;lParam, LVNI_FOCUSED=1h, LVNI_SELECTED=2h
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 mov
ecx,[ebx+16]
;subitem, or zero if none
mov
LVI_iSubItem,ecx
;
mov
LVI_pszText,OFFSET Buffer
;buffer receiving text
mov
LVI_cchTextMax,60h
;max size of buffer
;-----------------------------------------------------------------------------; API "SendMessageA" sends a message to the main window procedure
;-----------------------------------------------------------------------------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 window
call
SendMessageA
;- API Function Page 10

td_win32asm_015.asm
cmp
eax,0h
;error ?, NULL string
je
WP1_return
;skip on error
;-----------------------------------------------------------------------------; API "SetFocus" sets the keyboard focus to the specified window.
;-----------------------------------------------------------------------------push
hWnd_ListView
;hwnd, handle of window to receive focus
call
SetFocus
;- API Function ;-----------------------------------------------------------------------------; API "GetCursorPos" retrieves the cursor's position, in screen coordinates.
;-----------------------------------------------------------------------------push
OFFSET xpt
;pointer to POINT structure
call
GetCursorPos
;- API Function ;-----------------------------------------------------------------------------; API "TrackPopupMenuEx" displays a floating pop-up menu at the specified
; location and tracks the selection of items on the pop-up menu.
; The floating pop-up menu can appear anywhere on the screen.
;-----------------------------------------------------------------------------push
0h
;lptpm,Pointer TPMPARAMS structure,0=no
push
WP1_hWnd
;hWnd, handle of owner window
push
ypt
;y, vertical position
push
xpt
;x, horizontal position
push
0
;fuFlags, TPM_RIGHTALIGN=8,TPM_LEFTBUTTON=0
push
hPopup
;handle of popup menu
call
TrackPopupMenuEx
;- API Function jmp
WP1_return
;==============================================================================
; WM_DISPLAYCHANGE (value=7Eh) message, used to repaint the window area
;-----------------------------------------------------------------------------WP1_uMsg_7Eh:
cmp
eax,7Eh
;check if WM_DISPLAYCHANGE message recieved
jne
WP1_uMsg_111h
;if not goto label
;-----------------------------------------------------------------------------; API "InvalidateRect" adds a rectangle to specified window's update region.
; This function performs a WM_PAINT message.
;-----------------------------------------------------------------------------push
0h
;bErase, erase-background flag
push
0h
;lpRect, rect structure, 0h=client area
push
WP1_hWnd
;hWnd, handle window update region
call
InvalidateRect
;- 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
;extra info about the message in ax
cmp
ax,1h
;check if Copy to Clipboard selected
jne
WP1_return
;if not skip
;-----------------------------------------------------------------------------; API "CloseClipboard" closes the clipboard.
Page 11

td_win32asm_015.asm
;-----------------------------------------------------------------------------call
CloseClipboard
;- API Function ;-----------------------------------------------------------------------------; API "OpenClipboard" opens the clipboard for examination and prevents other
; applications from modifying the clipboard content.
;-----------------------------------------------------------------------------push
WP1_hWnd
;hwnd, handle of window opening clipboard
call
OpenClipboard
;- API Function cmp
eax,0h
;error ?
je
WP1_return
;
;-----------------------------------------------------------------------------; API "GlobalAlloc" allocates the specified number of bytes
;-----------------------------------------------------------------------------push
104h
;dwBytes,number of bytes to allocate
push
2h
;uFlags, alloc attributes, GMEM_MOVEABLE=2h
call
GlobalAlloc
;- API Function mov
h_Memory,eax
;store handle memory in variable
;-----------------------------------------------------------------------------; API "GlobalLock" locks a global memory object and returns a pointer.
;-----------------------------------------------------------------------------push
h_Memory
;hMem, handle of the global memory object
call
GlobalLock
;- API Function mov
p_Memory,eax
;pointer to global memory
;-----------------------------------------------------------------------------; API "lstrcpy" copies a string to a buffer
;-----------------------------------------------------------------------------push
OFFSET Buffer
;lpString2, address of string to copy
push
eax
;lpString1, address of buffer
call
lstrcpy
;- API Function ;-----------------------------------------------------------------------------; API "EmptyClipboard" empties clipboard and frees handles to data in clipboard
;-----------------------------------------------------------------------------call
EmptyClipboard
;- API Function ;-----------------------------------------------------------------------------; API "GlobalUnlock" decrements the lock count associated with a memory object
; that was allocated with the GMEM_MOVEABLE flag.
;-----------------------------------------------------------------------------push
h_Memory
;hMem, handle to the global memory object
call
GlobalUnlock
;- API Function ;-----------------------------------------------------------------------------; API "SetClipboardData" places data on clipboard in specified clipboard format
;-----------------------------------------------------------------------------push
h_Memory
;hData, data handle
push
1h
;uFormat, clipboard format, CF_TEXT=1h
call
SetClipboardData
;- API Function ;-----------------------------------------------------------------------------; API "CloseClipboard" closes the clipboard.
;-----------------------------------------------------------------------------call
CloseClipboard
;- API Function ;-----------------------------------------------------------------------------; API "SetFocus" sets the keyboard focus to the specified window.
;-----------------------------------------------------------------------------push
hWnd_ListView
;hwnd, handle of window to receive focus
Page 12

td_win32asm_015.asm
call
jmp

SetFocus
WP1_return

;- API Function -

;==============================================================================
; 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 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 "DestroyMenu" destroys the given menu and frees the memory
;-----------------------------------------------------------------------------push
hPopup
;hwnd, handle of window to destroy
call
DestroyWindow
;- API Function ;-----------------------------------------------------------------------------; API "DestroyWindow" destroys the given window
;-----------------------------------------------------------------------------push
hWnd_ListView
;hwnd, handle of window to destroy
call
DestroyWindow
;- API Function ret
;******************************************************************************
;==============================================================================
; end Main
= end of our program code
;-----------------------------------------------------------------------------Page 13

end Main

td_win32asm_015.asm
;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_015.asm
;asm command
; rc.exe /v rsrc.rc
;rc command
; cvtres.exe /machine:ix86 rsrc.res
; link.exe /subsystem:windows td_win32asm_015.obj rsrc.obj
;link command
;==============================================================================

Page 14

You might also like