flat assembler
Message board for the users of flat assembler.

Index > Windows > Snippets...

Author
Thread Post new topic Reply to topic
bitRAKE



Joined: 21 Jul 2003
Posts: 4020
Location: vpcmpistri
bitRAKE 26 Jun 2008, 21:05
Code:
PropEnumProc.REMOVE:
   label .hWnd             dword at esp+4
      label .lpszString       dword at esp+8
      label .hData            dword at esp+12

 pop [.hData-4]
      call [RemoveProp]
   retn    
invoke EnumProps,[.hWnd+4],PropEnumProc.REMOVE

Window properties can be used for a high-level interface, but requiring every user to remove all the properties they create is kind of silly. This little snippet insures all the properties are removed.

_________________
¯\(°_o)/¯ “languages are not safe - uses can be” Bjarne Stroustrup
Post 26 Jun 2008, 21:05
View user's profile Send private message Visit poster's website Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 4020
Location: vpcmpistri
bitRAKE 26 Jun 2008, 21:19
http://support.microsoft.com/kb/131462
Code:
; Preventing FNERR_BUFFERTOOSMALL with multiple file selection in Open File
; common dialog. http://support.microsoft.com/kb/131462
;
; Although it is doubtful that a single application would have concurrent
; multiple Open File dialogs selecting multiple files; multiple instances of
; the same application could be open and using the same code. So, Microsoft
; advises the use of a control property to preserve the OPENFILENAME pointer.
;
; Microsoft indicates to attach property to parent control, but no reason it
; can't be attached to this default or custom child control (simplifying the
; code slightly). Logically, the structure belongs to the parent, and so does
; the child control.
OFNHookProc:
      label .hWnd     dword at esp+4*1
    label .uMsg     dword at esp+4*2
    label .wParam   dword at esp+4*3
    label .lParam   dword at esp+4*4

        cmp [.uMsg],WM_NOTIFY
       je .WM_NOTIFY
       cmp [.uMsg],WM_DESTROY
      je .WM_DESTROY
      cmp [.uMsg],WM_INITDIALOG
   je .WM_INITDIALOG

       xor eax,eax
 retn 16

.WM_INITDIALOG:
  invoke SetProp,[.hWnd+8],.T_OFN,[.lParam]
   xor eax,eax
 retn 16

.WM_DESTROY:
     invoke RemoveProp,[.hWnd+4],.T_OFN
.WM_0:        xor eax,eax
 retn 16

.WM_NOTIFY:
      mov eax,[.lParam]
   cmp [eax+NMHDR.code],CDN_SELCHANGE
  jne .WM_0

       invoke GetParent,[.hWnd]
    ; returns characters needed (undocumented?) 1+
      invoke SendMessage,eax,CDM_GETSPEC,0,0
      add eax,MAX_PATH
    push eax
    invoke GetProp,[.hWnd+8],.T_OFN
     pop edx
     test eax,eax
        je .WM_0
    cmp [eax+OPENFILENAME.nMaxFile],edx
 jnc .WM_0

       pushad
      xchg eax,edi
        mov esi,edx
 invoke GetProcessHeap
       xchg eax,ebx

; this really isn't needed as HeapFree error is ignored and passing a NULL
; pointer goes right through.
;   cmp [eax+OPENFILENAME.lpstrFile],0
; je @F
       invoke HeapFree,ebx,0,[edi+OPENFILENAME.lpstrFile]
@@:   lea ebp,[esi*2] ; UNICODE: characters to bytes needed
   invoke HeapAlloc,ebx,HEAP_ZERO_MEMORY,ebp
   test eax,eax
        je @F
       mov [edi+OPENFILENAME.lpstrFile],eax
        mov [edi+OPENFILENAME.nMaxFile],esi
@@:  popad
       xor eax,eax
 retn 16

.T_OFN TCHAR "OFN",0    
Allocate space on the heap for OPENFILENAME.lpstrFile prior to calling GetOpenFileName as that pointer cannot be null. Also, note that WM_NOTIFY messages can be sent prior to property being created - which surprised me. It's possible to further simplify the WM_NOTIFY code by increasing the size of OPENFILENAME structure to hold parent window and heap handles (to be initialized in WM_INITDIALOG handler). Only mentioned for the sake of completeness.

_________________
¯\(°_o)/¯ “languages are not safe - uses can be” Bjarne Stroustrup
Post 26 Jun 2008, 21:19
View user's profile Send private message Visit poster's website Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 4020
Location: vpcmpistri
bitRAKE 10 Sep 2008, 06:32
Unique file name:
Code:
FILE.TEMPLATE TCHAR "%07u%07u%07u.log",0

        push esp
        push esp
        invoke GetSystemTimeAsFileTime,esp
        mov eax,[esp+4]
        xor edx,edx
        mov ecx,10000000
        div ecx
        xchg eax,[esp]
        div ecx
        xchg edx,[esp]
        div ecx
        push edx
        push eax
        invoke wsprintf,FILE.PATHNAME,FILE.TEMPLATE
        add esp,24    

_________________
¯\(°_o)/¯ “languages are not safe - uses can be” Bjarne Stroustrup
Post 10 Sep 2008, 06:32
View user's profile Send private message Visit poster's website Reply with quote
f0dder



Joined: 19 Feb 2004
Posts: 3175
Location: Denmark
f0dder 10 Sep 2008, 08:27
Are you sure it's a good idea to blindly remove windows properties?

IMHO you should only use one prop per windowclass anyway, and make it a pointer to a struct - that way you only have one property to worry about yourself, and you don't risk messing up anything Smile
Post 10 Sep 2008, 08:27
View user's profile Send private message Visit poster's website Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 4020
Location: vpcmpistri
bitRAKE 10 Sep 2008, 13:31
I use it when the window is being destroyed per MS.

_________________
¯\(°_o)/¯ “languages are not safe - uses can be” Bjarne Stroustrup
Post 10 Sep 2008, 13:31
View user's profile Send private message Visit poster's website 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-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.