I was converting some VB code and couldn't find anything here that was what I was looking for so, here I will show how to modify the GetOpenFileName dialog box to include a ListView and upon file click, populate the listview with the selected files icon and resource name. It is not really commented if any, but it shouldn't be too bad, I will try to explain as we go:

Pick a button and on that button click call DoIt
If a varible is not local, then it is global
hHeap is obtained from GetProcessHeap
here they are:


ofn OPENFILENAME <?>
hd DWORD ?
m_hDlg DWORD ?
m_hwnd DWORD ?
tR RECT <?>
tTR RECT <?>
wLp POINT <?>
DlgFilePath BYTE MAX_PATH + 1 dup (?)
hHeap DWORD ?

Sorry if I missed any



IS_INTRESOURCE proc IcoID:DWORD
mov eax, IcoID
shr eax, 16
ret
IS_INTRESOURCE endp
[/code

[code]
DoIt proc
mov ofn.lStructSize, sizeof OPENFILENAME
push hMain
pop ofn.hwndOwner
push hInst
pop ofn.hInstance
mov ofn.lpstrFilter, offset DlgFilter
mov ofn.lpstrTitle, offset DlgTitle
mov ofn.Flags, OFN_FILEMUSTEXIST\
Or OFN_PATHMUSTEXIST\
Or OFN_HIDEREADONLY\
or OFN_ENABLEHOOK\
or OFN_EXPLORER
mov ofn.lpfnHook, offset ProcDlgHook

push offset ofn
call GetOpenFileName

push -1
push imlDlgLrg
call ImageList_Remove

push 0
push 0
push LVM_DELETEALLITEMS
push hLVDlg
call SendMessage

ret
DoIt endp
[/code]
Next we need are callback proc which will handle the dialog messages and initialization
[code]
ProcDlgHook proc hDlg:HWND, uiMsg:UINT, wParam:WPARAM, lParam:LPARAM

cmp uiMsg, WM_INITDIALOG
je _INITDIALOG
cmp uiMsg, WM_NOTIFY
je _NOTIFY

PassThrough:
xor eax, eax
ret

_NOTIFY:
mov eax, wParam
cmp eax, 59 ; check to see if message is from our listview first
je LVMsg

; Not from listview, so continue
mov eax, lParam
mov ecx, .NMHDR.code
cmp ecx, CDN_SELCHANGE
je @F
cmp ecx, CDN_FILEOK
je FileOk
cmp ecx, CDN_FOLDERCHANGE
je FolderChange
cmp ecx, CDN_TYPECHANGE
je TypeChange
jmp PassThrough

@@:
push 0
push MAX_PATH + 1
push offset DlgFilePath
call memfill

push hDlg
call GetParent
mov m_hwnd, eax

push offset DlgFilePath
push MAX_PATH + 1
push CDM_GETFILEPATH
push m_hwnd
call SendMessage

call ShowIcons
jmp PassThrough

FileOk:
; On file click, we want dialog to stay open
push TRUE
push DWL_MSGRESULT
push hDlg
call SetWindowLong

mov eax, TRUE
ret

FolderChange:
jmp PassThrough

TypeChange:
jmp PassThrough

LVMsg:
mov eax, lParam
mov ecx, .NMHDR.code
cmp ecx, LVN_ITEMCHANGING
je @F
jmp PassThrough

@@:
mov edx, .NMLISTVIEW.uNewState
cmp edx, LVIS_FOCUSED or LVIS_SELECTED
je @F
jmp PassThrough

@@:
; Do what you want with selected listview item here then
; dialog will close
push hDlg
call GetParent
mov m_hwnd, eax

push 0
push 0
push WM_CLOSE
push m_hwnd
call PostMessage
ret

_INITDIALOG:
push hDlg
call GetParent
mov m_hwnd, eax

; We/I don't want the next 3 controls so hide em.
; Hide Ok button
push 0
push IDOK
push CDM_HIDECONTROL
push m_hwnd
call SendMessage

; Hide File Name edit control
push 0
push edt1
push CDM_HIDECONTROL
push m_hwnd
call SendMessage

; Hide File Name static control
push 0
push stc3
push CDM_HIDECONTROL
push m_hwnd
call SendMessage

; now move the next 3 controls up
; Adjust File type static top
push 0
push sizeof tTR
push offset tTR
call memfill

push 0
push sizeof wLp
push offset wLp
call memfill

push stc2
push m_hwnd
call GetDlgItem
mov hd, eax

push offset tTR
push hd
call GetWindowRect

push offset wLp
push m_hwnd
call ScreenToClient

mov eax, wLp.x
add eax, tTR.left

mov ecx, wLp.y
add ecx, tTR.top
sub ecx, 30

push SWP_NOSIZE
push 0
push 0
push ecx
push eax
push 0
push hd
call SetWindowPos

; Adjust File type combo top
push cmb1
push m_hwnd
call GetDlgItem
mov hd, eax

push 0
push sizeof tTR
push offset tTR
call memfill

push 0
push sizeof wLp
push offset wLp
call memfill


push offset tTR
push hd
call GetWindowRect

push offset wLp
push m_hwnd
call ScreenToClient

mov eax, wLp.x
add eax, tTR.left

mov ecx, wLp.y
add ecx, tTR.top
sub ecx, 30

push SWP_NOSIZE
push 0
push 0
push ecx
push eax
push 0
push hd
call SetWindowPos

; Adjust Cancel button top
push IDCANCEL
push m_hwnd
call GetDlgItem
mov hd, eax

push 0
push sizeof tTR
push offset tTR
call memfill

push 0
push sizeof wLp
push offset wLp
call memfill


push offset tTR
push hd
call GetWindowRect

push offset wLp
push m_hwnd
call ScreenToClient

mov eax, wLp.x
add eax, tTR.left

mov ecx, wLp.y
add ecx, tTR.top
sub ecx, 28

push SWP_NOSIZE
push 0
push 0
push ecx
push eax
push 0
push hd
call SetWindowPos

push 0
push hInst
push 59
push hDlg
push 211
push 160
push 5
push 420
push WS_CHILD \
or WS_VISIBLE\
or WS_CLIPSIBLINGS\
or WS_VSCROLL\
or LVS_ICON\
or LVS_SINGLESEL\
or LVS_SHOWSELALWAYS\
or LVS_SHAREIMAGELISTS
push 0
push offset WndClsListView
push WS_EX_CLIENTEDGE
call CreateWindowEx ; Listview
mov hLVDlg, eax

push FALSE
push hFont
push WM_SETFONT
push hLVDlg
call SendMessage

push imlDlgLrg
push LVSIL_NORMAL
push LVM_SETIMAGELIST
push hLVDlg
call SendMessage

push m_hwnd
push hLVDlg
call SetParent

push 0
push sizeof tTR
push offset tTR
call memfill

push 0
push sizeof wLp
push offset wLp
call memfill

push offset tTR
push m_hwnd
call GetWindowRect

push offset wLp
push m_hwnd
call ScreenToClient

mov eax, wLp.x
add eax, tTR.right
add eax, 165

mov ecx, wLp.y
add ecx, tTR.bottom
sub ecx, 25

push SWP_NOMOVE
push ecx
push eax
push 0
push 0
push 0
push m_hwnd
call SetWindowPos

mov eax, TRUE
ret
ProcDlgHook endp
[/code]
Now we will load listview with icons on file selection
Note: PathIsDirectory is from shlwapi so include the lib and inc.
[code]
ShowIcons proc
LOCAL hLib:DWORD

; Clear imagelist
push -1
push imlDlgLrg
call ImageList_Remove

; Clear listview
push 0
push 0
push LVM_DELETEALLITEMS
push hLVDlg
call SendMessage

; is the path a directory? If yes, leave
push offset DlgFilePath
call PathIsDirectory
test eax, eax
jnz Done

; Get icon count
push -1
push offset DlgFilePath
push hInst
call ExtractIcon
test eax, eax
jz Done

; We have icons! load the file
push LOAD_LIBRARY_AS_DATAFILE
push 0
push offset DlgFilePath
call LoadLibraryEx
test eax, eax
jz Done
mov hLib, eax

; Now get all the icon names
push 0
push offset EnumResNamesProc
push RT_GROUP_ICON
push eax
call EnumResourceNames

push hLib
call FreeLibrary

Done:
ret
ShowIcons endp
[/code]
Next proc is the Callback for EnumResourceNames
[code]
EnumResNamesProc proc uses esi hModule:DWORD,lpszType:DWORD, lpszName:DWORD, lParam:DWORD
LOCAL IconTemp:DWORD
LOCAL LVParam:DWORD

push LR_DEFAULTCOLOR
push 32
push 32
push IMAGE_ICON
push lpszName
push hModule
call LoadImage
mov IconTemp, eax

push eax
push -1
push imlDlgLrg
call ImageList_ReplaceIcon

push IconTemp
call DestroyIcon

push imlDlgLrg
call ImageList_GetImageCount
sub eax, 1

mov lvi.imask, LVIF_IMAGE or LVIF_TEXT
mov lvi.iItem, eax
mov lvi.iSubItem, 0
mov lvi.iImage, eax

push 50
push HEAP_ZERO_MEMORY
push hHeap
call HeapAlloc
mov LVParam, eax

push 0
push 50
push LVParam
call memfill

push lpszName
call IS_INTRESOURCE
test eax, eax
jz @F

push lpszName
call StrLen

push eax
push LVParam
push lpszName
call MemCopy
jmp Continue


@@:
push LVParam
push lpszName
call dwtoa

Continue:
mov eax, LVParam
mov lvi.pszText, eax
push offset lvi
push 0
push LVM_INSERTITEM
push hLVDlg
call SendMessage

push LVParam
push 0
push hHeap
call HeapFree

mov eax, TRUE
ret

EnumResNamesProc endp
[/code]

I think that is it.

Hope it helps.
Posted on 2003-06-08 20:44:18 by Gunner