flat assembler
Message board for the users of flat assembler.

Index > Windows > Problem with GetOpenFileName

Thread Post new topic Reply to topic

Joined: 01 Apr 2006
Posts: 55
Location: Northern Ireland
moriman 17 May 2007, 22:10

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


        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

        invoke  GetMessage,msg,NULL,0,0
        cmp     eax,1
        jb      end_loop
        jne     msg_loop
        invoke  TranslateMessage,msg
        invoke  DispatchMessage,msg
        jmp     msg_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
        invoke  DefWindowProc,[hWnd],[wMsg],[wParam],[lParam]
        jmp     .finish
        mov     eax, [wParam]
        and     eax, 0FFFFh
        cmp     eax, IDM_OPEN
        je      .file_open
        jmp     .finish
        stdcall DoFileOpen, [hWnd]
        jmp     .wmBYE
        invoke  PostQuitMessage,0
        jmp     .wmBYE
        xor     eax,eax
        pop     edi esi ebx
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.lpstrDefExt], lpstrDefExt
        invoke  GetOpenFileName, ofn
        or      eax, eax
        jz      .Finish
        invoke  SetWindowText, [hwnd], szFileName
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,\

  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',\

  include 'api\kernel32.inc'
  include 'api\user32.inc'
  include 'api\Comdlg32.inc'

Any help would be greatly appreciated


Post 17 May 2007, 22:10
View user's profile Send private message Reply with quote

Joined: 12 Apr 2005
Posts: 244
Location: US
Yardman 17 May 2007, 23:29
[ Post removed by author. ]

Last edited by Yardman on 04 Apr 2012, 02:23; edited 1 time in total
Post 17 May 2007, 23:29
View user's profile Send private message Reply with quote

Joined: 01 Apr 2006
Posts: 55
Location: Northern Ireland
moriman 18 May 2007, 00:12
Thanks Yardman, works perfectly now Wink
btw, also had to change this line...
lpstrDefExt db 'avi', 00
lpstrDefExt du 'avi', 00

Strange that the win32api.hlp doesn't seem to mention this┬┐



Pointer to a buffer containing pairs of null-terminated filter strings. The last string in the buffer must be terminated by two NULL characters.
The first string in each pair is a display string that describes the filter (for example, "Text Files"), and the second string specifies the filter pattern (for example, "*.TXT"). To specify multiple filter patterns for a single display string, use a semicolon to separate the patterns (for example, "*.TXT;*.DOC;*.BAK").
Post 18 May 2007, 00:12
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  

< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum

Copyright © 1999-2023, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.