News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

Viewing Animated GIF files

Started by bluedevil, May 18, 2017, 02:31:14 AM

Previous topic - Next topic

bluedevil

Hello;
I have edit the sources caballero had shared. Bu i am stuck again. Ok here are the issues:

1. I have add a "Close" menu item. I want to close the working Gif and want to see a blank window. I have tried several of thse commands but neither of them worked:
.elseif eax == IDM_FILE_CLOSE
;invoke KillTimer, [hWnd], cdIdTimer
        ;invoke GdipDisposeImage, [hGraphics]
        ;invoke GdipFree, [pPropertyItem]
        ;invoke GdipDeleteGraphics, [memGraphics]
        ;invoke GdipDeleteGraphics, [hGraphics]
        ;invoke UpdateWindow,hWin


2. I have added a "Open" menu item and also an accelerator for it. But it only works for one time like yours caballero. When i click open again -i mean call "FileOpen" again- OpenFile dialog doesn't recognize the gif file. I debugged it. So the problem is when i call ofn OpenFilename Structure the PATH of the secondly opened file overwrites the szFilter variable. Unfortunately i couldn't managed to fixed this issue.

FileOpen Proc Uses EBX
;LOCAL ofn :OPENFILENAME


Invoke RtlZeroMemory,addr ofn,SizeOf ofn
mov ofn.lStructSize, sizeof OPENFILENAME
m2m ofn.hwndOwner, hWnd
m2m ofn.hInstance, hInstance
m2m ofn.lpstrFilter, offset szOfnFilter ;Our Unicode filter
;mov ofn.lpstrCustomFilter,
;mov ofn.nMaxCustFilter,
;mov ofn.nFilterIndex,
;lea eax, szFileName
mov ofn.lpstrFile, offset szAnimGif ;Our Unicode file path
mov ofn.nMaxFile, sizeof szAnimGif * 2;trying to alloc a big part
;mov ofn.lpstrFileTitle
;mov ofn.nMaxFileTitle
;invoke GetModuleFileName,NULL,offset szBuffer,MAX_PATH
;mov ofn.lpstrInitialDir,offset SzBuffer
mov ofn.lpstrTitle, offset szOpenGif ;Dosya aç diyaloğonun başlığı
mov ofn.Flags, OFN_EXPLORER OR OFN_FILEMUSTEXIST OR OFN_HIDEREADONLY OR OFN_PATHMUSTEXIST OR OFN_LONGNAMES
;mov ofn.nFileOffset
;mov ofn.nFileExtension
mov ofn.lpstrDefExt, NULL

invoke GetOpenFileNameW,addr ofn ;Show Open File Diolog
.if eax
;Close old File?
        invoke    GdipDeleteGraphics, [memGraphics]
        invoke    GdipDisposeImage, [hGraphics]
        ;Load GIF
        invoke    prLoadAnimGif
        invoke    prGetGifSize
        invoke    SetMainWindowSize
        mov       dword ptr [nFramePosition], 0
        invoke    BeginPaint, [hWnd], offset ps
        invoke    prDrawFrameGif, eax
        invoke    EndPaint,[hWnd], offset ps
.EndIf

;invoke lstrcpyW,ofn.lpstrFile, chr$("hataoruBlueDevil.gif") ; itried interesting things but neigter of them worked
;m2m ofn.lpstrFilter, offset szOfnFilter
RET
FileOpen EndP


3. I also checked the macros asm because i want see that WSTR does. caballero you define a szAnimGif widestring like "blahblaf.GIF". It works first time. But when we try to open something new, szAnimGif turns like "C:\dir\anotherDir\maybeOneMoreDir\andFancy.Gif". At the end this variable overwrites our filter variable.

4. I also discovered one more thing. I execute proggy on a flash usb. like F:\proggy.exe and no errors. because the path is small it didn't overwrite the filter.

5.Because szFilter is overwritten, we cant select them on the openfile dialog. But we can write the name of the gif file to the name edit. And when we enter it we can show our gif on our dialog

Thank you for everything

..Dreams make the future
But the past never lies..
BlueDeviL // SCT
My Code Site:
BlueDeviL Github

jj2007

No time to look in detail, but just one question: How does OPENFILENAME (Ansi) work together with GetOpenFileNameW?

avcaballero

You are right as ever, JJ, nevertheless, I don't see any difference between them

OPENFILENAMEW STRUCT
  lStructSize        DWORD      ?
  hwndOwner          DWORD      ?
  hInstance          DWORD      ?
  lpstrFilter        DWORD      ?
  lpstrCustomFilter  DWORD      ?
  nMaxCustFilter     DWORD      ?
  nFilterIndex       DWORD      ?
  lpstrFile          DWORD      ?
  nMaxFile           DWORD      ?
  lpstrFileTitle     DWORD      ?
  nMaxFileTitle      DWORD      ?
  lpstrInitialDir    DWORD      ?
  lpstrTitle         DWORD      ?
  Flags              DWORD      ?
  nFileOffset         WORD      ?
  nFileExtension      WORD      ?
  lpstrDefExt        DWORD      ?
  lCustData          DWORD      ?
  lpfnHook           DWORD      ?
  lpTemplateName     DWORD      ?
OPENFILENAMEW ENDS


OPENFILENAMEA STRUCT
  lStructSize        DWORD      ?
  hwndOwner          DWORD      ?
  hInstance          DWORD      ?
  lpstrFilter        DWORD      ?
  lpstrCustomFilter  DWORD      ?
  nMaxCustFilter     DWORD      ?
  nFilterIndex       DWORD      ?
  lpstrFile          DWORD      ?
  nMaxFile           DWORD      ?
  lpstrFileTitle     DWORD      ?
  nMaxFileTitle      DWORD      ?
  lpstrInitialDir    DWORD      ?
  lpstrTitle         DWORD      ?
  Flags              DWORD      ?
  nFileOffset         WORD      ?
  nFileExtension      WORD      ?
  lpstrDefExt        DWORD      ?
  lCustData          DWORD      ?
  lpfnHook           DWORD      ?
  lpTemplateName     DWORD      ?
OPENFILENAMEA ENDS


> BlueDevil
1. Which OS are you using?
2. Do you have the latest version?
3. Neither of nasmx, fasm, masm, tinyc or pellesc works to you? All of them works to me in my W7-64 and WXP-32

I experimented the same issue in one of the first versions, that's why I allocated szAnimGif at the end of the data.  You can try to change
    mov       ofn.nMaxFile,MAXSIZE          ; Indicamos el tamaño máximo del fichero
by:
    mov       ofn.nMaxFile,MAXSIZE/2          ; Indicamos el tamaño máximo del fichero

By some reason fullfil the buffer with stuff though it does not come to mind

Try to value MAXSIZE       equ  600  (instead 300, for example)


jj2007

#48
Quote from: caballero on May 31, 2017, 04:35:35 AM
You are right as ever, JJ, nevertheless, I don't see any difference between them

You are right indeed - they are identical. I thought there was some fixed size buffer inside it, wrong idea :icon_redface:

P.S.: I have tried for an hour now to chase the GetOpenFileNameW bug, no luck. All I can say is that there is heap corruption - but no heap involved there ::)

Attached a version that works. There is still a problem with the heap, but at least you may understand why FileOpen crashed.