Pelles C forum

Assembly language => Assembly discussions => Topic started by: Vortex on March 06, 2023, 09:10:19 PM

Title: Drag and drop example
Post by: Vortex 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
Title: Re: Drag and drop example
Post by: Vortex 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.