NO

Author Topic: Drag and drop example  (Read 1911 times)

Offline Vortex

  • Member
  • *
  • Posts: 867
    • http://www.vortex.masmcode.com
Drag and drop example
« on: March 06, 2023, 09:10:19 PM »
A simple drag and drop example :

Code: [Select]
.386
.model flat,stdcall
option casemap:none

include    DragDrop.inc

includelib \PellesC\lib\Win\user32.lib
includelib \PellesC\lib\Win\kernel32.lib
includelib \PellesC\lib\Win\gdi32.lib
includelib \PellesC\lib\Win\shell32.lib
includelib \PellesC\lib\Win\comctl32.lib

DlgProc PROTO :DWORD,:DWORD,:DWORD,:DWORD
EditBox PROTO :DWORD,:DWORD,:DWORD,:DWORD,:DWORD,:DWORD

.data

DlgBox db 'DLGBOX',0
fname  db 'Filename',0

.data?

buffer      db 256 dup(?)
hControl    dd ?

.code

start:

    invoke  GetModuleHandle,0
    xor     edx,edx
    invoke  DialogBoxParam,eax,ADDR DlgBox,\
            edx,ADDR DlgProc,edx
           
    invoke  ExitProcess,eax

DlgProc PROC hWnd:DWORD,uMsg:DWORD,wParam:DWORD,lParam:DWORD

    .IF uMsg==WM_INITDIALOG

        invoke  GetDlgItem,hWnd,4001
        mov     hControl,eax

    invoke  DragAcceptFiles,eax,TRUE

        xor     eax,eax
        invoke  SetWindowSubclass,hControl,\
                ADDR EditBox,eax,eax

    .ELSEIF uMsg==WM_CLOSE

        invoke  EndDialog,hWnd,0

    .ELSE

        xor eax,eax
        ret

    .ENDIF

    mov     eax,1
    ret

DlgProc ENDP

EditBox PROC hWnd:DWORD,uMsg:DWORD,wParam:DWORD,lParam:DWORD,uIdSubClass:DWORD,dwRefData:DWORD

    .IF uMsg == WM_DROPFILES

        invoke  DragQueryFile,wParam,0,ADDR buffer,256
        xor     eax,eax
        invoke  MessageBox,eax,ADDR buffer,ADDR fname,eax
        invoke  DragFinish,wParam

    .ELSEIF uMsg == WM_NCDESTROY

        invoke  RemoveWindowSubclass,hControl,\
                ADDR EditBox,0

    .ENDIF

    invoke  DefSubclassProc,hWnd,uMsg,wParam,lParam
    ret

EditBox ENDP

END start
« Last Edit: March 19, 2023, 10:58:44 AM by Vortex »
Code it... That's all...

Offline Vortex

  • Member
  • *
  • Posts: 867
    • http://www.vortex.masmcode.com
Re: Drag and drop example
« Reply #1 on: March 19, 2023, 11:00:06 AM »
Some minor improvements :

- hControl is now a global variable.
- Subclassing removed before the termination of the application.
Code it... That's all...