moriman
Joined: 01 Apr 2006
Posts: 55
Location: Northern Ireland
|
Hi,
I'm trying to use GetOpenFileName to give the user a way to choose which file to open, but even though afaik, I have the structure for OPENFILENAME correct, especially the lpstrDefExt and nFilterIndex parts, when the dialog box opens, there is rubbish in the File name and Files of Type controls.
format PE GUI 4.0
entry start
include 'win32w.inc'
section '.code' code readable executable
start:
invoke GetModuleHandle,0
mov [wc.hInstance],eax
invoke LoadIcon,0,IDI_APPLICATION
mov [wc.hIcon],eax
invoke LoadCursor,0,IDC_ARROW
mov [wc.hCursor],eax
invoke RegisterClass,wc
invoke CreateWindowEx,0,_class,_title,WS_VISIBLE+WS_DLGFRAME+WS_SYSMENU,128,128,256,192,NULL,NULL,[wc.hInstance],NULL
msg_loop:
invoke GetMessage,msg,NULL,0,0
cmp eax,1
jb end_loop
jne msg_loop
invoke TranslateMessage,msg
invoke DispatchMessage,msg
jmp msg_loop
end_loop:
invoke ExitProcess,[msg.wParam]
proc WindowProc hWnd,wMsg,wParam,lParam
push ebx esi edi
cmp [wMsg], WM_DESTROY
je .wmDESTROY
cmp [wMsg], WM_COMMAND
je .wmCOMMAND
.defwndproc:
invoke DefWindowProc,[hWnd],[wMsg],[wParam],[lParam]
jmp .finish
.wmCOMMAND:
mov eax, [wParam]
and eax, 0FFFFh
cmp eax, IDM_OPEN
je .file_open
jmp .finish
.file_open:
stdcall DoFileOpen, [hWnd]
jmp .wmBYE
.wmDESTROY:
invoke PostQuitMessage,0
jmp .wmBYE
.wmBYE:
xor eax,eax
.finish:
pop edi esi ebx
ret
endp
;-------------------------------------------
proc DoFileOpen, hwnd
mov [ofn.lStructSize], sizeof.OPENFILENAME
mov eax, [hwnd]
mov [ofn.hwndOwner], eax
mov [ofn.lpstrFilter], lpstrFilter
mov [ofn.lpstrFile], szFileName
mov [ofn.nMaxFile], MAX_PATH
mov [ofn.Flags], OFN_FILEMUSTEXIST+OFN_PATHMUSTEXIST+OFN_HIDEREADONLY
mov [ofn.lpstrDefExt], lpstrDefExt
invoke GetOpenFileName, ofn
or eax, eax
jz .Finish
invoke SetWindowText, [hwnd], szFileName
.Finish:
ret
endp
;--------------------------------------------
section '.data' data readable writeable
_class TCHAR 'VideoReader',0
_title TCHAR 'Video Reader',0
IDM_MAIN = 1000
IDM_OPEN = 1100
szFileName db MAX_PATH dup ' '
lpstrDefExt db 'avi', 00
lpstrFilter db 'AVI Files (*.avi)', 00, '*.avi', 00, 'All Files (*.*)', 00, '*.*', 00, 00
ofn OPENFILENAME 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
wc WNDCLASS 0,WindowProc,0,0,NULL,NULL,NULL,COLOR_BTNFACE+1,IDM_MAIN,_class
msg MSG
;----------------------------------------
section '.rsrc' resource data readable
directory RT_MENU,menus
resource menus,\
IDM_MAIN,LANG_ENGLISH+SUBLANG_DEFAULT,main_menu
menu main_menu
menuitem '&File',0,MFR_POPUP + MFR_END
menuitem '&Open', IDM_OPEN, MFR_END
;---------------------------------------------------
section '.idata' import data readable writeable
library kernel32,'KERNEL32.DLL',\
user32,'USER32.DLL',\
comdlg32,'COMDLG32.DLL'
include 'api\kernel32.inc'
include 'api\user32.inc'
include 'api\Comdlg32.inc'
;--------------------------------------------
Any help would be greatly appreciated
thx
mori
|