News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Setting file type "automatically" in save file

Started by allynm, January 12, 2010, 10:56:13 PM

Previous topic - Next topic

allynm

Hi everyone -

I'm serving up another beginner's creampuff hereby.  I'm trying to learn to use OPENFILENAME along with an edit box.  Everything works just fine, EXCEPT I have to append the filetype manually.  For example as barf.txt, not just barf.  I had supposed that when I set the value of nFilterIndex to its position value in the filter string that .txt would be appended automatically.

What am I doing wrong?

Thanks,

Mark Allyn

Slugsnack

Have a look at the SaveFileDlg macro and its source

allynm

Hi Sllugsnack,

Thanks, I will.  I got nowhere on MSDN library.

Mark

allynm

Slugsnack-

I did as you suggested.  There may be a problem with how I've written the filter string.  Here is what I did:


FilterString db "All Files", 0, "*.*",0,\
"Text Files",0, "*.txt",0,\        
                   "ASM Files", 0, "*.asm",0,0


What sayest thou?

Regards,
Mark

Slugsnack

include \masm32\include\masm32rt.inc

.code
  Start:

xor ebx, ebx
  invoke GetModuleHandle, ebx
mov eax, SaveFileDlg( ebx, eax, chr$("Lala"), chr$("Text Files",0,"*.txt",0,"ASM Files",0,"*.asm",0,0) )
  invoke ExitProcess, ebx

  end Start


      SaveFileDlg MACRO hWin,hInstance,lpTitle,lpPattern
        invoke SaveFileDialog,hWin,hInstance,reparg(lpTitle),reparg(lpPattern)
        EXITM <eax>
      ENDM


SaveFileDialog proc hParent:DWORD,Instance:DWORD,lpTitle:DWORD,lpFilter:DWORD

    LOCAL ofn:OPENFILENAME

    .data?
      savefilebuffer db 260 dup (?)
    .code

    mov eax, OFFSET savefilebuffer
    mov BYTE PTR [eax], 0

  ; --------------------
  ; zero fill structure
  ; --------------------
    push edi
    mov ecx, sizeof OPENFILENAME
    mov al, 0
    lea edi, ofn
    rep stosb
    pop edi

    mov ofn.lStructSize,        sizeof OPENFILENAME
    m2m ofn.hWndOwner,          hParent
    m2m ofn.hInstance,          Instance
    m2m ofn.lpstrFilter,        lpFilter
    m2m ofn.lpstrFile,          offset savefilebuffer
    mov ofn.nMaxFile,           sizeof savefilebuffer
    m2m ofn.lpstrTitle,         lpTitle
    mov ofn.Flags,              OFN_EXPLORER or OFN_LONGNAMES or \
                                OFN_HIDEREADONLY or OFN_OVERWRITEPROMPT
                               
    invoke GetSaveFileName,ADDR ofn
    mov eax, OFFSET savefilebuffer
    ret

SaveFileDialog endp

jj2007

Quote from: allynm on January 13, 2010, 12:20:58 AM
There may be a problem with how I've written the filter string

That one looks ok. Do you supply a full file name with extension here?

m2m ofn.lpstrFile,          offset savefilebuffer

Or maybe I have not fully understood your problem...

allynm

Hi JJ and Sllugsnack:

FilterString in OPENFILENAME is coded like this:

mov ofn.lpstrFilter, OFFSET FilterString

maybe it has to be m2m instead of mov?

Thanks,
Mark

Slugsnack

Quote from: allynm on January 13, 2010, 03:12:14 AM
Hi JJ and Sllugsnack:

FilterString in OPENFILENAME is coded like this:

mov ofn.lpstrFilter, OFFSET FilterString

maybe it has to be m2m instead of mov?

Thanks,
Mark
mov is fine. Could you post your full source ? Your filter string is fine, I assume things are going wrong elsewhere.

allynm

Hi Slugsnack and JJ :

Here is the section of code in which I attempt to save the file.  The entire pgm is probably too long for this forum.  If you need to see more I'll bundle it up as a zipfile.

.ELSEIF ax == IDM_SAVE
INVOKE ShowWindow, hwndEdit3, SW_SHOWNORMAL
INVOKE SetFocus, hwndEdit3
mov ofn.nFilterIndex, 3
mov ofn.Flags, OFN_LONGNAMES or OFN_EXPLORER or\
  OFN_HIDEREADONLY
INVOKE GetSaveFileName, ADDR ofn  ;line 283
.IF eax == TRUE
  INVOKE CreateFile, ADDR buffer3,
GENERIC_READ or GENERIC_WRITE, \
FILE_SHARE_READ or FILE_SHARE_WRITE,\
NULL, CREATE_NEW, FILE_ATTRIBUTE_ARCHIVE,\
NULL
mov hFile, eax




I hope this helps.  Thanks,
Mark

TNick

Quote from: msdnlpstrDefExt
Pointer to a buffer that contains the default extension. GetOpenFileName and GetSaveFileName append this extension to the file name if the user fails to type an extension. This string can be any length, but only the first three characters are appended. The string should not contain a period (.). If this member is NULL and the user fails to type an extension, no extension is appended.

Isn't this what you are looking for?

Nick

Slugsnack

Quote from: allynm on January 13, 2010, 03:39:22 AM
Hi Slugsnack and JJ :

Here is the section of code in which I attempt to save the file.  The entire pgm is probably too long for this forum.  If you need to see more I'll bundle it up as a zipfile.

.ELSEIF ax == IDM_SAVE
INVOKE ShowWindow, hwndEdit3, SW_SHOWNORMAL
INVOKE SetFocus, hwndEdit3
mov ofn.nFilterIndex, 3
mov ofn.Flags, OFN_LONGNAMES or OFN_EXPLORER or\
  OFN_HIDEREADONLY
INVOKE GetSaveFileName, ADDR ofn  ;line 283
.IF eax == TRUE
  INVOKE CreateFile, ADDR buffer3,
GENERIC_READ or GENERIC_WRITE, \
FILE_SHARE_READ or FILE_SHARE_WRITE,\
NULL, CREATE_NEW, FILE_ATTRIBUTE_ARCHIVE,\
NULL
mov hFile, eax




I hope this helps.  Thanks,
Mark
Unless you've not shown some of the code, every element should be initialised in your ofn structure. See how it is done in the code I posted at the top

allynm

Hi TNick and Slugsnack -

It looks to me like TNick has nailed  the problem.  If I follow Slugsnack's advice to fill the whole struct then I will accomplish what TNick suggests.  Without the suggestion, however, I probably would have missed the importance of that field in the OFN struct, however.

I have to be out of town for two days and won't be able to test this until Friday.  Thanks to everyone who has pitched in.

Regards,
Mark

allynm

Hi TNick & Slugsnack

I tried out TNick's suggestion and it worked.  Mystery solved.  Thanks to both of you...

Mark