I am trying to convert this to a trayicon.
I want it to just detect the USB drive and then run the batch file.

I studied the trayicon.asm program but am not sure what to add and subtract.

Thanks.


CTEXT macro Text
    local szText
    .data
    szText byte Text, 0
    .code
    exitm <offset szText> 
endm

DlgProc PROTO :HWND,:UINT,:WPARAM,:LPARAM
GetVolumeName            PROTO :DWORD

DEV_BROADCAST_HDR STRUCT
dbch_size      DWORD  ?
dbch_devicetype DWORD  ?
dbch_reserved  DWORD  ?
DEV_BROADCAST_HDR ENDS


DEV_BROADCAST_VOLUME STRUCT
dbcv_size        DWORD  ?
dbcv_devicetype  DWORD  ?
dbcv_reserved    DWORD  ?
dbcv_unitmask    DWORD  ?
dbcv_flags      DWORD  ?
DEV_BROADCAST_VOLUME ENDS

.const

IDD_DIALOG             equ 1000
IDC_INFO                equ 101

DBT_DEVICEARRIVAL        equ 8000h
DBT_DEVICEREMOVECOMPLETE equ 8004h
DBT_DEVTYP_VOLUME        equ 2h

.data

szDrivePath              db "%c:\\%s",0
SystemInfo              STARTUPINFO <>
ProcessInfo              PROCESS_INFORMATION <>
szCommandLine            db  "C:\bat\F_cruzer.bat",0
 
.data?

hInstance   dd  ?
szBuf              db  16 dup(?)

.code

start:

invoke GetModuleHandle,NULL
mov hInstance,eax

      invoke InitCommonControls
      invoke DialogBoxParam,hInstance,IDD_DIALOG,NULL,addr DlgProc,NULL
      invoke ExitProcess,0

DlgProc proc hWnd:HWND,uMsg:UINT,wParam:WPARAM,lParam:LPARAM
local dbt_h : DEV_BROADCAST_HDR
local dbt_v : DEV_BROADCAST_VOLUME

      .if uMsg==WM_INITDIALOG

    .elseif uMsg == WM_DEVICECHANGE
            .if wParam == DBT_DEVICEARRIVAL
                  mov ebx, lParam
                assume ebx:ptr DEV_BROADCAST_HDR
                .if .dbch_devicetype == DBT_DEVTYP_VOLUME
                    invoke SetDlgItemText,hWnd, IDC_INFO,CTEXT ("USB-Drive found")
                    mov edx,lParam
                    assume edx:ptr DEV_BROADCAST_VOLUME
                    invoke GetVolumeName,.dbcv_unitmask
                    push eax
                    invoke wsprintf,offset szBuf,offset szDrivePath,eax,0
                    invoke GetDriveType,offset szBuf
                    .if eax == DRIVE_REMOVABLE
                        invoke Sleep, 1500
                        pop eax
                    invoke SetDlgItemText,hWnd, IDC_INFO,offset szBuf
                   
                  ; run batch file to copy files to thumbdrive
                  INVOKE CreateProcess,NULL,ADDR szCommandLine, NULL, NULL, FALSE, \
                  NORMAL_PRIORITY_CLASS, NULL, NULL, ADDR SystemInfo, ADDR ProcessInfo
                 
                    .endif
                    assume edx:nothing
                .endif
                assume ebx:ptr nothing
            .elseif wParam == DBT_DEVICEREMOVECOMPLETE
                    invoke SetDlgItemText,hWnd, IDC_INFO,CTEXT ("USB-Drive Removed")
            .endif
.elseif uMsg==WM_COMMAND

.elseif uMsg==WM_CLOSE
@Exit:
invoke EndDialog,hWnd,0
.else
mov eax,FALSE
ret
.endif
      mov eax,TRUE
ret

DlgProc endp

GetVolumeName proc flag:DWORD
push esi
push ecx
mov ecx, 26
mov esi,flag
@@:
test esi,1h
jnz @f
shr esi,1h
dec ecx
test ecx,ecx
jnz @b
@@:
mov eax,5Bh
sub eax,ecx
pop ecx
pop esi
ret
GetVolumeName endp

end start

Posted on 2010-07-01 11:45:43 by skywalker
skywalker,

Hide your window and use Shell_NotifyIcon() to add icon to the tray. It's a pity that message-only windows don't receive broadcasts.
Posted on 2010-07-11 00:45:52 by baldr